fix regex for checking github fine-grained tokens#130
fix regex for checking github fine-grained tokens#130tstromberg merged 2 commits intocodeGROOVE-dev:mainfrom
Conversation
|
There was a problem hiding this comment.
Pull request overview
Updates GitHub fine-grained personal access token (PAT) detection/redaction to match the documented github_pat_<22 base62>_<59 base62> format used by GitHub.
Changes:
- Update
githubTokenRegexto validate fine-grained PATs with the22 + '_' + 59base62 segment format. - Update
sanitizeForLogto redact fine-grained PATs using the new segmented format. - Adjust and extend unit tests to cover the new valid format and reject the old 82-char-suffix format.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| cmd/reviewGOOSE/security.go | Updates token validation + log redaction regex for fine-grained PAT format. |
| cmd/reviewGOOSE/security_test.go | Updates test vectors for fine-grained PATs and adds an invalid-case test. |
Comments suppressed due to low confidence (1)
cmd/reviewGOOSE/security.go:87
- sanitizeForLog recompiles several regular expressions on every call (MustCompile inside the function). Since this runs on log paths, consider precompiling these regexps once at package scope (similar to githubTokenRegex) and reusing them to avoid repeated compilation overhead.
s = regexp.MustCompile(`\b[a-f0-9]{40}\b`).ReplaceAllString(s, "[REDACTED-TOKEN]")
// New format tokens (ghp_, ghs_, ghr_, gho_, ghu_)
s = regexp.MustCompile(`\bgh[psoru]_[A-Za-z0-9]{36,251}\b`).ReplaceAllString(s, "[REDACTED-TOKEN]")
// Fine-grained personal access tokens
s = regexp.MustCompile(`\bgithub_pat_[a-zA-Z0-9]{22}_[a-zA-Z0-9]{59}\b`).ReplaceAllString(s, "[REDACTED-TOKEN]")
// Bearer tokens in headers
s = regexp.MustCompile(`Bearer [A-Za-z0-9_\-.]+`).ReplaceAllString(s, "Bearer [REDACTED]")
// Authorization headers
s = regexp.MustCompile(`Authorization: \S+`).ReplaceAllString(s, "Authorization: [REDACTED]")
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
the pattern for github fine-grained token has
github_pat_prefix, followed by two base62 chars segments, all separated with an underscore - ie: