Skip to content

Conversation

@majiayu000
Copy link
Contributor

Summary

  • Added NulByteValidationMiddleware to validate incoming requests
  • Returns 400 Bad Request when NUL bytes (%00) detected in URL path or query
  • Prevents PostgreSQL encoding errors from being exposed as 500 errors

Before

GET /v0.1/servers?cursor=%00
→ 500 Internal Server Error
→ "invalid byte sequence for encoding UTF8: 0x00"

After

GET /v0.1/servers?cursor=%00
→ 400 Bad Request
→ "Invalid request: query parameters contain null bytes"

Fixes #862

majiayu000 and others added 2 commits December 28, 2025 22:29
Added NulByteValidationMiddleware to validate incoming requests and
return 400 Bad Request when NUL bytes are detected in the URL path
or query parameters. This prevents PostgreSQL encoding errors and
properly rejects malformed input.

Fixes modelcontextprotocol#862

Signed-off-by: majiayu000 <[email protected]>
@rdimitrov
Copy link
Member

hey, thanks for your PR @majiayu000 👋

Note there was another PR - #866 which was opened by @Avish34 and we had a chat together and agreed the approach in this one is preferable out of the 2.

Cheers! 🍻

@rdimitrov rdimitrov merged commit ab6a5a6 into modelcontextprotocol:main Jan 3, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unhandled NUL Bytes in API Requests

2 participants