Skip to content

security(oauth): token POST credentials can leak through redirects #729

Closed

Description

@PierrunoYT

Summary

OAuth token requests validate only the initial token endpoint. The supplied or default http.Client can follow HTTP 307/308 redirects while replaying the POST body to another origin or an HTTPS-to-HTTP destination.

The replayed form may contain authorization codes, PKCE verifiers, refresh tokens, client secrets, and client IDs.

Affected code

  • internal/oauth/flow.go:113-151 builds the sensitive token form.
  • internal/oauth/flow.go:154-180 validates only the initial URL and calls client.Do without a token-specific redirect policy.
  • internal/mcp/oauth.go:224-247 uses the same implementation for MCP OAuth login and refresh.
  • internal/oauth/flow_test.go:185-190 covers an initially insecure endpoint but not redirected endpoints.

Reproduction outline

  1. Configure or discover an HTTPS token endpoint.
  2. Have that endpoint return 307 Temporary Redirect or 308 Permanent Redirect to a different origin or an HTTP URL.
  3. Perform authorization-code exchange or token refresh.
  4. Observe that Go can replay the POST and form body at the redirect target.

Impact

Authorization credentials and long-lived refresh tokens can be disclosed cross-origin or over plaintext despite the initial endpoint passing HTTPS validation.

Suggested fix

Clone the selected HTTP client and install a token-specific CheckRedirect policy. The safest default is to reject all token-endpoint redirects.

Add 307/308 tests for both code exchange and refresh and assert that the redirect target receives no request body or credential-bearing request.

Activity

  1. shriza1991 commented on Jul 18, 2026

    @shriza1991

    Hi, I'd like to work on this, can you please assign this to me if its available?

  2. Vasanthdev2004 commented on Jul 18, 2026

    @Vasanthdev2004
    Collaborator

    assigned @shriza1991

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions