fix(server): reject userinfo in Origin and Host headers#2490
Open
morluto wants to merge 2 commits into
Open
Conversation
🦋 Changeset detectedLatest commit: 58451de The changes in this PR will be included in the next version bump. This PR includes changesets to release 6 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
@modelcontextprotocol/client
@modelcontextprotocol/codemod
@modelcontextprotocol/core
@modelcontextprotocol/server
@modelcontextprotocol/server-legacy
@modelcontextprotocol/express
@modelcontextprotocol/fastify
@modelcontextprotocol/hono
@modelcontextprotocol/node
commit: |
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 #2489.
Summary
Reject Origin and Host header values containing URL userinfo before matching their hostnames against an allowlist.
The validators previously compared only the hostname returned by
URL. Because URL parsing removes userinfo components, values such ashttp://user@localhost,http://@localhost, anduser@localhost:3000were normalized to the allowlisted hostnamelocalhost.What changed
@userinfo delimiter before matching the parsed hostname against an allowlist.invalid_origin_headerorinvalid_host_headerwhen the delimiter is present.The shared server helpers are consumed by the Node, Express, Fastify, and Hono middleware, so the adapters inherit the corrected parsing behavior without adapter-specific changes.
Behavior and scope
This prevents invalid Origin and Host syntax from being normalized into an allowlisted hostname.
Browsers do not normally emit userinfo in Origin or permit JavaScript to set Host directly, so this change is scoped as parser-boundary hardening rather than a demonstrated browser exploit. Valid hostname, port, IPv4, and bracketed IPv6 forms remain unchanged.
How has this been tested?
pnpm --filter @modelcontextprotocol/server exec vitest run test/server/originValidation.test.ts test/server/hostHeaderValidation.test.ts— 12 tests passed.pnpm --filter @modelcontextprotocol/server test— 470 tests passed.pnpm --filter @modelcontextprotocol/node exec vitest run test/validation.test.ts— 5 tests passed.pnpm --filter @modelcontextprotocol/server buildBreaking changes
None. Valid Origin and Host values retain their existing behavior.
Types of changes
Checklist