Skip to content

🌱 test(hub): pin PKCE verifier in the GitHub browser login contract - #15128

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

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

Conversation

@hivecommons-hive

@hivecommons-hive hivecommons-hive Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Refs #14598

Summary

#14683 and #14701 already landed every behavior item in the RFC on v6: the form-POST exchange with exact redirect_uri, the token-consumer docs, the S256 PKCE verifier cookie and the fail-closed callback. #14893 pinned the state contract. This PR adds PKCE assertions to the end-to-end browser contract and documents them. The literal pre-exchange mismatch requirement remains open in #14598; endpoint rejection coverage does not establish local verifier-transaction binding. It changes no production code.

Tests (src/pkg/hub/oauth_browser_contract_test.go)

  • beginGitHubBrowserContract now requires a hive_oauth_pkce cookie that is HttpOnly, Secure, Lax, short-lived and holds a valid verifier. It also requires code_challenge_method=S256 with code_challenge = S256(cookie verifier), and checks the verifier itself never appears in the authorize URL.
  • TestGitHubBrowserLoginContract:
    • The token form must carry code_verifier equal to the cookie verifier.
    • The verifier joins the list of values that must never appear in a request URL or the logs.
    • The PKCE cookie must be cleared on every outcome.
    • Failed logins must write no user record.
    • New case verifier rejected: GitHub answers bad_verification_code for a verifier that doesn't match the challenge. The callback must return 502 with no /user call, no session and no user record.
  • New TestGitHubBrowserVerifierFailsBeforeExchange: the state is valid, but the verifier is missing (expired or never issued), empty, malformed or truncated. Each case must return 400 with zero token-endpoint calls, no session, no user record, a cleared PKCE cookie, and no code or verifier in the logs.
  • Removed the stale "once [scanner] hub-auth: add S256 PKCE verifier cookie to Hub GitHub login #14633 lands" TODO.

Docs

src/docs/hub-login-token.md now describes the PKCE step and the fail-closed matrix, and its oauth.go line references are updated to current v6.

Related

Validation

Not run locally: tests run in CI. gofmt is clean.

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

Extend the browser-login contract tests: the authorize redirect must carry the
S256 challenge of the hive_oauth_pkce cookie, the exchange must send that exact
code_verifier in the form body, a missing/expired/malformed/truncated verifier
must fail with 400 before the code is redeemed, a GitHub-rejected verifier must
mint no session or user record, and the verifier must never reach a request URL
or the logs. Document the PKCE step and fail-closed matrix in
src/docs/hub-login-token.md and refresh its line references.

Refs #14598

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com>
@kubestellar-prow kubestellar-prow Bot added the dco-signoff: yes Indicates the PR's author has signed the DCO. label Oct 28, 2026
@hivecommons-hive
hivecommons-hive Bot requested a review from Danathar as a code owner October 28, 2026 21:56
@hivecommons-hive hivecommons-hive Bot linked an issue Oct 28, 2026 that may be closed by this pull request
@kubestellar-prow kubestellar-prow Bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Oct 28, 2026
@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 28, 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

@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 new assertions against src/pkg/hub/oauth.go at 787d67e; they pin what the code already does and nothing more. Looks correct to me.

  • Fail-closed ordering: handleOAuthCallback reads and clears the PKCE cookie at oauth.go:746-747 before any other check, and validPKCEVerifier at oauth.go:825 returns 400 before exchangeGitHubLogin (:830) — so TestGitHubBrowserVerifierFailsBeforeExchange expecting 400/0 calls and a cleared cookie on every case matches the code path.
  • truncated case: oauthPKCEVerifier mints 32 bytes → 43 base64url chars, so v[:42] falls under the 43-char floor at oauth.go:1492.
  • verifier rejected case: an error body with no access_token hits oauth.go:1014 → 502 with zero /user calls, as the table expects.
  • Docs: all eight oauth.go:N citations in src/docs/hub-login-token.md resolve to the lines they describe on this head (checked each one).

No production code changes; CI test (hub 1-4/4) green.

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

@hivecommons-hive hivecommons-hive Bot added stage/060-reviewed Review swarm verdict approve; a gate is still pending (CI running, soak not started) and removed stage/050-review-pending Review swarm requested; awaiting a verdict for the current head labels Oct 28, 2026

@hanthor hanthor left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewed head 787d67e against the production OAuth flow and existing PKCE tests. The cookie/challenge assertions, exact verifier form-field check, invalid-verifier rejection matrix, and no-session/no-user-record assertions match the implementation. No patch-introduced production bug found; Hub shards and aggregate tests/coverage have passed.

Please reconcile the closure claim before merging: #14598/#14636 literally require mismatched verifiers to fail before token exchange, whereas the new verifier-rejected case submits the original issued verifier and returns an unconditional token-endpoint error after one exchange. It covers rejection handling, not a substituted valid verifier or zero-exchange mismatch rejection. Replace Fixes #14598 with Refs #14598 until that acceptance discrepancy is resolved, and exercise the actual substituted-verifier transaction if claiming mismatch coverage. Keep #14598 open rather than implicitly treating every criterion as fulfilled. Retain all normal CI and owner-approval gates.

@hanthor hanthor left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approving the scoped tests/documentation change at 787d67e, not declaring every RFC acceptance criterion complete. I have changed the closing reference to Refs #14598 and qualified the completion claim so the mismatch/pre-exchange question remains explicitly open. The new assertions match the existing production behavior; normal CI and required owner-approval gates still apply. No OAuth security requirement or failing check is waived.

@kubestellar-prow kubestellar-prow Bot added the lgtm Indicates that a PR is ready to be merged. label Oct 28, 2026
@kubestellar-prow

Copy link
Copy Markdown
Contributor

LGTM label has been added.

DetailsGit tree hash: 6d13f43446aea7e2b473777aa3123793db87206b

@hanthor

hanthor commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

/lgtm
/approve

Scoped approval for the tests/docs at 787d67e. The PR now references rather than closes #14598; its literal pre-exchange mismatch requirement remains open. Keep all normal CI and merge gates.

@kubestellar-prow

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: hanthor

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

The pull request process is described 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 approved Indicates a PR has been approved by an approver from all required OWNERS files. label Oct 28, 2026
@hivecommons-hive
hivecommons-hive Bot merged commit efe577b into v6 Oct 28, 2026
87 of 93 checks passed
@kubestellar-prow
kubestellar-prow Bot deleted the scanner/fix-14598 branch October 28, 2026 22:25
@hivecommons-hive

Copy link
Copy Markdown
Contributor Author
Evidence bundle `#15128787d67e` sha256:e5442c4ffa540491af01ad409da1b3ddb0f3106a13d4180cdab5f9864f9d569b — download from the dashboard or `hivectl review evidence #15128`.

@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/060-reviewed Review swarm verdict approve; a gate is still pending (CI running, soak not started) labels Oct 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. 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. lgtm Indicates that a PR is ready to be merged. 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

1 participant