Skip to content

Commit 25def02

Browse files
Fix: Hide config.SecretURL when the URL is incorrect. (#3887)
* fix: Hide config.SecretURL when the URL is incorrect. Updated the config.go to redact the URL. Added test cases to check URL stays hidden. Signed-off-by: Kapil Ramwani([email protected]) --------- Signed-off-by: Simon Pasquier <[email protected]> Co-authored-by: Simon Pasquier <[email protected]>
1 parent 52eb1fc commit 25def02

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

config/config.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,12 @@ func (s *SecretURL) UnmarshalJSON(data []byte) error {
165165
s.URL = &url.URL{}
166166
return nil
167167
}
168-
return json.Unmarshal(data, (*URL)(s))
168+
// Redact the secret URL in case of errors
169+
if err := json.Unmarshal(data, (*URL)(s)); err != nil {
170+
return errors.New(strings.ReplaceAll(err.Error(), string(data), "[REDACTED]"))
171+
}
172+
173+
return nil
169174
}
170175

171176
// Load parses the YAML input s into a Config.

config/config_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,15 @@ func TestUnmarshalSecretURL(t *testing.T) {
602602
require.Equal(t, "http://example.com/se%20cret", u.String(), "SecretURL not properly unmarshaled in YAML.")
603603
}
604604

605+
func TestHideSecretURL(t *testing.T) {
606+
b := []byte(`"://wrongurl/"`)
607+
var u SecretURL
608+
609+
err := json.Unmarshal(b, &u)
610+
require.Error(t, err)
611+
require.NotContains(t, err.Error(), "wrongurl")
612+
}
613+
605614
func TestMarshalURL(t *testing.T) {
606615
for name, tc := range map[string]struct {
607616
input *URL

0 commit comments

Comments
 (0)