Repository navigation
🐛 fix(hub): bind the PKCE verifier to the login transaction before token exchange - #15179
Conversation
…ken exchange Signed-off-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com> Co-authored-by: hanthor <5840441+hanthor@users.noreply.github.com>
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
hive/awaiting-ci: CI pending — sweep will merge when green. 🐝 Hive Agent: — hive: agent=scanner backend=copilot model=claude-fable-5.1 copilot=1.0.88 |
Open PR overlap checkBase branch: Conflicts are checked with every PR merged onto the current tip of No conflicting open PRs or same-file overlaps were found. |
There was a problem hiding this comment.
Read src/pkg/hub/oauth.go at fe11122 plus the callers; this looks correct to me.
What I verified in the tree (not just the diff):
handleOAuthCallbackreads and clears the PKCE cookie first (oauth.go:757-760), then verifies the state nonce and clears the state cookie (oauth.go:775-782), and only then runs the newpkceVerifierMatchesChallengecheck (oauth.go:846) beforeexchangeGitHubLogin. Clearing onwdoes not affectr.Cookie, sooauthStateBoundChallenge(r)still sees the bound challenge. The "both cookies already cleared" comment is accurate.- The
.separator is safe: the nonce ishex.EncodeToString(oauth.go:1595) and the challenge isbase64.RawURLEncoding(oauth.go:1516); neither alphabet contains..strings.Cuton a bare-nonce (OIDC / pre-deploy) cookie yields an empty challenge, whichpkceVerifierMatchesChallengerejects fail-closed for GitHub and which the OIDC branch never consults. matchedCallbackStatenow compares only the nonce half (oauth.go:1672-1691);oauthStateCookieNamehas no other non-test reader insrc/pkg/hub, so the cookie format change has no hidden consumers.TestGitHubBrowserVerifierFailsBeforeExchangemakes the fake GitHub fail the test on any contact and asserts400/0 callsfor substituted, mutated, replaced, stripped and emptied cases — that covers the gap the issue named.
No findings. CI test (hub 1/4..4/4) is green at this head.
— hive: agent=reviewer-2 backend=copilot model=claude-fable-5.1 copilot=1.0.88
There was a problem hiding this comment.
Read the diff against the v6 tree (src/pkg/hub/oauth.go at fe11122, plus the three test files) and the callback path end to end. The change does what the body says and I found no correctness or security defect.
What I verified
startProviderLogin(oauth.go:584-600) now mints the verifier before the state cookie and storesnonce.challengeonly for the non-OIDC path; the OIDC cookie stays a bare nonce."."cannot appear in a hex nonce or a base64url challenge, sosplitOAuthStateCookie(oauth.go:1540) is unambiguous, and thestateparameter is untouched —matchedCallbackState(oauth.go:1672-1691) compares only the nonce half, in constant time as before.- In
handleOAuthCallbackthe new check (oauth.go:847) runs after the state match and thevalidPKCEVerifierguard and beforeexchangeGitHubLogin(oauth.go:852).pkceVerifierMatchesChallenge(oauth.go:1560) fails closed on an empty bound challenge, so a pre-deploy bare-nonce cookie or a stripped challenge is a 400, not a bypass.oauthStateBoundChallengereads the request cookie, so the earlier response-side clearing does not interfere. TestGitHubBrowserVerifierFailsBeforeExchangemakes the fake GitHub fail the test on any contact and covers substituted 43/128-char verifiers, a one-char-mutated verifier, and replaced/stripped/emptied bound challenges.pkg/hubbuilds at this head and the hub test shards are green in CI.
One low-severity docs-currency item
src/docs/hub-login-token.md keeps the citations oauth.go:627, :744, :825, :975 while the diff inserts ~20 lines above them. At fe11122 those lines are now a comment, an HTML <h1>, a } and a }; the authorize URL is at oauth.go:638, handleOAuthCallback at :754, the pre-exchange guards at :836-847, and exchangeGitHubLogin at :996. Nothing in CI gates this file, so it will only drift further — worth refreshing in this PR since the same paragraph is being edited.
Looks correct to me otherwise; this is a trust-surface change (login/PKCE), so the final call belongs to a maintainer.
— hive: agent=reviewer backend=copilot model=claude-fable-5.1 copilot=1.0.88
|
Thank you for your contribution! Your PR has been merged. We'd love to hear how your experience was: share feedback |
Closes #14598
This resolves the last open acceptance item of the RFC. Everything else already landed: #14683, #14701 and #14893 (form-POST token exchange with the exact
redirect_uri, S256 PKCE verifier in the HttpOnlyhive_oauth_pkcecookie, fail-closed callback) and #15128 (browser-contract tests).Why
@hanthor's remaining requirement on the issue: a syntactically valid but substituted verifier was only caught by GitHub during the token exchange, not locally, and the existing rejection fixture used the original verifier with an unconditional endpoint error. This PR adds the local pre-exchange binding and real mismatch coverage.
What changes
startProviderLogin(GitHub) mints the verifier before the state cookie and storesnonce.challengein the existinghive_oauth_statecookie, binding the issued S256code_challengeto the login transaction. Thestateparameter format, cookie names, scopes and the OIDC path (bare nonce) are unchanged.matchedCallbackStatecompares only the nonce half.handleOAuthCallback(GitHub) now recomputes S256 of thehive_oauth_pkceverifier and compares it in constant time with the challenge bound to the state cookie beforeexchangeGitHubLogin. A missing, malformed or substituted verifier, or a missing, emptied or replaced bound challenge, fails closed:400, both cookies cleared, no token request, no/usercall, no session, no user record.Tests
TestGitHubBrowserVerifierFailsBeforeExchange: the fake GitHub now fails the test if it is contacted at all. New cases: substituted valid 43-char verifier, substituted 128-char verifier, issued verifier with one character changed, state-bound challenge replaced, stripped, or emptied. Each case asserts zero endpoint calls, no session, no user record, and both cookies cleared.beginGitHubBrowserContractasserts that the bound challenge equals the authorizecode_challengeand is not in thestateparameter. The happy path still checks thatcode_verifierequals the cookie verifier.addPKCECookiehelper binds its verifier's challenge into the request's state cookie, the same way the real login does.src/docs/hub-login-token.md. Changelog:changelog.d/security-14598-pkce-prebind.md.I did not run the tests locally, following AGENTS.md. CI decides whether this passes.
— hive: agent=scanner backend=copilot model=claude-fable-5.1 copilot=1.0.88 requested_by=@hanthor