Repository navigation
fix(logs): mask fine-grained github_pat_ tokens - #1784
Open
rudycelekli wants to merge 1 commit into
Open
rudycelekli wants to merge 1 commit into
rudycelekli wants to merge 1 commit into
Conversation
The github_token pattern only covered the gh?_ prefixes. Fine-grained personal access tokens (github_pat_<id>_<secret>), the format GitHub now creates by default, matched nothing in free text and were logged in full.
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
This branch has not been deployed
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.
Bug
The log sanitizer's
github_tokenpattern is\b(gh[poushr]_[A-Za-z0-9]{36,})\b. It does not cover fine-grained personal access tokens (github_pat_<id>_<secret>), which is the format GitHub creates by default and the one the GitHub MCP server docs tell people to put inGITHUB_PERSONAL_ACCESS_TOKEN.No other pattern catches the token in free text.
bearer_tokenonly applies afterBearer, andhigh_entropyneeds a=/:/quote prefix and excludes_, so its 30+ character run never starts right after the prefix.The security pattern set already matches this format (
patterns/tokens.go:github_pat_[a-zA-Z0-9]+_[a-zA-Z0-9]{30,}). The log sanitizer never got the same branch.Trigger
On main this line is written unchanged.
Fix
Add a
github_pat_[A-Za-z0-9]+_[A-Za-z0-9]{30,}branch togithub_token. It uses the same shape as the security pattern and the existing mask (github_***<last2>).Test
A fine-grained case was added to
TestSanitizer_GitHubTokens. The leak check now looks for the token body (token[12:]) instead of the whole token, so a partial mask can't pass.Commands run
CGO_ENABLED=0 go test -count=1 ./internal/logs: oksanitizer.goreverted,TestSanitizer_GitHubTokens/fine-grained_github_pat_fails withtoken leaked unmasked.gofmt -l internal/logs: no output