Reduce false positives in DatadogToken detector #4632
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #4631
Description:
Reduce false positives in DatadogToken detector by filtering out legitimate code identifiers, checksums, encrypted data, and test values that match the detector pattern.
Changes:
sha512-...==patterns)h1:...=patterns)%3Apatterns)ENC[AES256_GCM,data:...]patterns)caBundlepatterns)res.Body.Close()errorsThis reduces false positives from legitimate code identifiers, checksums, encrypted data, and test values while still detecting real Datadog API and Application keys that contain digits and have higher entropy.
Problem:
The DatadogToken detector was flagging any 32-character or 40-character alphanumeric string near the keywords "datadog" or "dd" as a potential secret, including:
service%3Amy-app-service-name)sha512-...==patterns)h1:...=patterns)ENC[AES256_GCM,data:...]patterns)11111111111111111111111111111111)caBundlefields)Solution:
Added
isLikelyFalsePositive()helper function with multiple filters:11111111111111111111111111111111sha512-...==patterns in package.json filesh1:...=patterns in go.sum/go.mod files%3Apatterns and URL structuresENC[AES256_GCM,data:...]patternscaBundleand certificate-related fieldsImplementation Details:
FromData()to useFindAllStringSubmatchIndex()to get match positions for context extractionsha512-,h1:,%3A,ENC[,caBundle)Checklist:
make test-community)?make lintthis requires golangci-lint)?