Skip to content

auth: validate unadvertised RFC 9207 iss instead of rejecting it - #1187

Open
asjdf wants to merge 2 commits into
modelcontextprotocol:mainfrom
asjdf:fix/1152-validate-unadvertised-iss
Open

auth: validate unadvertised RFC 9207 iss instead of rejecting it#1187
asjdf wants to merge 2 commits into
modelcontextprotocol:mainfrom
asjdf:fix/1152-validate-unadvertised-iss

Conversation

@asjdf

@asjdf asjdf commented Aug 20, 2026

Copy link
Copy Markdown

Summary

Fixes #1152.

Sentry, Linear, and Notion omit authorization_response_iss_parameter_supported from their authorization-server metadata. Sentry still sends a correct iss in the authorization response, so sign-in fails after the browser step: the user has already consented and an authorization code has been issued, but validateIssuerResponse rejects the exchange solely because the server did not advertise RFC 9207 support.

RFC 9207 §2.4 says clients MUST extract and compare iss when the parameter is present. §2.4 also notes that clients SHOULD discard an unadvertised iss, but that is a recommendation and local policy may accept servers that send iss without advertising. Validating a matching iss is interoperable with those hosted MCP servers and still catches mix-up attacks: a wrong iss is rejected whether or not support was advertised.

When iss is present, this change always compares it to the expected issuer (simple string equality). A match is accepted even if the server did not advertise support. A mismatch still returns authorization response issuer %q does not match expected issuer %q. Absence of iss remains an error only when the server advertised support.

Test plan

  • go test ./auth/ -run TestValidateIssuerResponse -count=1
  • go test ./auth/...

New TestValidateIssuerResponse cases:

  • UnadvertisedIssCorrect: iss == expectedIssuer, issSupported == false → no error
  • UnadvertisedIssWrong: iss == "https://attacker.example.com", issSupported == false → error containing does not match expected issuer

Existing advertised+match / advertised+mismatch / missing-iss cases are unchanged.

When an authorization response includes iss, always compare it to the
expected issuer (RFC 9207 §2.4) rather than failing solely because the
server omitted authorization_response_iss_parameter_supported.
@asjdf
asjdf marked this pull request as ready for review August 20, 2026 08:48
@asjdf asjdf changed the title WIP: auth: validate unadvertised RFC 9207 iss instead of rejecting it auth: validate unadvertised RFC 9207 iss instead of rejecting it Aug 20, 2026
Comment thread auth/authorization_code.go Outdated
Comment on lines +619 to +623
// per [RFC 9207]. When iss is present it is always compared to expectedIssuer
// (RFC 9207 §2.4), even if the server did not advertise
// authorization_response_iss_parameter_supported. An unadvertised matching iss
// is accepted; a mismatch is rejected. Absence of iss is an error only when
// the server advertised support.

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.

According to spec

However, there might be legitimate authorization servers that provide the iss parameter without indicating their support in their metadata. Local policy or configuration can determine whether to accept such responses, and specific guidance is out of scope for this specification.

What do you think about adding a configurable value in AuthorizationCodeHandlerConfig to let the client define the local policy if accepting or not

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Good call — added AcceptUnadvertisedIss on AuthorizationCodeHandlerConfig as the local policy knob.

  • Zero value (false) keeps the released v1.7.0 behavior: if metadata does not advertise authorization_response_iss_parameter_supported and iss is present, we reject.
  • Set AcceptUnadvertisedIss: true to accept a matching unadvertised iss (Sentry/Linear/Notion-style servers).
  • A wrong iss is still rejected either way; we never accept a mismatch.

Pushed on this branch in 7fdf782.

Keep the released default of rejecting an unadvertised matching iss,
and let callers opt in for servers that send iss without advertising it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OAuth: a correct but unadvertised RFC 9207 iss fails the whole sign-in (§2.4 asks for validation, not rejection)

2 participants