Skip to content

fix(gateway): truly no-auth when inbound auth is disabled (no OAuth advertising) - #187

Merged
its-mash merged 1 commit into
mainfrom
fix/no-auth-discovery
Jun 25, 2026
Merged

fix(gateway): truly no-auth when inbound auth is disabled (no OAuth advertising)#187
its-mash merged 1 commit into
mainfrom
fix/no-auth-discovery

Conversation

@its-mash

Copy link
Copy Markdown
Member

Problem

With gateway.auth_disabled on, the handshake already returns 200 for a tokenless client (the middleware accepts anonymously, no 401). But the gateway still served OAuth discovery — so MCP clients that probe .well-known/oauth-protected-resource / .well-known/oauth-authorization-server (per the MCP authorization spec) started an OAuth flow against a gateway that doesn't ask for a token.

Fix

Gate the discovery handlers on the toggle: when auth is disabled, oauth_metadata and resource_metadata return 404. Per the spec's discovery sequence (no WWW-Authenticate resource_metadata + 404 well-known → "abort or use pre-configured values"), the client then connects without OAuth. Combined with the existing tokenless-200 handshake, this is the spec's "no auth" path end to end:

auth required (default) auth disabled
tokenless /mcp handshake 401 200 (anonymous)
.well-known/oauth-* 200 (metadata) 404

Tests

Extended the authless integration harness (which drives the real middleware) to mount the discovery routes and assert they 404 when disabled / 200 when required, alongside the existing tokenless-200 vs 401 handshake assertions.

https://claude.ai/code/session_01Baan9JmzR43uxxRUh7CAMF

With `gateway.auth_disabled` on, the handshake already returns 200 for a
tokenless client (no 401), but the OAuth-discovery endpoints still served
metadata — so MCP clients that probe `.well-known/oauth-protected-resource`
(per the MCP authorization spec) started an OAuth flow against a gateway that
accepts them without a token.

Gate the discovery handlers: when auth is disabled, `oauth_metadata` and
`resource_metadata` return 404. Combined with the tokenless-200 handshake,
this is the spec's "no auth" path — no 401 challenge and no resource
metadata, so the client connects without OAuth.

Tests: extend the authless integration harness to assert the discovery
endpoints 404 when auth is disabled and 200 when it's required (alongside the
existing tokenless-handshake 200 / 401 assertions).

Claude-Session: https://claude.ai/code/session_01Baan9JmzR43uxxRUh7CAMF
Signed-off-by: Mohammod Al Amin Ashik <maa.ashik00@gmail.com>
@its-mash
its-mash merged commit 3e617fd into main Jun 25, 2026
13 checks passed
@its-mash
its-mash deleted the fix/no-auth-discovery branch June 25, 2026 04:32
its-mash added a commit that referenced this pull request Jun 25, 2026
The earlier no-auth tests stubbed the `/mcp` handler and only checked two
discovery endpoints — so they couldn't catch the real failure an editor hit:
with auth disabled but discovery still advertising OAuth (the pre-#187 state),
VS Code probed `/.well-known/oauth-protected-resource/mcp`, got 200, entered an
OAuth flow, and stalled at `initialize`.

- auth_disable: assert the RFC 9728 `/.well-known/oauth-protected-resource/mcp`
  sub-path (the one editors probe first) 404s when auth is disabled and is
  served when required, alongside the other two endpoints.
- gateway_notifications: add `authless_anonymous_client_completes_real_initialize`
  — boots the real gateway with the REAL `mcp_oauth_middleware` + auth disabled
  and drives it with a real rmcp client that sends no token, proving the
  anonymous handshake completes end to end (initialize + list_tools) rather than
  hanging.

Claude-Session: https://claude.ai/code/session_01Baan9JmzR43uxxRUh7CAMF
Signed-off-by: Mohammod Al Amin Ashik <maa.ashik00@gmail.com>
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.

1 participant