fix(oauth): narrow MINT_REPO_TOKEN's response with typeof before storing it - #6988
Open
pedrofrxncx wants to merge 1 commit into
Open
fix(oauth): narrow MINT_REPO_TOKEN's response with typeof before storing it#6988pedrofrxncx wants to merge 1 commit into
pedrofrxncx wants to merge 1 commit into
Conversation
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.
Source: bug found while hardening the OAuth token-refresh lane (
apps/api/src/oauth/).Why:
github-mint.ts'smintRepoTokenreadsres.structuredContent?.tokenfrom the (untrusted) response of theMINT_REPO_TOKENMCP tool call and passes it straight through as the connection'saccessToken, trusting an uncheckedas MintResultcast. Every sibling OAuth response-parsing path in this same directory (refresh-access-token.ts'saccess_token/expires_inhandling) explicitly narrows withtypeofbefore trusting server-controlled fields — this one didn't, so a malformed or non-stringtoken/expiresAtfrom a misbehaving/misconfiguredmcp-github-slugged connection would reach the token vault (tokenStorage.upsert) as a non-stringaccessToken, or produce anInvalid DateforexpiresAt.Fix: extracted the parsing into a pure
extractMintedToken(res)helper that:RECONNECT_ERROR) whenstructuredContent.tokenisn't a non-empty string (matches theaccess_tokentypeof-guard pattern inrefresh-access-token.ts)expiresAtwhen it's a string that parses to a validDate, otherwise falls back tonull(the existingresolveGhsExpiryfallback then computes a safe expiry)Behavior-preserving for well-formed responses (byte-identical logic, just extracted + typeof-guarded); the only behavior change is refusing to persist a malformed field instead of silently trusting it.
Verify:
bun test apps/api/src/oauth/github-mint.test.ts— 6 new cases covering isError, missing/non-string token, and non-string/unparseable expiresAt, plus the existingresolveGhsExpirysuite, all green.Checks run locally:
bun run fmt,cd apps/api && bunx tsc --noEmit, the targeted test file above,bunx oxlinton both changed files (0 warnings/errors). Full CI validates the rest.Summary by cubic
Hardens the OAuth token-refresh lane by type-checking
MINT_REPO_TOKEN's response before persisting it, so malformed tool output can't reach the token vault.extractMintedToken, which rejects non-string tokens and falls back tonullexpiry for invalid dates.RECONNECT_ERRORwhen the token is missing or not a string, matching the pattern inrefresh-access-token.ts.Written for commit c49a095. Summary will update on new commits.