Repository navigation
mcp: reject unencoded non-ASCII characters in Mcp-Param headers - #1521
Closed
luiacuaniello wants to merge 1 commit into
Closed
luiacuaniello wants to merge 1 commit into
luiacuaniello wants to merge 1 commit into
Conversation
validateParamHeaders compared an Mcp-Param-{Name} value without the
=?base64?...?= wrapper directly with the body value, so a value with
characters outside visible ASCII would pass whenever it matched the
body argument.
The 2026-07-28 specification requires such values to be Base64-encoded,
and servers to reject a recognized Mcp-Param header that contains
invalid characters.
Reject a value containing any byte other than visible ASCII, space or
horizontal tab before decoding it, with the usual header mismatch
error -32020.
Fixes modelcontextprotocol#1520
Contributor
|
This PR has been closed automatically. This repo only keeps pull requests open when they come from a maintainer, or from a contributor a maintainer has assigned to the linked issue, and you aren't currently assigned to #1520. You're welcome to keep pushing commits here (just avoid force-pushing, since GitHub can't reopen a rewritten branch), but that on its own won't get the PR reviewed or the issue assigned. There's no need to open a new PR either way. Maintainers: reopen, remove |
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 #1520.
validateParamHeadersdecodes anMcp-Param-{Name}value when it contains the=?base64?...?=wrapper, and otherwise compares it directly with the body value. Therefore, with protocol version 2026-07-28, a value with characters outside visible ASCII, sent unencoded, is accepted if it matches the body argument:Mcp-Param-Region: caféwith"region": "café"runs the tool. The specification requires that such values be Base64-encoded, and that servers reject a recognizedMcp-Param-{Name}header containing invalid characters (Server Behavior for Custom Headers).The value is now rejected before decoding if it contains any byte other than visible ASCII, space or horizontal tab (RFC 9110, section 5.5), with the same 400 status and
-32020(HeaderMismatch) error as the other header checks. A tab within the value is still accepted: it is a valid character in a field value, and the TypeScript SDK sends it unencoded. Base64-encoded values behave as before.The conformance check for this requirement,
sep-2243-server-reject-invalid-param-chars, only sends invalid Base64, which the server already rejects; this is why it passes onmain.Tests:
TestValidateParamHeaders_InvalidCharacters: unencoded non-ASCII characters and an unencoded control character are rejected; a non-ASCII value encoded in Base64 and a value containing a space and a tab are accepted. Without the change, both rejection cases fail.go test ./...,go test -raceonmcpandauth,go vet ./..., staticcheck v0.6.1 and the server conformance suite (0.2.0-alpha.11, both modes as in CI, with the baseline) pass, with the same conformance results as onmain.AI disclosure: I found this and prepared the fix with Claude Code; I reviewed the change and can explain it.