Skip to content

fix: report full token values for GitHub and GitLab detectors - #1016

Open
abu-tahir-0 wants to merge 1 commit into
Yelp:masterfrom
abu-tahir-0:fix/report-full-token-values
Open

abu-tahir-0 wants to merge 1 commit into
Yelp:masterfrom
abu-tahir-0:fix/report-full-token-values

Conversation

@abu-tahir-0

Copy link
Copy Markdown

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_line on 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_string uses re.findall(), which returns only captured groups rather than the whole match. Findings therefore looked like ghp, 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.py and gitlab_token.py. This is the minimal change: detection behavior is unchanged, only the reported value is corrected.

Testing

  • Added tests/plugins/token_value_test.py asserting the reported secret_value equals the full token for GitHub PAT, GitLab PAT, and GitLab CI build token formats.
  • Confirmed the new tests fail against the unmodified detector source and pass with the fix.
  • pytest full suite: 1034 passed, 6 xfailed. Two pre-existing failures in TestScanDiff are caused by a newer unidiff rejecting 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.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant