Skip to content

DCR discovery rejects an origin-only issuer published with a trailing slash (https://host/) #7289

Done

Description

@reyortiz3

Bug description

When a DCR upstream is configured with dcrConfig.discoveryUrl
(https://host.example.com/.well-known/oauth-authorization-server), ToolHive derives the expected
issuer as https://host.example.com and compares it byte for byte with the issuer in the fetched
metadata. An authorization server that publishes "issuer": "https://host.example.com/" is rejected:

issuer mismatch (RFC 8414 §3.3): expected "https://host.example.com", got "https://host.example.com/"

Registration then fails and the upstream is unusable. Servers built on FastMCP's OAuth proxy publish
exactly this form for any root-URL deployment (see "Additional context").

Steps to reproduce

  1. Run an MCP server that is its own OAuth authorization server through FastMCP's proxy at a root
    URL. For example mcp-atlassian 0.24.8 with ATLASSIAN_OAUTH_PROXY_ENABLE=true,
    PUBLIC_BASE_URL=https://host.example.com, plus the required dummy JIRA_URL,
    ATLASSIAN_OAUTH_CLIENT_ID, ATLASSIAN_OAUTH_CLIENT_SECRET and
    ATLASSIAN_OAUTH_REDIRECT_URI values. The discovery routes make no upstream calls.
  2. curl -s https://host.example.com/.well-known/oauth-authorization-server returns
    "issuer":"https://host.example.com/".
  3. Configure an OAuth2 upstream with DCR and
    discoveryUrl: https://host.example.com/.well-known/oauth-authorization-server.
  4. Resolve the registration. It fails with the error above.

PUBLIC_BASE_URL makes no difference at a root URL:

PUBLIC_BASE_URL published issuer
https://host.example.com https://host.example.com/
https://host.example.com/ https://host.example.com/
https://host.example.com/mcp-atlassian https://host.example.com/mcp-atlassian

Expected behavior

The two forms identify the same issuer. Per RFC 3986 §6.2.3, an http(s) URI with an empty path
normalizes to a path of /. Registration should succeed.

Actual behavior

fetchDiscoveryDocument requires exact string equality, so registration fails. The expected issuer
is derived from the discovery URL and cannot be overridden. registrationEndpoint avoids discovery
but needs explicit endpoints and leaves the token endpoint auth method to default selection.

Environment

  • ToolHive: v0.68.0. The same comparison is on main at a4dc984 (pkg/oauthproto/discovery.go:318).
  • Server: mcp-atlassian 0.24.8, FastMCP 3.4.11, MCP Python SDK 1.30.0. FastMCP 4.2.5 behaves the same.

Additional context

Where the trailing slash comes from on the server side:

  • mcp-atlassian passes PUBLIC_BASE_URL through unmodified and sets no issuer_url:
    servers/main.py L1167, L1200
  • FastMCP builds AnyHttpUrl(base_url) (L366) and defaults the issuer to it (L1098):
    auth.py
  • The MCP SDK publishes that object as issuer (L171) while stripping the slash with rstrip("/")
    for the endpoints it builds (L158, L159, L191):
    routes.py

ToolHive side:
deriveExpectedIssuerFromDiscoveryURL
(L1330) already normalizes a stray / on the discovery URL so the expected issuer stays slash-free.
The document's own issuer gets no equivalent treatment.

Related: #5390 (path-insertion discovery) and #1957 (issuer mismatch).

Proposed change

Compare issuers with a helper that treats an empty path and / as equal, and nothing else:

// Sketch, not compiled.
// issuersEqual reports whether expected and got are the same issuer under RFC 8414 §3.3,
// treating an empty path and "/" as equivalent (RFC 3986 §6.2.3).
func issuersEqual(expected, got string) bool {
	if expected == got {
		return true
	}
	e, errE := url.Parse(expected)
	g, errG := url.Parse(got)
	if errE != nil || errG != nil {
		return false
	}
	rootOnly := func(u *url.URL) bool { return u.Path == "" || u.Path == "/" }
	return rootOnly(e) && rootOnly(g) &&
		e.Scheme == g.Scheme && e.Host == g.Host &&
		e.RawQuery == "" && g.RawQuery == "" && e.Fragment == "" && g.Fragment == ""
}

The check stays as strict as before where it protects against mix-up attacks. Scheme, host and port
must still match exactly, and a path issuer keeps byte-exact equality, including a trailing slash.

Tests: exact match, slash on either side, a different host, a different scheme, a different port,
a path issuer with and without a trailing slash (both must still mismatch), and query or fragment
present.

An alternative is a dcrConfig field to pin the expected issuer. It has a larger surface and leaves
the default experience broken for FastMCP-based servers.

Activity

  1. added
    bug
    on Nov 24, 2026
  2. added
    needs-triage
    on Nov 24, 2026
  3. media-ctrl commented on Nov 25, 2026

    @media-ctrl

    The normalisation you want already exists one function away. deriveExpectedIssuerFromDiscoveryURL collapses a stray "/" to an empty path in the insert branch, and its own comment says the reason is that "https://host/" would otherwise fail the section 3.3 byte-equality check. The metadata side never gets that treatment: fetchDiscoveryDocument compares metadata.Issuer to expectedIssuer with !=, and the append branch derives the bare origin.

    So the mismatch is asymmetric by construction. Your expected value is normalised to https://host, the server publishes the form your own comment calls spurious, and the comparison is byte equality.

    Fix: compare normalised forms on both sides, mapping an empty path to "/" and lowercasing scheme and host, never touching a non-empty path. RFC 3986 section 6.2.3 is explicit that an empty path should be normalised to "/", so this is not relaxing 3.3, it is applying it to two spellings of one identifier.

    Do not strip a trailing slash from a non-empty path: /a and /a/ are not equivalent under 6.2.3, and treating them as equal would create the mix-up this check prevents.

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

    bugneeds-triage

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions