Find, verify, and analyze leaked credentials
Go credentialsdevsecopsdynamic-analysisprecommitscanningsecretsecret-managementsecretssecuritysecurity-toolstrufflehogverification
Don't reuse maps; editing them afterwards edits them for all results (#5351)
Charlie Gunyon88524578ce32
diff --git a/pkg/detectors/dockerhub/v1/dockerhub.go b/pkg/detectors/dockerhub/v1/dockerhub.goindex 2062cae0c..f28d77f32 100644--- a/pkg/detectors/dockerhub/v1/dockerhub.go+++ b/pkg/detectors/dockerhub/v1/dockerhub.go@@ -64,15 +64,16 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result// Process results.for token := range tokens {- s1 := detectors.Result{- DetectorType: s.Type(),- Raw: []byte(token),- SecretParts: map[string]string{"pat": token},- }-for username := range usernames {- s1.RawV2 = []byte(fmt.Sprintf("%s:%s", username, token))- s1.SecretParts["username"] = username+ s1 := detectors.Result{+ DetectorType: s.Type(),+ Raw: []byte(token),+ RawV2: []byte(fmt.Sprintf("%s:%s", username, token)),+ SecretParts: map[string]string{+ "pat": token,+ "username": username,+ },+ }if verify {if s.client == nil {@@ -94,7 +95,11 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result// PAT matches without usernames cannot be verified but might still be useful.if len(usernames) == 0 {- results = append(results, s1)+ results = append(results, detectors.Result{+ DetectorType: s.Type(),+ Raw: []byte(token),+ SecretParts: map[string]string{"pat": token},+ })}}returndiff --git a/pkg/detectors/dockerhub/v2/dockerhub.go b/pkg/detectors/dockerhub/v2/dockerhub.goindex a29867644..544a86d60 100644--- a/pkg/detectors/dockerhub/v2/dockerhub.go+++ b/pkg/detectors/dockerhub/v2/dockerhub.go@@ -64,15 +64,16 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result// Process results.for token := range tokens {- s1 := detectors.Result{- DetectorType: s.Type(),- Raw: []byte(token),- SecretParts: map[string]string{"pat": token},- }-for username := range usernames {- s1.RawV2 = []byte(fmt.Sprintf("%s:%s", username, token))- s1.SecretParts["username"] = username+ s1 := detectors.Result{+ DetectorType: s.Type(),+ Raw: []byte(token),+ RawV2: []byte(fmt.Sprintf("%s:%s", username, token)),+ SecretParts: map[string]string{+ "pat": token,+ "username": username,+ },+ }if verify {if s.client == nil {@@ -94,7 +95,11 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result// PAT matches without usernames cannot be verified but might still be useful.if len(usernames) == 0 {- results = append(results, s1)+ results = append(results, detectors.Result{+ DetectorType: s.Type(),+ Raw: []byte(token),+ SecretParts: map[string]string{"pat": token},+ })}}return