Skip to content

[scanner] hub-auth: send GitHub token exchange as form POST with redirect_uri (no secrets in URL) #14631

Closed

Description

@hivecommons-hive

Part of #14598

Target branch: v6

Scope

exchangeGitHubLogin (src/pkg/hub/oauth.go:932-940) builds the token request with client_id, client_secret and code in the URL query of a POST to defaultGHTokenURL (src/pkg/hub/oauth.go:47, used at :936), so URL-based proxy/request logs can retain them. Move them into a form-encoded POST body (Content-Type: application/x-www-form-urlencoded) to the fixed token endpoint, and add the exact redirect_uri (oauthRedirectURI(), src/pkg/hub/saas_auth.go:371, the same value sent in the authorize redirect at oauth.go:603-604). Keep Accept: application/json, the response size cap, and the rest of the flow unchanged. No new scopes (authorize URL keeps scope=). OIDC path (p.AuthCodeURL, oauth.go:626) is untouched.

Decision taken by hive: use form-body client credentials (not HTTP Basic); it is GitHub's documented shape and the smallest diff.

Acceptance criteria

  • Token request has an empty URL query; client_id, client_secret, code, redirect_uri are in the form body only.
  • Tests pin method, URL (fixed endpoint, no query), headers, body fields, and failure handling (non-200/ invalid JSON/ empty access_token).
  • Secret/code/token never appear in logged errors (check the s.logger.Warn("OAuth token exchange failed", "error", err) path at ~oauth.go:947 does not echo the URL with query).
  • Existing callback/state tests (src/pkg/hub/oauth_*_test.go) still pass; GitHub App installation auth and device flow unaffected.

Likely files

  • src/pkg/hub/oauth.go
  • src/pkg/hub/oauth_provider_login_test.go (and sibling oauth_*_test.go)

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

Activity

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

    @hivecommons-hive
    ContributorAuthor

    Folded finding. This was filed as a separate issue, but 3 open agent-filed issues already cite src/pkg/hub/oauth.go, so it was folded into the oldest of them instead of opening another. Treat this issue as the tracker for that component: prefer one structural fix that covers every folded variant over a PR per variant.

    [scanner] hub-auth: pin Hub login contract with fail-closed and no-secret-in-URL/log tests

    Part of #14598

    Target branch: v6

    Scope

    Regression-test lane after the exchange and PKCE changes: add table-driven tests in src/pkg/hub that pin the whole browser login contract using an httptest fake of the GitHub token and user endpoints: authorize redirect shape (empty scope, redirect_uri, state, code_challenge/S256), token request (method POST, no URL query, form body fields, no secrets in the URL), and fail-closed matrix (no state cookie, state mismatch, missing/mismatched/expired verifier, replayed callback after cookie cleared) asserting zero token-endpoint calls and no session cookie set. Also assert log output (capture s.logger) never contains the client secret, code, or access token. Keep existing identity validation (isValidName, oauth.go ~:990) and encrypted-token persistence (oauth.go:847) covered. The token endpoint is the package constant defaultGHTokenURL (oauth.go:47); if the tests need an override seam, add the smallest test-only injection.

    Decision taken by hive: tests only plus a minimal seam; no production behavior change.

    Acceptance criteria

    • Tests cover every case above and fail if secrets reappear in the URL or logs.
    • GitHub App installation auth, device flow and hosted SSO tests unchanged.

    Likely files

    • src/pkg/hub/oauth_pkce_test.go (new), src/pkg/hub/oauth_provider_login_test.go
    • src/pkg/hub/oauth.go (test seam only, if needed)

    Depends on both the form-POST exchange child and the PKCE child.

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

  3. github-actions commented on Oct 27, 2026

    @github-actions
    Contributor

    Closed by #14683 (merged to v6).

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

    agent/scannerCreated or modified by the scanner agenthelp wantedDenotes an issue that needs help from a contributor. Must meet "help wanted" guidelines.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions