-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Clarify HTTP 403 status for invalid Origin headers #1439
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Clarify HTTP 403 status for invalid Origin headers #1439
Conversation
|
modelcontextprotocol/python-sdk#1353 for python SDK if this is accepted |
|
@pja-ant is there a RFC reference we can include that rationalizes the response code? |
Hey @dend. You mean a SEP? Thought that might be overkill, but happy to put one together if you feel it's needed here. The SEP guidelines state (emphasis mine):
My sense is that this isn't super substantial, but at the end of the day I'm the noob here so I'll do whatever people like! In terms of the rationalization: between 400 and 403 (the only two contenders in my opinion), I feel 403 is most appropriate since 400 generally means some sort of "client error" where the server couldn't process even if it wanted whereas 403 "indicates that the server understood the request but refuses to fulfill it", which is exactly what's happening here. |
|
I think this is fine without a SEP. @localden @pcarleton, any objections to defining 403's? @pja-ant can you add a minor changelog entry? |
Add explicit guidance that servers MUST respond with HTTP 403 Forbidden when the Origin header is present but invalid. This addresses part of issue modelcontextprotocol#1398 regarding inconsistent error responses across SDKs. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
7dfb0b8 to
e51a039
Compare
|
Thanks for the improvement introduced in this PR, the added clarification definitely helps.
still needs refinement to accurately reflect when DNS rebinding protection is relevant and to avoid creating unintended non-compliance in existing SDKs. As written, the statement implies that all MCP servers, in all environments, must enforce Origin validation. This has two issues:
For these reasons, I suggest at least rephrasing the requirement to scope it appropriately:
Even better, since Host validation is the actual mechanism required to prevent DNS rebinding:
However, enforcing Origin validation after Host validation should be optional and not mandatory (when running locally). Please let me know if you would prefer that I file a separate issue for these remarks. |
Add explicit guidance that servers MUST respond with HTTP 403 Forbidden when the Origin header is present but invalid. This addresses part of issue #1398 regarding inconsistent error responses across SDKs. Currently TypeScript returns 403, but Python return 400. 403 seems like the most appropriate response here, so going with that (and will update Python if this is accepted).
Motivation and Context
Spec does not specify the response, so implementations have diverged.
#1398
How Has This Been Tested?
Breaking Changes
Technically this could be a breaking change if there are some clients somewhere are relying on specific implementation of this from specific SDKs, but since e.g. TypeScript SDK already returns 403, it's already behavior that clients have to deal with depending on the server.
Marking as "breaking change" as a precaution, but I think this should be a safe change.
Types of changes
Checklist