Reduce False Positives in Twilio Detector #4516
Open
+10
−7
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.
This PR addresses false positive issues in the Twilio detector by making the regex patterns more context-aware and removing an overly generic keyword.
Changes Made
1. Added Context-Aware Regex Patterns
Updated both
sidPatandkeyPatto require contextual keywords within 40 characters of the credential:Why: The previous
keyPatmatched any 32-character hexadecimal string, which is extremely common in codebases (MD5 hashes, commit SHAs, etc.). By requiring proximity to Twilio-related keywords, we significantly reduce false matches while maintaining detection of legitimate credentials.2. Removed "sid" from Keywords
Why: The keyword "sid" is extremely common in code (session IDs, database fields, variable names like
user_sid,request_sid, etc.) and was causing the detector to run unnecessarily on a large percentage of scanned files. Since Twilio Account SIDs always start with "AC" and our regex already requires contextual keywords, keeping only "twilio" as the trigger is sufficient and improves performance.3. Switched to FindAllStringSubmatch
Updated the pattern matching to use
FindAllStringSubmatchinstead ofFindAllString:Why: With the addition of capturing groups in the regex patterns, we need
FindAllStringSubmatchto properly extract just the credential values (capture group [1]) without the surrounding context keywords that are used for filtering.Impact
Testing
Verified that the detector still matches valid Twilio credentials in common formats while filtering out unrelated hex strings and reducing unnecessary detector invocations.
Checklist:
make test-community)?make lintthis requires golangci-lint)?