Skip to content

Find, verify, and analyze leaked credentials

redact secret for twilio api key (#4550)

Mustansire7b3dbfb0fb7
diff --git a/pkg/detectors/twilioapikey/twilioapikey.go b/pkg/detectors/twilioapikey/twilioapikey.go
index 4a73e11d7..677e4ceb3 100644
--- a/pkg/detectors/twilioapikey/twilioapikey.go
+++ b/pkg/detectors/twilioapikey/twilioapikey.go
@@ -63,7 +63,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
DetectorType: detectorspb.DetectorType_Twilio,
Raw: []byte(apiKey),
RawV2: []byte(apiKey + secret),
- Redacted: secret,
+ Redacted: secret[:5] + "...",
ExtraData: make(map[string]string),
}
diff --git a/pkg/detectors/twilioapikey/twilioapikey_test.go b/pkg/detectors/twilioapikey/twilioapikey_test.go
index 0af8521ea..4e61f3462 100644
--- a/pkg/detectors/twilioapikey/twilioapikey_test.go
+++ b/pkg/detectors/twilioapikey/twilioapikey_test.go
@@ -81,3 +81,24 @@ func TestTwilioAPIKey_Pattern(t *testing.T) {
})
}
}
+
+func TestTwilioAPIKey_SecretRedacted(t *testing.T) {
+ d := Scanner{}
+
+ results, err := d.FromData(
+ context.Background(),
+ false,
+ []byte(fmt.Sprintf("%s token - '%s'\n%s token - '%s'\n", keyword, validAPIKey, keyword, validSecret)))
+ if err != nil {
+ t.Errorf("error = %v", err)
+ return
+ }
+
+ if len(results) == 0 {
+ t.Errorf("did not receive result")
+ }
+
+ if results[0].Redacted != validSecret[:5]+"..." {
+ t.Errorf("expected redacted secret to be '%s', got '%s'", validSecret[:5]+"...", results[0].Redacted)
+ }
+}