Repository navigation
fix(github): mask a short token without a panic - #9450
Open
henry-rystic wants to merge 1 commit into
Open
henry-rystic wants to merge 1 commit into
henry-rystic wants to merge 1 commit into
Conversation
A token with a known prefix that is shorter than the masked range made SanitizeToken slice out of range. The panic broke the create request after the row was saved, and then every list request. Mask such a token as a generic string instead. Do the same for a short app secret key. Closes apache#9446 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Henry Starman <334243260+henry-rystic@users.noreply.github.com>
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.
Summary
A GitHub token with a known prefix, but too short, causes a panic.
Cause:
SanitizeTokeninbackend/plugins/github/models/connection.gochecked onlytokenLen >= prefixLen.ghp_and the other classic prefixes) or 85 (github_pat_).Fix:
SanitizeTokennow masks it withutils.SanitizeString. This shows the first 2 and the last 2 characters, for examplegh*****rt.SanitizeSecrethad the same kind of bug. A GitHub App private key of 100 characters or less madestrings.Repeatpanic. It now usesutils.SanitizeStringtoo.prefixLen != 0 && hiddenLen != 0is always true. It is removed.Does this close any open issues?
Closes #9446
Screenshots
N/A
Other Information
Tests added in
backend/plugins/github/models/connection_test.go:TestGithubConnection_Sanitizetable, with literal expected values:ghp_becomesg**_,ghp_shortbecomesgh*****rt, a classic token one character below 32, a classic token of exactly 32 characters,github_pat_tokens of 30, 84 and 85 characters, and a list with a valid token and a short token.TestGithubConn_SanitizeSecret: a table test for app keys of 5, 99, 100 and 101 characters.Without the fix, each short case fails with
slice bounds out of rangeornegative Repeat count. A key of exactly 100 characters was returned without a mask, and now it is masked. The rows at the exact limit (32 and 85 characters) and the key of 101 characters check the boundary, so they pass before and after the fix.go test ./plugins/github/...passes on MySQL 8.4 and PostgreSQL 17, andgo vetpasses.Manual test. I built the backend image from this branch and ran it with MySQL 8.4. I ran the same steps on
apache/devlake:main_261124_0230_52d63a1to compare.POST /plugins/github/connectionswith a valid token.POST /plugins/github/connectionswith"token":"ghp_short".gh*****rt.GET /plugins/github/connections.GET /plugins/github/connections/<short id>.POST /plugins/github/connectionswith agithub_pat_token of 30 characters.DELETE /plugins/github/connections/<short id>.Not changed. A short token is still accepted on create, because masking is enough to fix the list. GitHub rejects the token when the connection is tested.
This PR was prepared with AI assistance (Claude Code). The commits carry a
Co-Authored-By:trailer.🤖 Generated with Claude Code