Skip to content

Commit 6e2e4ec

Browse files
authored
chore: Obfuscate field by repeating * with character length (#181)
* chore: Obfuscate field by repeating * with character length * test: Obfuscate
1 parent 3a48028 commit 6e2e4ec

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

internal/destregistry/baseprovider.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ import (
1111
"github.com/hookdeck/outpost/internal/models"
1212
)
1313

14-
// ObfuscateValue masks a sensitive value. For strings:
15-
// - Less than 10 characters: return "****" to avoid revealing length
16-
// - 10 or more characters: show first 4 characters + asterisks for the rest
14+
// ObfuscateValue masks a sensitive value with the following rules:
15+
// - For strings with length >= 10: show first 4 characters + asterisks for the rest
16+
// - For strings with length < 10: replace each character with an asterisk
1717
func ObfuscateValue(value string) string {
1818
if len(value) < 10 {
19-
return "****"
19+
return strings.Repeat("*", len(value))
2020
}
2121
return value[:4] + strings.Repeat("*", len(value)-4)
2222
}

internal/destregistry/registry_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -530,22 +530,22 @@ func TestObfuscateValue(t *testing.T) {
530530
{
531531
name: "empty string",
532532
input: "",
533-
expected: "****",
533+
expected: "",
534534
},
535535
{
536536
name: "single character",
537537
input: "a",
538-
expected: "****",
538+
expected: "*",
539539
},
540540
{
541541
name: "short string",
542542
input: "abc123",
543-
expected: "****",
543+
expected: "******",
544544
},
545545
{
546546
name: "9 characters",
547547
input: "123456789",
548-
expected: "****",
548+
expected: "*********",
549549
},
550550
{
551551
name: "10 characters",
@@ -600,11 +600,11 @@ func TestObfuscateDestination(t *testing.T) {
600600
assert.Equal(t, "visible-value", obfuscated.Config["public_key"])
601601

602602
// Sensitive fields should be obfuscated according to length:
603-
// - Less than 10 chars: "****"
603+
// - Less than 10 chars: replace each character with an asterisk
604604
// - 10+ chars: first 4 chars + asterisks
605605
assert.Equal(t, "sens***************", obfuscated.Config["secret_key"]) // 19 chars
606606
assert.Equal(t, "abcd************", obfuscated.Credentials["api_key"]) // 16 chars
607-
assert.Equal(t, "****", obfuscated.Credentials["token"]) // 3 chars
607+
assert.Equal(t, "***", obfuscated.Credentials["token"]) // 3 chars
608608
assert.Equal(t, "****", obfuscated.Credentials["code"]) // 4 chars
609609
}
610610

@@ -716,7 +716,7 @@ func TestDisplayDestination(t *testing.T) {
716716
require.NoError(t, err)
717717
assert.Equal(t, "mock-target", display.Target)
718718
assert.Equal(t, "value", display.Config["public_key"])
719-
assert.Equal(t, "****", display.Config["secret_key"])
719+
assert.Equal(t, "******", display.Config["secret_key"])
720720
assert.Equal(t, "secr******", display.Credentials["api_key"])
721721
}
722722

0 commit comments

Comments
 (0)