Skip to content

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

Closed
4 of 4 issues completed

Description

@hanthor

Problem

The Hub's browser GitHub sign-in is an OAuth authorization-code flow in src/pkg/hub/oauth.go (startProviderLogin / exchangeGitHubLogin). It already has meaningful CSRF protection: a random state nonce is bound to an HttpOnly, Secure, SameSite=Lax cookie, checked before exchanging the code, and cleared as single-use. This RFC proposes targeted hardening, not replacing that state protection.

The current token exchange has concrete gaps:

  • It does not use PKCE, although GitHub's web application flow supports S256 code_challenge / code_verifier and recommends it.
  • It sends client_id, client_secret, and code in the URL query of a POST request. URL-based proxy/request logs can retain those values.
  • It does not send the exact redirect_uri during the token exchange, although GitHub strongly recommends binding the exchange to the original redirect URI.

Hive has multiple distinct auth paths: the Hub uses this browser authorization-code flow; direct-route spokes use GitHub's Device Authorization Grant in src/pkg/dashboard/api_auth.go; hosted spokes use the Hub's signed SSO handoff. The GitHub App installation credential is separate from the human login token and remains the source for repo writes/advisory posting.

The Hub currently encrypts and persists the GitHub user token for existing Hub features. Audit its consumers before changing retention or refresh behavior. Keep the identity-only/no-additional-scope intent. GitHub documents that a scope-less request can still receive scopes the user previously authorized for that OAuth app, so verify and document that behavior rather than claiming an empty scope revokes prior grants.

Proposal

  1. Add S256 PKCE per login transaction. Bind the verifier to the existing state/browser transaction (server-side one-use transaction or a separate short-lived HttpOnly cookie); expire and consume it once. Reject missing, mismatched, expired, or replayed verifier/state before token exchange or session creation.
  2. Exchange the code using the fixed token endpoint with form-encoded POST fields or HTTP Basic client authentication. Do not put client_secret, code, or tokens in the request URL or logs. Include the exact configured redirect_uri and code_verifier.
  3. Preserve the existing state-cookie CSRF defenses, callback identity revalidation, and no-extra-scopes contract. Keep human identity credentials separate from the GitHub App installation token.
  4. Keep direct-spoke device flow and hosted-spoke SSO behavior unchanged in this RFC. Decide separately whether a browser redirect should later be offered to direct-route spokes and how they would obtain a confidential client secret.
  5. Document which Hub features need the encrypted user token and define the expected lifetime/refresh behavior before changing token storage.

Acceptance criteria

  • Hub browser login uses state plus PKCE S256 and completes without asking the user to copy a device code.
  • State/verifier mismatch, missing values, expiry, and callback replay fail closed before code exchange/session minting.
  • The token exchange uses the exact redirect URI and verifier; client secret/code/token are absent from the URL and logs. Tests pin request method, URL, body/auth, and rejection behavior.
  • No new GitHub API scopes are requested, and GitHub App installation auth/advisory posting is unaffected.
  • Existing GitHub identity validation, encrypted-token consumers, Hub SSO, and direct-spoke device-flow behavior remain covered.

Related work

References

Activity

  1. hivecommons-hive commented on Oct 27, 2026

    @hivecommons-hive
    Contributor

    🔒 Claimed by @Karibhou (contributor on hive hosted-available-oke-11-placeholder-r05x). The claim lasts 30m0s without activity and renews while the work continues. Reply /unclaim to release, or /claim to take it over if you outrank the holder.

  2. added
    help wantedDenotes an issue that needs help from a contributor. Must meet "help wanted" guidelines.
    on Oct 27, 2026
  3. hivecommons-hive commented on Oct 27, 2026

    @hivecommons-hive
    Contributor

    🔓 Claim by @Karibhou released (released on disconnect).

  4. 26 remaining items

  5. added
    stage/020-claimedClaimed by the scanner or a relay contributor
    and removed
    stage/010-actionableTriaged; eligible for the hive to pick up
    on Oct 28, 2026
  6. hivecommons-hive commented on Oct 28, 2026

    @hivecommons-hive
    Contributor

    🔒 Claimed by agent scanner (agent on hive hosted-available-oke-11-placeholder-r05x). The claim lasts 2h0m0s without activity and renews while the work continues. Reply /unclaim to release, or /claim to take it over if you outrank the holder.

  7. hivecommons-hive commented on Oct 29, 2026

    @hivecommons-hive
    Contributor

    Fixed by #15128 (merged efe577b). Closing. Reply /reopen if the problem persists.

  8. github-actions commented on Oct 29, 2026

    @github-actions
    Contributor

    @hanthor this issue was closed by @hivecommons-hive[bot] as completed.

    If this was closed by a merged PR, the fix only takes effect once it ships in a tagged release and your deployment updates to it — check your running version against the fix before concluding the fix failed.

    If you are still seeing the problem, comment /reopen and it will be reopened for you — you do not need write access. Please add what you are still observing (running version, logs, steps) so it is not closed the same way again.

  9. hivecommons-hive commented on Oct 29, 2026

    @hivecommons-hive
    Contributor

    🔓 Claim by agent scanner released (holding agent relaunched).

  10. hanthor commented on Oct 29, 2026

    @hanthor
    ContributorAuthor

    Verified the final acceptance gap is now resolved by #15179 (merge c3c33e3), not by #15128 alone. The merged implementation locally binds the verifier to the state/login transaction before token exchange; the regression matrix includes actual substituted valid verifiers and bound-challenge tampering, all requiring zero endpoint calls and no session/user record. Full relevant CI at the implementation head and merge passed. The earlier bot closure crediting only #15128 was premature, but the current closed state is now justified. #14636 is also complete; no reopening or security requirement waiver is needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedDenotes an issue that needs help from a contributor. Must meet "help wanted" guidelines.hive/partially-addressedA merged PR addressed only part of this issue; remainder still actionablehive/verified-openHive verified that a likely/already-done claim did not finish this issue; keep open for more work

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions