Skip to content

fix: update GitHub token redaction regex for new JWT format - #736

Merged
waynesun09 merged 2 commits into
mainfrom
fix-token-redactor-regex
May 8, 2026
Merged

fix: update GitHub token redaction regex for new JWT format#736
waynesun09 merged 2 commits into
mainfrom
fix-token-redactor-regex

Conversation

@waynesun09

Copy link
Copy Markdown
Member

Summary

  • Update GitHub token prefix regex patterns (ghp_, gho_, ghu_, ghs_, ghr_) to include underscores in the character class
  • GitHub's April 2026 token format change introduces ghs_APPID_JWT tokens (~520 chars) containing underscores between segments
  • The previous [a-zA-Z0-9] character class would fail to match the full token, leaving new-format installation tokens unredacted in logs
  • Add test case verifying redaction of JWT-style ghs_ tokens with underscores

Test plan

  • go test ./internal/security/... -run TestSecretRedactor — all pass including new JWT format test
  • go vet ./internal/security/... — clean
  • Existing github_pat test still passes (no regression)

GitHub's April 2026 token format change introduces underscores in
ghs_ installation tokens (ghs_APPID_JWT, ~520 chars). The existing
regex [a-zA-Z0-9] fails to match these, causing tokens to leak
unredacted in logs. Add underscore to the character class for all
GitHub token prefix patterns (ghp_, gho_, ghu_, ghs_, ghr_).

Signed-off-by: Wayne Sun <gsun@redhat.com>
@github-actions

github-actions Bot commented May 7, 2026

Copy link
Copy Markdown

fullsend review is working on this — view logs

@github-actions

github-actions Bot commented May 7, 2026

Copy link
Copy Markdown

Site preview

Preview: https://64c5df6f-site.fullsend-ai.workers.dev

Commit: 23ffc72b3fd28ab04ae128185856f27d742ccfef

@fullsend-ai-review

fullsend-ai-review Bot commented May 7, 2026

Copy link
Copy Markdown

Review: #736

Head SHA: 23ffc72
Timestamp: 2026-05-07T00:00:00Z
Outcome: approve

Summary

The change correctly broadens GitHub token redaction regex patterns to handle the new JWT-style installation token format (ghs_APPID_HEADER.PAYLOAD.SIGNATURE) introduced in GitHub's April 2026 token format change. The regex modifications are sound — [a-zA-Z0-9_.\-] for ghs_ correctly matches all base64url characters plus JWT dot separators, and adding underscores to the other token patterns (ghp_, gho_, ghu_, ghr_) is a defensive broadening consistent with the existing github_fine_pat pattern. The test case constructs a realistic ~520 character JWT-format token and validates redaction. No correctness, security, or injection concerns identified.

Findings

Info

  • [style] internal/security/redactor.go:137 — The ghs_ character class [a-zA-Z0-9_.\-] uses an escaped hyphen (\-). While correct in RE2, placing the hyphen at the end ([a-zA-Z0-9_.-]) is the conventional way to include a literal hyphen in a character class and avoids any ambiguity.

Footer

Outcome: approve
This review applies to SHA 23ffc72b3fd28ab04ae128185856f27d742ccfef. Any push to the PR head clears this review and requires a new evaluation.

Previous run

Review: #736

Head SHA: 4c0f372
Timestamp: 2026-05-07T00:00:00Z
Outcome: approve

Summary

This is a well-scoped security fix that adds underscore (_) to the character class of five GitHub token redaction regex patterns (ghp_, gho_, ghu_, ghs_, ghr_), aligning them with the existing github_fine_pat pattern which already included underscores. Without this fix, GitHub's new JWT-format installation tokens (which contain underscores between segments) would only be partially matched, causing the redactor to stop at the first underscore and leak the remainder of the token in logs. The minimum match length of 36 characters is preserved, keeping false-positive risk negligible. The new test case constructs a realistic ~514-character JWT-style ghs_ token and verifies complete redaction. No issues found across correctness, intent alignment, platform security, content security, injection defense, or style dimensions.

Findings

No findings.

Footer

Outcome: approve
This review applies to SHA 4c0f37210a2eb821335b22c5f106a72940b496c7. Any push to the PR head clears this review and requires a new evaluation.

@ralphbean ralphbean left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch on the token format change. Two notes below — neither blocks merge, but worth considering before the broader rollout hits.

Sources consulted:

Comment thread internal/security/redactor.go Outdated
{"github_pat", `ghp_[a-zA-Z0-9_]{36,}`},
{"github_oauth", `gho_[a-zA-Z0-9_]{36,}`},
{"github_user_token", `ghu_[a-zA-Z0-9_]{36,}`},
{"github_server_token", `ghs_[a-zA-Z0-9_]{36,}`},

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[critical — deferred] The GitHub blog post describes the new format as ghs_APPID_JWT and says tokens should be treated as opaque strings (~520 chars). Standard JWTs contain dots (.) as segment separators and base64url encoding uses hyphens (-). If the actual token includes these characters, this regex [a-zA-Z0-9_] will stop matching at the first dot, leaking the remaining JWT segments unredacted.

The test case at scanner_test.go constructs a token by repeating a base64 string without dots, so it wouldn't catch this.

Worth verifying against a real token from the rollout (which started April 27). If dots are present, the character class should be [a-zA-Z0-9_.\-] and the test should include a dot-separated JWT structure.

Ref: https://github.blog/changelog/2026-04-24-notice-about-upcoming-new-format-for-github-app-installation-tokens/

{"github_user_token", `ghu_[a-zA-Z0-9]{36,}`},
{"github_server_token", `ghs_[a-zA-Z0-9]{36,}`},
{"github_refresh_token", `ghr_[a-zA-Z0-9]{36,}`},
{"github_pat", `ghp_[a-zA-Z0-9_]{36,}`},

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[moderate — informational] Per the GitHub announcement, only ghs_ (installation server-to-server) tokens are changing to the JWT format right now. The other types (ghp_, gho_, ghu_, ghr_) are noted as being "addressed separately in future updates." Adding _ to all five is harmless and arguably good future-proofing — just noting for accuracy.

The new JWT-based ghs_ tokens use base64url segments separated by
dots (header.payload.signature). The previous character class
[a-zA-Z0-9_] stops matching at the first dot, leaking the remaining
JWT segments unredacted. Update ghs_ pattern to [a-zA-Z0-9_.\-] and
fix the test to use a realistic dot-separated JWT structure.

Signed-off-by: Wayne Sun <gsun@redhat.com>
@github-actions

github-actions Bot commented May 7, 2026

Copy link
Copy Markdown

fullsend review is working on this — view logs

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.

3 participants