OAuth discovery drops explicit default ports from advertised issuer identifiers

Ouverte
#1,420 2 commentaires 0 réactions 1 personne assignée Voir sur GitHub

Les mainteneurs répondent en général sous 2 jours

@gocamille y travaille déjà.

Depuis le 31/10/2026.

Évaluation

Cette issue n'a pas encore été évaluée.

Description

bug P1 ready for work T-security T-transport

Summary

OAuth discovery rejects internally consistent metadata when the advertised authorization-server issuer contains an explicit default port, such as https://auth.example.com:443/tenant1.

The original identifier is parsed into a Url, which removes :443. The serialized URL is then used as the expected issuer, while AuthorizationMetadata.issuer retains the original JSON string.

Reproduced against main at c742b5536724ec376b14b7ddcbbd024b7d6ae163 (rmcp 3.8.0). The same code is present at 98a54789b80110ad210495c4ad845c89e1980471, the rmcp revision pinned by Codex 0.166.0.

Reproduction with simulated metadata

Using the existing RecordingOAuthHttpClient test helper, return these responses during AuthorizationManager::resolve_metadata():

  1. An initial 401 for the MCP resource https://mcp.example.com/.
  2. Protected resource metadata:
{
  "resource": "https://mcp.example.com/",
  "authorization_servers": ["https://auth.example.com:443/tenant1"]
}
  1. Authorization-server metadata:
{
  "issuer": "https://auth.example.com:443/tenant1",
  "authorization_endpoint": "https://auth.example.com/tenant1/authorize",
  "token_endpoint": "https://auth.example.com/tenant1/token"
}

No real OAuth credentials or external service are needed.

Expected: discovery accepts the metadata because its issuer exactly matches the identifier advertised by protected resource metadata.

Actual:

Authorization server issuer mismatch: expected https://auth.example.com/tenant1, received https://auth.example.com:443/tenant1

Root cause

In crates/rmcp/src/transport/auth.rs, authorization_metadata_from_resource_metadata() parses the candidate with Url::parse(candidate), then calls:

.try_discover_oauth_server(&candidate_url, Some(candidate_url.as_str()))

candidate_url.as_str() has already lost the explicit default port. Parsing is appropriate for transport, but its normalized output no longer represents the original OAuth identifier.

This also creates an asymmetric check: an advertised issuer containing :443 can incorrectly match metadata that omits it, because the expected value has been normalized first.

Relation to #1144 / #1145

#1145 preserves the issuer through discovery to address the trailing-slash problem in #1144, but retains the parsed URL representation. That preserves a tenant's trailing slash while still losing an explicit default port and host casing.

I did not find an existing issue specifically covering this default-port case. #1268 concerns HTTP Origin validation and is a separate problem.

Proposed approach

Preserve the advertised absolute issuer string for identity validation, separately from the parsed URL used to construct discovery requests. Keep the existing resolved-URL behavior for legacy relative references.

The fix should not normalize both issuers or treat identifiers with and without :443 as interchangeable. RFC 8414 sections 3.3 and 4 require validation against the original issuer identifier.

Local validation and question

A local candidate fix has mocked regression coverage for matching and mismatched default ports, nonstandard ports, host casing, tenant paths and trailing slashes, including the complete metadata discovery path. A before/after comparison of OAuth and HTTP tests found no new failures; full upstream CI has not been run.

Would preserving the original advertised identifier be an appropriate follow-up to #1145 before submitting a PR?

AI assistance was used for the investigation and local regression tests. All examples above use fictional domains and tenants.

Langage dominant
Rust
Étoiles
4.1k
Forks
694
Merge moyen
3 j 14 h
PR mergées (30 j)
39

Préparer son environnement

Ouvrir dans Codespaces

Lance le conteneur de développement du projet dans votre navigateur, avec votre propre compte GitHub.

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de modelcontextprotocol/rust-sdk

Toutes les issues de modelcontextprotocol/rust-sdk

Issues similaires

Plus d'issues Rust

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.