Repository navigation
Accept every Origin with allowed_origins: :any and keep the Host check - #685
Open
koic wants to merge 1 commit into
Conversation
…` check ## Motivation and Context `StreamableHTTPTransport` accepts a cross-origin request only when its `Origin` is listed in `allowed_origins:`. A remote server that browser-based clients on any origin may call, authenticated by a bearer token alone, had two ways to admit them: `dns_rebinding_protection: false`, which also turns off the `Host` check, or building the transport per request with that request's own `Origin` in the list. `allowed_origins: :any` now skips the `Origin` check alone. A rebound request names the attacker's host in `Host` and, if sent, `Origin`, so it passes as same-origin and the `Host` check is what refuses it; that check stays on. What the `Origin` check adds is refusing a page on another site that relies on what the browser attaches by itself (a cookie, or the reach of a server on localhost), which a server requiring a bearer token on every request does not accept. The docs state that condition. The TypeScript SDK arms its Host and Origin validation separately, so the same setup is already possible there. Resolves modelcontextprotocol#684. ## How Has This Been Tested? `test/mcp/server/transports/streamable_http_transport_test.rb`; the test that sends three foreign `Origin` values with `allowed_origins: :any` gets 403 on the previous library. ## Breaking Changes A Symbol passed as `allowed_origins:` was accepted before and matched no `Origin`. `:any` now turns the `Origin` check off, and another Symbol raises `ArgumentError` at construction.
This branch has not been deployed
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.
Motivation and Context
StreamableHTTPTransportaccepts a cross-origin request only when itsOriginis listed inallowed_origins:. A remote server that browser-based clients on any origin may call, authenticated by a bearer token alone, had two ways to admit them:dns_rebinding_protection: false, which also turns off theHostcheck, or building the transport per request with that request's ownOriginin the list.allowed_origins: :anynow skips theOrigincheck alone. A rebound request names the attacker's host inHostand, if sent,Origin, so it passes as same-origin and theHostcheck is what refuses it; that check stays on. What theOrigincheck adds is refusing a page on another site that relies on what the browser attaches by itself (a cookie, or the reach of a server on localhost), which a server requiring a bearer token on every request does not accept. The docs state that condition.The TypeScript SDK arms its Host and Origin validation separately, so the same setup is already possible there.
Resolves #684.
How Has This Been Tested?
test/mcp/server/transports/streamable_http_transport_test.rb; the test that sends three foreignOriginvalues withallowed_origins: :anygets 403 on the previous library.Breaking Changes
A Symbol passed as
allowed_origins:was accepted before and matched noOrigin.:anynow turns theOrigincheck off, and another Symbol raisesArgumentErrorat construction.Types of changes
Checklist