fix(mcp): validate HTTP origins and hosts - #3093
Conversation
64ea691 to
f972526
Compare
|
Preview deployment for your docs. Learn more about Mintlify Previews.
💡 Tip: Enable Workflows to automatically generate PRs for you. |
|
Docs7 for context7.com
Commit |
f972526 to
ff75023
Compare
enesgules
left a comment
There was a problem hiding this comment.
The loopback logic is correct and well tested: IPv6 brackets, 127.1 canonicalization, userinfo/path rejection, null origin rejection, rejection before express.json, Vary headers, getOptionValueSource. Two blocking items on scope and compatibility, plus a few minor ones inline.
Blocking
-
Hosted mode breaks browser MCP clients. The public server at
mcp.context7.comhas no cookies and no ambient credentials; auth is header-only. For that serverAccess-Control-Allow-Origin: *is not a vulnerability. The comment this PR removes fromindex.tsshows the team deliberately added those headers so browser clients pass preflight. After this change MCP Inspector, web IDEs, and the Cloudflare playground get 403 from the hosted server. The Cobalt finding is the local server + DNS rebinding, and that stays fixed if the strict Origin allowlist applies only whenisLocalis true. See inline comment. -
localhostclients can getECONNREFUSED. The default bind is now127.0.0.1only. On macOS with Node 24,localhostresolves to::1first (verified locally: a Node client withautoSelectFamily: falseagainst a127.0.0.1-only listener fails;autoSelectFamily: truesucceeds). Every doc and MCP config example sayshttp://localhost:3000/mcp. Either bind both127.0.0.1and::1for a loopback host, or change the docs/README examples tohttp://127.0.0.1:PORT/mcp. See inline comment.
enesgules
left a comment
There was a problem hiding this comment.
All four threads are addressed in 34a007c and verified locally: hosted mode keeps wildcard CORS, strict Origin/Host checks are loopback-only, bind-host normalization runs only in the HTTP branch, docs use 127.0.0.1, and Dockerfile/Smithery keep 0.0.0.0. Typecheck, lint, build, and 94 tests pass.
Summary
Fixes the MCP HTTP Origin validation / permissive CORS finding reported as Cobalt PT38659_23.
null, malformed, and explicitly empty Origin values before JSON parsing or MCP dispatch on loopback serversVaryheaders127.0.0.1by default and documents the exact client URL instead of relying on platform-dependentlocalhostresolution0.0.0.0bindCONTEXT7_MCP_HOSTcannot break stdio startupLinear: CTX7-2533
Validation
git diff --checkpassed