Skip to content

fix(oauth): drop the query string from the legacy metadata discovery URL - #1757

Merged
Dumbris merged 2 commits into
smart-mcp-proxy:mainfrom
rudycelekli:fix/oauth-legacy-metadata-query-20261023-01
Oct 29, 2026
Merged

Dumbris merged 2 commits into
smart-mcp-proxy:mainfrom
rudycelekli:fix/oauth-legacy-metadata-query-20261023-01

Conversation

@rudycelekli

Copy link
Copy Markdown
Contributor

Bug

BuildRFC8414MetadataURLs builds three candidate metadata URLs. The RFC 8414 and base-only candidates are rebuilt from the parsed scheme, host and path, but the legacy "append to the path" candidate is built by string concatenation on the raw input. When the URL has a query string, /.well-known/oauth-authorization-server ends up appended to the query instead of the path.

The input is the configured server URL whenever no protected-resource metadata is found (config.go passes serverConfig.URL to findWorkingMetadataDoc). Server URLs with ?token= or similar are common enough that the logging helpers already special-case them.

Trigger

Server URL https://host.example.com/mcp?token=abc produces this legacy candidate:

https://host.example.com/mcp?token=abc/.well-known/oauth-authorization-server

That is a request to /mcp with a mangled query, so a server that only publishes metadata under the legacy layout is never discovered.

Fix

Build the legacy candidate from baseURL plus the escaped path, the same way as the other two candidates. The query and fragment are no longer included. Inputs without a query string produce the same URLs as before.

Test

New TestBuildRFC8414MetadataURLs case "URL with path and query string".

Commands run

  • CGO_ENABLED=0 go test -count=1 ./internal/oauth: ok
  • With the fix reverted (git stash of discovery.go), -run TestBuildRFC8414MetadataURLs fails with URL[1] = "https://host.example.com/mcp?token=abc/.well-known/oauth-authorization-server", want "https://host.example.com/mcp/.well-known/oauth-authorization-server".
  • gofmt -l on the edited files: no output

@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Review finding (P2): rebuilding the legacy candidate as scheme://host +
EscapedPath dropped the userinfo, which net/http turns into a Basic
Authorization header, so discovery behind a Basic-auth gateway broke.
Strip only the query and fragment from a copy of the parsed URL instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Dumbris

Dumbris commented Oct 26, 2026

Copy link
Copy Markdown
Member

Verified the bug on main and the fix; thank you! The review found one gap, so I pushed a small maintainer commit on top of your branch: the query strip was right, but rebuilding the legacy candidate as scheme://host + path also dropped the URL userinfo, which net/http turns into Basic auth, so discovery behind a Basic-auth gateway broke (even without a query string). The commit strips only query and fragment from a copy of the parsed URL and adds userinfo cases to TestBuildRFC8414MetadataURLs.

I will merge once CI is green.

@Dumbris Dumbris left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Verified: the bug reproduces on main and the PR fixes it. The review found one gap, closed by the maintainer commit on top (regression test included). Race tests and CI lint for the touched packages are clean on this branch merged with main, and the result was cross-reviewed clean.

@Dumbris
Dumbris merged commit 60c34da into smart-mcp-proxy:main Oct 29, 2026
46 checks passed
@Dumbris

Dumbris commented Oct 29, 2026

Copy link
Copy Markdown
Member

Merged. Thank you, @rudycelekli! Legacy OAuth metadata discovery now builds the well-known URL from the parsed server URL, so a ?token= query no longer swallows the suffix and points discovery at the wrong place.

Contributions like this are what keep MCPProxy moving, and they matter a lot to the project.

One small ask, only if you feel like it: a short public note about your change (a tweet, a LinkedIn post, a line in a community you are part of) helps more people discover MCPProxy. No pressure at all, and I would be glad to repost 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.

3 participants