@@ -21,9 +21,10 @@ type Scanner struct {
2121var _ detectors.Detector = (* Scanner )(nil )
2222
2323var (
24+ keyPat = regexp .MustCompile (detectors .PrefixRegex ([]string {"confluent" }) + `\b([a-zA-Z0-9]{16})\b` )
2425 // Match cflt prefix followed by 60 characters consisting of A-Z, a-z, 0-9, + or /
2526 //See https://docs.confluent.io/cloud/current/security/authenticate/workload-identities/service-accounts/api-keys/overview.html#api-secret-format
26- secretPat = regexp .MustCompile (detectors . PrefixRegex ([] string { "Confluent" }) + `\b(cflt[A-Za-z0-9+/]{60})\b` )
27+ secretPat = regexp .MustCompile (`\b(cflt[A-Za-z0-9+/]{60})\b` )
2728)
2829
2930// Keywords are used for efficiently pre-filtering chunks.
@@ -32,31 +33,37 @@ func (s Scanner) Keywords() []string {
3233 return []string {"cflt" }
3334}
3435
35- func (Scanner ) Version () int { return 2 }
36+ func (s Scanner ) Version () int { return 2 }
3637
3738// FromData will find and optionally verify Confluent secrets in a given set of bytes.
3839func (s Scanner ) FromData (ctx context.Context , verify bool , data []byte ) (results []detectors.Result , err error ) {
3940 dataStr := string (data )
4041
42+ matches := keyPat .FindAllStringSubmatch (dataStr , - 1 )
4143 secretMatches := secretPat .FindAllStringSubmatch (dataStr , - 1 )
4244
43- for _ , match := range secretMatches {
44- resSecret := strings .TrimSpace (match [1 ]) // Use index 1 for the captured group
45+ for _ , match := range matches {
46+ resMatch := strings .TrimSpace (match [1 ])
4547
46- s1 := detectors.Result {
47- DetectorType : detectorspb .DetectorType_Confluent ,
48- Raw : []byte (resSecret ),
49- ExtraData : map [string ]string {
50- "rotation_guide" : "https://docs.confluent.io/cloud/current/security/authenticate/workload-identities/service-accounts/api-keys/best-practices-api-keys.html#rotate-api-keys-regularly" ,
51- "version" : fmt .Sprintf ("%d" , s .Version ()),
52- },
53- }
48+ for _ , match := range secretMatches {
49+ resSecret := strings .TrimSpace (match [1 ]) // Use index 1 for the captured group
5450
55- if verify {
56- s1 .Verified = verifyConfluentSecret (resSecret )
57- }
51+ s1 := detectors.Result {
52+ DetectorType : detectorspb .DetectorType_Confluent ,
53+ Raw : []byte (resMatch ),
54+ RawV2 : []byte (resMatch + resSecret ),
55+ ExtraData : map [string ]string {
56+ "rotation_guide" : "https://docs.confluent.io/cloud/current/security/authenticate/workload-identities/service-accounts/api-keys/best-practices-api-keys.html#rotate-api-keys-regularly" ,
57+ "version" : fmt .Sprintf ("%d" , s .Version ()),
58+ },
59+ }
5860
59- results = append (results , s1 )
61+ if verify {
62+ s1 .Verified = verifyConfluentSecret (resSecret )
63+ }
64+
65+ results = append (results , s1 )
66+ }
6067 }
6168
6269 return results , nil
0 commit comments