Repository navigation
fix(mcp): validate Origin and MCP-Protocol-Version; document the exact mount URL - #685
Merged
Merged
Conversation
…t mount URL - Refuse a present Origin that is not exactly the site's canonical origin with 403 before parsing (DNS-rebinding check the Streamable HTTP transport requires); an absent Origin is still admitted. Mirrors the forms/store idiom. - On every message after initialize, treat a missing MCP-Protocol-Version as 2025-03-26 and answer 400 for an unsupported value. - Document that the client endpoint is the declared mount exactly: /mcp/* is required route syntax, and /mcp/ or any subpath answers 404. Add a test. Fixes #676 Fixes #672 Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Sep 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #676
Fixes #672
What changed
#676,
packages/mcp/src/mcp.tshandle()Originheader is present and is not exactly the site's canonical origin (context.origin, i.e.--origin), the request gets403 Forbiddenbefore its content type, size or body is read. A request with noOriginis still admitted, because non-browser MCP clients don't send one. This uses the same exact-match rule aspackages/formsandpackages/store.initializeis checked, requests and notifications alike. A missing header is treated as2025-03-26, as the transport spec says. A value outsideSUPPORTED_PROTOCOL_VERSIONSgets400.initializestill negotiates fromparams.protocolVersionand ignores the header. No protocol versions were added.#672, docs only (runtime behavior unchanged). The client endpoint is the declared
mount, exactly:POST https://site.example/mcp./mcp/*is route syntax that core requires. A request to/mcp/or to any subpath gets404. This is now stated in the README "Declare a server" section,llms.txt, the scaffold note insrc/extension.ts, anddocs/EXTENSIONS.md.Docs updated in this PR: README ("Declare a server"; "What this implements", where this also removes a duplicated "protocol version negotiation" bullet), SECURITY.md, llms.txt, CHANGELOG (Unreleased), the MCP paragraph in docs/EXTENSIONS.md, and the regenerated
llms-full.txt.Evidence
packages/mcp/test/mcp.test.ts:nullalso get 403. A matching Origin and no Origin both get 200.initializeignores the header./mcp/gets 404.call()used to dropcontent-typewhenever a caller passedinit.headers, because of the spread order. No existing test passed headers, so nothing depended on that. It's fixed here.npm run typecheck: passes.npm run verify: exit 0 on macOS.Limitations and follow-up
allowedOriginssetting (or a general core route option) is still undecided, so it's left as a follow-up to [Request]: Origin allowlist and MCP-Protocol-Version check for @jimhoyd/urlcode-mcp mounts #676 and not added here.auth.🤖 Generated with Claude Code