mcpproxy-go icon indicating copy to clipboard operation
mcpproxy-go copied to clipboard

[Feature]: Harden the OAuth client role (iss validation, issuer-bound credentials, application_type)

Open felipecrs opened this issue 1 week ago • 2 comments

Problem / motivation

mcpproxy is trusted with real OAuth credentials against third-party authorization servers, but its client role accepts responses more loosely than its authorization-server role sends them. Three gaps:

  1. No iss validation. RFC 9207 §2.4 lets the client verify that a redirect carrying an authorization code really came from the expected issuer, closing the authorization-code injection class of attacks. Curiously, the AS role already emits iss, but the client role never checks it. v1.0.0 of the SDK, which go.mod pins, predates the fix.
  2. Credentials can be replayed across issuers. The persistent DCR credentials are recorded against the server key (config.go#L1185-L1223); a later metadata swap on the same upstream entry could exchange them against a different AS while the fields remain valid.
  3. DCR omits application_type: "web". The SDK's registration payload only sends client_name, redirect_uris, and the auth-method / grant / response-type defaults (oauth.go, mcp-go v1.0.0); per RFC 7591 servers may default to native, which changes the redirect rules applied to mcpproxy's loopback flow.

The good news: upstream mcp-go already merged fixes for all three. v1.2.0 added issuer checks on AS metadata, v1.3.0 bound credentials to the issuer, and v1.4.0 added RFC 9207 iss response validation and application_type in DCR (mcp-go v1.4.0 oauth.go).

Proposed solution

Upgrade the mcp-go pin to at least v1.4.0, then verify each path actually engages:

  • the loopback redirect handler receives the iss query param and the validation fires on real AS responses, not solely in unit tests
  • persisted credentials are keyed by issuer, not just server key, so a metadata swap cannot trigger a cross-AS exchange; migrate existing records on read
  • the DCR payload sent from internal/oauth arrives at the real registration endpoints complete

Alternatives considered

Patching the gaps in internal/oauth on top of v1.0.0. Rejected: the fixes already exist upstream, duplicating them would mean more code to delete on the next bump.

Related to #1971, which covers the authorization-server role; this one covers the client direction.

Which edition?

Both / not sure

Pre-submission checklist

  • [x] I searched existing issues and discussions for a similar request

felipecrs avatar Nov 25 '26 16:11 felipecrs

Thanks @felipecrs, this was a good catch. I checked all three gaps against main (661ad51d7). The spec is in https://github.com/smart-mcp-proxy/mcpproxy-go/pull/2050 (Spec 135; docs only, implementation follows in later PRs).

Confirmed:

  1. No RFC 9207 iss check. The callback server copies the query into a map[string]string and never reads iss (internal/oauth/config.go:2013-2019). Every login path exchanges the code through ProcessAuthorizationResponse(code, state, verifier) (internal/upstream/core/connection_oauth.go:1678-1688). In mcp-go v1.4.0, ProcessAuthorizationResponse still doesn't check iss; only the new ProcessAuthorizationCallback does. So the bump alone won't engage it. The spec moves the decision into mcpproxy's callback handler and keeps mcp-go's check as a second line.
  2. Credentials not bound to the issuer. Rows are keyed by name|url and carry no issuer (internal/storage/models.go:628-657). The stored-credential refresh is mcpproxy's own request (internal/upstream/core/oauth_refresh.go:124-139, client.go:989-1010), so mcp-go's v1.3 binding doesn't cover it. That request also follows redirects. RFC 8414 issuer equality never runs either, because mcpproxy hands mcp-go an explicit metadata URL from its own preflight (internal/oauth/config.go:1385-1545). Existing rows are bound on first use, so nobody is forced to sign in again.
  3. DCR omits application_type. Confirmed (mcp-go v1.0.0 RegisterClient). One correction, though: OIDC DCR defaults to web when the field is omitted, and a loopback http redirect is the native case. The spec sends native for loopback and web only for the non-loopback remote callback.

Not as described: the authorization-server role doesn't currently emit iss. mcplogin.BuildRedirect only orders the key if a caller passes one, and no caller does (internal/mcplogin/redirect.go:131-146). I've listed that as a Spec 132 follow-up.

Found while checking: a client_secret given through oauth.extra_params is copied into the browser-facing authorization URL (internal/upstream/core/oauth_stale_dcr_client.go:38-61). The spec covers that too.

Dumbris avatar Nov 25 '26 19:11 Dumbris

Spec 135 PR-2a merged in #2090: mcpproxy now checks the RFC 9207 iss parameter on every OAuth authorization response before the code is exchanged.

Landed

  • An expected issuer is recorded per login flow (discovered, configured or synthetic, plus authorization_response_iss_parameter_supported) and registered atomically with the callback waiter for that state.
  • The decision runs in the callback handler before the page is chosen and before a provider error is reported, and runs again at the exchange.
    • A wrong or empty iss, or a missing one when support is advertised, is refused as MCPX_OAUTH_ISSUER_MISMATCH. Nothing is sent to the token endpoint.
    • For a synthetic issuer (endpoint overrides) any iss is accepted, with a log line when it differs.
    • In strict mode the exchange uses mcp-go's ProcessAuthorizationCallback.
  • Per-server opt-out oauth.skip_issuer_validation (*bool, default off). It is request policy, not identity: it never clears a grant, moves the epoch or changes the server id.
  • New diagnostics code with a catalog entry, classifier case and error doc; feature-page section and configuration row.

Remaining

  • PR-2:
    • D0 metadata resolver, Snapshot and GuardedTransport (T015–T017).
    • D3 discovery issuer equality, the same-origin metadata redirect policy and the policy-keyed cache (T023–T024). Until this lands, Protected is provisional and is neither logged nor stored.
    • D4 issuer-bound rows, mix_up_protected persistence, TOFU and static-client provenance (T025–T030).
    • The ISSUER_CHANGED and METADATA_ISSUER_MISMATCH codes.
  • PR-3:
    • The PATCH route plus the Web UI and macOS editor fields for the opt-out.
    • The broker iss check (T033).
    • Mapping the mismatch to the login action in health, Doctor, the Web UI and the tray.
    • Surfaces (T034–T036), e2e (T037) and the real-provider check (T038).
  • Known residual: a server with an empty "oauth": {} block gets a new history id when skip_issuer_validation is added, as any oauth edit does today. The no-block case keeps its id.

Dumbris avatar Nov 28 '26 23:11 Dumbris