fix: Update GitHub token detector for new App token format#961
Open
Mallikarjunadevops wants to merge 1 commit into
Open
fix: Update GitHub token detector for new App token format#961Mallikarjunadevops wants to merge 1 commit into
Mallikarjunadevops wants to merge 1 commit into
Conversation
omobolajiadeyan
suggested changes
Jun 8, 2026
omobolajiadeyan
left a comment
There was a problem hiding this comment.
Thank you for covering the new installation-token rollout. I reproduced this branch locally, and there are two correctness issues to address before merge:
- GitHub changed only installation tokens (
ghs_). The current pattern applies{36,519}plus JWT punctuation toghp,gho,ghu, andghras well, so those token types can now consume arbitrary long dotted/hyphenated strings. GitHub's current recommended compatibility regex is specificallyghs_[A-Za-z0-9\.\-_]{36,}. It also deliberately has no upper bound because clients should treat the token as opaque;519reintroduces a length assumption and may truncate a valid token. - The prefix alternation remains a capturing group.
RegexBasedDetector.analyze_string()usesfindall(), so this branch yields only the captured prefix. My direct check producedfinding_values=['ghp']for a classic token andfinding_values=['ghs']for the new sample, rather than the full secret. The existing count-only test does not catch this.
A compatible shape would be two non-capturing/full-match patterns, for example:
re.compile(r'(?:ghp|gho|ghu|ghr)_[A-Za-z0-9_]{36}')
re.compile(r'ghs_[A-Za-z0-9._-]{36,}')The second pattern covers both classic and stateless ghs_ tokens. Please add assertions on the exact detected secret_value, not only len(output), plus a stateless sample longer than 519 characters to protect the opaque/unbounded requirement.
Local verification performed: python -m pytest tests/plugins/github_token_test.py -v (4 passed), followed by direct analyze_string() and analyze_line() inspection.
Official guidance:
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.
Issue 958: GitHubTokenDetector misses new GitHub App installation token format
What kind of change does this PR introduce?
Bug fix
What is the current behavior?
GitHubTokenDetectoruses a regex that only matches classic 36-character prefixes (likeghp_...). It fails to match the new GitHub App installation token format (ghs_APPID_JWT) which is ~520 characters long. (Fixes #958)What is the new behavior?
Updates the GitHub token regex in
detect_secrets/plugins/github_token.pyto allow matching up to 519 characters with periods, hyphens, etc.re.compile(r'(ghp|gho|ghu|ghs|ghr)_[A-Za-z0-9_.-]{36,519}'). This covers the new App installation token formats.Does this PR introduce a breaking change?
No
Other information:
Added test case in
tests/plugins/github_token_test.pywith a dummy new token formatghs_12345_eyJhbGciOiJSUzI1NiJ9.A*100.B*100and verified the detector successfully flags it.Testing Evidence
Pytest completed successfully for all test cases in
tests/plugins/github_token_test.py.