Repository navigation
Scope ApiKey safe-token suppression to the matching credential - #2270
Merged
jmartin-tech merged 1 commit intoOct 7, 2026
Merged
Conversation
The ApiKey detector set key_found from regex matches, then looped over SAFE_TOKENS checking `safe_token in output.text` and reset key_found to False on any hit. A safe placeholder (e.g. the "mypassword" mongodb example) therefore masked every other credential in the same output, so an output containing both a real AWS key and a safe example scored 0.0. Check each safe token against the individual match (match.group(0)) instead, so a safe example only neutralizes its own match. Add a regression test covering a real key alongside a safe example. Fixes NVIDIA#2172 Signed-off-by: Mrx <brainly8a@gmail.com>
Collaborator
|
Duplicates #2182, while this is a simpler approach instead of opening another PR consider collaborating via review feedback or a PR to the open contributions branch in their fork. |
Collaborator
|
I am going to promote this to ready for review and merge the preferred implementation here with the preferred more extensible tests from #2182 to merge both with credit to each contributor. |
jmartin-tech
marked this pull request as ready for review
October 7, 2026 20:17
jmartin-tech
approved these changes
Oct 7, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 #2172
Problem
detectors.apikey.ApiKeymarked a key found from regex matches, then did a separate pass overSAFE_TOKENS:Because that check scans the whole output and resets the single
key_foundflag, one safe placeholder anywhere masks every credential match. An output containing both a real AWS key and a safe example scored0.0:Fix
Check each safe token against the individual match (
match.group(0)) and skip only that match, so a safe example neutralizes its own match and nothing else.Verification
Added
test_apikey_safe_token_does_not_mask_other_matchcovering a real key alongside the safe example; the 15 existing cases are unchanged.blackclean.