fix(security): detect GitHub stateless token format (~520 chars)#530
Merged
Conversation
GitHub App installation tokens (ghs_) are moving to a stateless format
that is much longer (~520 chars) than today's 40-char tokens. Two
detection layers hardcoded the old length and silently break on it:
- internal/security/patterns/tokens.go: ghp_/gho_/ghs_/ghr_ patterns
pinned to exactly {36} chars. FindAllString still substring-matched a
longer token but truncated the capture to 40 chars, so the recorded
detection dropped the ~480-char tail. Widened to {36,}.
- internal/logs/sanitizer.go: github_token mask regex bounded at
{36,255} with \b anchors. A ~520-char alphanumeric run has no word
boundary within range, so the regex matched nothing and the token
leaked into logs unmasked. Widened to {36,}.
Short-token rejection (ghp_12345) and 40-char tokens still behave as
before. Added tests asserting full capture / masking of a 520-char token.
Deploying mcpproxy-docs with
|
| Latest commit: |
89ea1d0
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://0b49110a.mcpproxy-docs.pages.dev |
| Branch Preview URL: | https://fix-github-stateless-token-d.mcpproxy-docs.pages.dev |
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
📦 Build ArtifactsWorkflow Run: View Run Available Artifacts
How to DownloadOption 1: GitHub Web UI (easiest)
Option 2: GitHub CLI gh run download 26437210697 --repo smart-mcp-proxy/mcpproxy-go
|
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.
Why
GitHub notified that GitHub App installation tokens are moving to a new stateless format (
ghs_…) that is much longer (~520 chars) than today's 40-char tokens, warning that "apps with hardcoded length assumptions may break."Two of mcpproxy's secret-handling layers hardcoded the old length and silently break on the new format:
internal/security/patterns/tokens.go)ghp_/gho_/ghs_/ghr_pinned to{36}FindAllStringsubstring-matched a longer token but truncated the capture to 40 chars — the recorded detection dropped the ~480-char tail, so the token tail could be stored in plaintext in the activity loginternal/logs/sanitizer.go)\b(gh[poushr]_[A-Za-z0-9]{36,255})\b\bword boundary within{36,255}, so the regex matched nothing and the token leaked into logs unmaskedWhat
{36,}.ghp_12345) and existing 40-char behavior unchanged.Tests (TDD)
TestGitHubTokenPatterns_LongStatelessFormat— asserts the full 520-char token is captured for all four prefixes (failed showing 40-of-520 truncation before the fix).TestSanitizer_GitHubTokens+TestSanitizer_LongStatelessGitHubToken(newinternal/logs/sanitizer_test.go) — long token leaked unmasked before, masked after; 40-char tokens still masked.Verification:
internal/security/patterns,internal/logs,internal/securityall pass; gofmt clean,go vetclean. E2E suite shows the same 10 pre-existing failures with and without this change (unrelatedupstream_serversenv/args/headers flow), so no regression introduced. The tool-approval-hash stability canary is unaffected — this only touches detection/redaction regexes.