From eb32a3787521be1cc377a7d5bd33b2dcb6b65d97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luka=20Bre=C4=8Di=C4=87?= Date: Fri, 25 Oct 2024 10:27:59 +0200 Subject: [PATCH] fix: hide sensitive info when listing targets (#1289) Signed-off-by: Luka Brecic --- pkg/api/controllers/target/list.go | 36 ++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/pkg/api/controllers/target/list.go b/pkg/api/controllers/target/list.go index d60a913125..6a8a55726d 100644 --- a/pkg/api/controllers/target/list.go +++ b/pkg/api/controllers/target/list.go @@ -4,6 +4,7 @@ package target import ( + "encoding/json" "fmt" "net/http" @@ -30,5 +31,40 @@ func ListTargets(ctx *gin.Context) { return } + for _, target := range targets { + p, err := server.ProviderManager.GetProvider(target.ProviderInfo.Name) + if err != nil { + target.Options = fmt.Sprintf("Error: %s", err.Error()) + continue + } + + manifest, err := (*p).GetTargetManifest() + if err != nil { + target.Options = fmt.Sprintf("Error: %s", err.Error()) + continue + } + + var opts map[string]interface{} + err = json.Unmarshal([]byte(target.Options), &opts) + if err != nil { + target.Options = fmt.Sprintf("Error: %s", err.Error()) + continue + } + + for name, property := range *manifest { + if property.InputMasked { + delete(opts, name) + } + } + + updatedOptions, err := json.MarshalIndent(opts, "", " ") + if err != nil { + target.Options = fmt.Sprintf("Error: %s", err.Error()) + continue + } + + target.Options = string(updatedOptions) + } + ctx.JSON(200, targets) }