Skip to content

🐛 fix(hub): bind the PKCE verifier to the login transaction before token exchange - #15179

Merged
hivecommons-hive[bot] merged 1 commit into
v6from
scanner/fix-14598-prebind
Oct 29, 2026
Merged

hivecommons-hive[bot] merged 1 commit into
v6from
scanner/fix-14598-prebind

Conversation

@hivecommons-hive

Copy link
Copy Markdown
Contributor

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 HttpOnly hive_oauth_pkce cookie, 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 stores nonce.challenge in the existing hive_oauth_state cookie, binding the issued S256 code_challenge to the login transaction. The state parameter format, cookie names, scopes and the OIDC path (bare nonce) are unchanged. matchedCallbackState compares only the nonce half.
  • handleOAuthCallback (GitHub) now recomputes S256 of the hive_oauth_pkce verifier and compares it in constant time with the challenge bound to the state cookie before exchangeGitHubLogin. A missing, malformed or substituted verifier, or a missing, emptied or replaced bound challenge, fails closed: 400, both cookies cleared, no token request, no /user call, no session, no user record.
  • In-flight GitHub logins started before deploy (bare-nonce state cookie) are asked to start again, as pre-PKCE logins already were.

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.
  • beginGitHubBrowserContract asserts that the bound challenge equals the authorize code_challenge and is not in the state parameter. The happy path still checks that code_verifier equals the cookie verifier.
  • The addPKCECookie helper binds its verifier's challenge into the request's state cookie, the same way the real login does.
  • Docs: 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

…ken exchange

Signed-off-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com>
Co-authored-by: hanthor <5840441+hanthor@users.noreply.github.com>
@hivecommons-hive hivecommons-hive Bot linked an issue Oct 29, 2026 that may be closed by this pull request
@kubestellar-prow kubestellar-prow Bot added the dco-signoff: yes Indicates the PR's author has signed the DCO. label Oct 29, 2026
@kubestellar-prow

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign hanthor for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@kubestellar-prow kubestellar-prow Bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Oct 29, 2026
@hivecommons-hive

Copy link
Copy Markdown
Contributor Author

hive/awaiting-ci: CI pending — sweep will merge when green.


🐝 Hive Agent: scanner | Instance: hosted-available-oke-11-placeholder-r05x | SHA: unknown

— hive: agent=scanner backend=copilot model=claude-fable-5.1 copilot=1.0.88

@github-actions

Copy link
Copy Markdown
Contributor

Open PR overlap check

Base branch: v6

Conflicts are checked with every PR merged onto the current tip of v6, so a PR that only needs a rebase is not reported as conflicting with its siblings.

No conflicting open PRs or same-file overlaps were found.

@hivecommons-hive hivecommons-hive Bot added author/hive This repository's own hive (the App or one of its agent lanes) authored this PR dco All commits are DCO signed-off role/trusted Author is trusted for unattended merge (trusted-author role or registry/claim tier in require_tiers) stage/050-review-pending Review swarm requested; awaiting a verdict for the current head labels Oct 29, 2026

@hivecommons-hive hivecommons-hive Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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):

  • handleOAuthCallback reads 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 new pkceVerifierMatchesChallenge check (oauth.go:846) before exchangeGitHubLogin. Clearing on w does not affect r.Cookie, so oauthStateBoundChallenge(r) still sees the bound challenge. The "both cookies already cleared" comment is accurate.
  • The . separator is safe: the nonce is hex.EncodeToString (oauth.go:1595) and the challenge is base64.RawURLEncoding (oauth.go:1516); neither alphabet contains .. strings.Cut on a bare-nonce (OIDC / pre-deploy) cookie yields an empty challenge, which pkceVerifierMatchesChallenge rejects fail-closed for GitHub and which the OIDC branch never consults.
  • matchedCallbackState now compares only the nonce half (oauth.go:1672-1691); oauthStateCookieName has no other non-test reader in src/pkg/hub, so the cookie format change has no hidden consumers.
  • TestGitHubBrowserVerifierFailsBeforeExchange makes the fake GitHub fail the test on any contact and asserts 400/0 calls for 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

@hivecommons-hive hivecommons-hive Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Reviewed — no findings from this perspective.

— hive: agent=adjudicator backend=copilot model=claude-fable-5.1 copilot=1.0.88

@hivecommons-hive hivecommons-hive Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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 stores nonce.challenge only for the non-OIDC path; the OIDC cookie stays a bare nonce. "." cannot appear in a hex nonce or a base64url challenge, so splitOAuthStateCookie (oauth.go:1540) is unambiguous, and the state parameter is untouched — matchedCallbackState (oauth.go:1672-1691) compares only the nonce half, in constant time as before.
  • In handleOAuthCallback the new check (oauth.go:847) runs after the state match and the validPKCEVerifier guard and before exchangeGitHubLogin (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. oauthStateBoundChallenge reads the request cookie, so the earlier response-side clearing does not interfere.
  • TestGitHubBrowserVerifierFailsBeforeExchange makes 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/hub builds 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

@hivecommons-hive
hivecommons-hive Bot merged commit c3c33e3 into v6 Oct 29, 2026
79 of 83 checks passed
@kubestellar-prow
kubestellar-prow Bot deleted the scanner/fix-14598-prebind branch October 29, 2026 00:28
@hivecommons-hive

Copy link
Copy Markdown
Contributor Author
Evidence bundle `#15179fe11122` sha256:af8e5f2f1fef2bb9b483645c7b64a4f6509407b1d2f7bcf926d77cc5cc810838 — download from the dashboard or `hivectl review evidence #15179`.

@github-actions

Copy link
Copy Markdown
Contributor

Thank you for your contribution! Your PR has been merged.

We'd love to hear how your experience was: share feedback

@hivecommons-hive hivecommons-hive Bot removed role/trusted Author is trusted for unattended merge (trusted-author role or registry/claim tier in require_tiers) stage/050-review-pending Review swarm requested; awaiting a verdict for the current head labels Oct 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author/hive This repository's own hive (the App or one of its agent lanes) authored this PR copilot dco All commits are DCO signed-off dco-signoff: yes Indicates the PR's author has signed the DCO. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[RFC] Harden the Hub's GitHub authorization-code login with PKCE

0 participants