Find, verify, and analyze leaked credentials
Go credentialsdevsecopsdynamic-analysisprecommitscanningsecretsecret-managementsecretssecuritysecurity-toolstrufflehogverification
Fix nondeterminism in custom detectors (#4446)
Brad Larsen7f32919787f5
diff --git a/pkg/custom_detectors/custom_detectors.go b/pkg/custom_detectors/custom_detectors.goindex c0b6638cc..2a8f4f302 100644--- a/pkg/custom_detectors/custom_detectors.go+++ b/pkg/custom_detectors/custom_detectors.go@@ -5,8 +5,10 @@ import ("context""encoding/json""io"+ "maps""net/http""regexp"+ "slices""strings""golang.org/x/sync/errgroup"@@ -214,7 +216,8 @@ func (c *CustomRegexWebhook) createResults(ctx context.Context, match map[string}var raw string- for key, values := range match {+ for _, key := range slices.Sorted(maps.Keys(match)) {+ values := match[key]// values[0] contains the entire regex match.secret := values[0]if len(values) > 1 {diff --git a/pkg/custom_detectors/custom_detectors_test.go b/pkg/custom_detectors/custom_detectors_test.goindex 05ada041b..d7ec360fd 100644--- a/pkg/custom_detectors/custom_detectors_test.go+++ b/pkg/custom_detectors/custom_detectors_test.go@@ -538,7 +538,7 @@ func TestDetectorValidations(t *testing.T) {DetectorType: detectorspb.DetectorType_CustomRegex,DetectorName: "test",Verified: false,- Raw: []byte("MyStrongP@sswordc392c9837d69b44c764cbf260b-e6184"),+ Raw: []byte("c392c9837d69b44c764cbf260b-e6184MyStrongP@ssword"),},},},