Repository navigation
fix: report full token values for GitHub and GitLab detectors - #1016
Open
abu-tahir-0 wants to merge 1 commit into
Open
abu-tahir-0 wants to merge 1 commit into
abu-tahir-0 wants to merge 1 commit into
Conversation
The denylist regexes used capturing groups for the token prefix/partition.
RegexBasedDetector.analyze_string uses findall(), which returns only the
captured group rather than the whole match, so findings contained just the
prefix ('ghp', 'glpat') or an empty string instead of the token. That made
distinct tokens hash identically in baselines and broke masking. Make the
groups non-capturing and assert the full token value in dedicated tests.
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.
Problem
The GitHub and GitLab token detectors reported only a prefix (or an empty string) instead of the full token value (issue #858). For example,
analyze_lineon a GitLab CI token returned''rather than the token itself.Root Cause
The denylist regexes used capturing groups around the token prefix/partition.
RegexBasedDetector.analyze_stringusesre.findall(), which returns only captured groups rather than the whole match. Findings therefore looked likeghp,glpat, or'', making distinct tokens hash identically in baselines and breaking masking.Solution
Convert the relevant capturing groups to non-capturing groups in
github_token.pyandgitlab_token.py. This is the minimal change: detection behavior is unchanged, only the reported value is corrected.Testing
tests/plugins/token_value_test.pyasserting the reportedsecret_valueequals the full token for GitHub PAT, GitLab PAT, and GitLab CI build token formats.pytestfull suite: 1034 passed, 6 xfailed. Two pre-existing failures inTestScanDiffare caused by a newerunidiffrejecting a test fixture; confirmed unchanged by the fix.Impact
Baselines now hash distinct tokens correctly and masking redacts the actual secret instead of a three-letter prefix.