Repository navigation
Read the request body only after authentication (v1.9.4) - #26
Merged
Merged
Conversation
The MCP endpoint parsed up to 10 MB of JSON before it looked at the credential. In managed mode the body is now read after the token, the session lookup and the ownership check, and the pre-auth rate limit applies before any of it. On a new session the body is read before the connection slot is taken, so a body that doesn't parse can't hold one. On an existing session the lookup now runs before the read, so the session is checked again afterwards and still answers 404 if it ended in the meantime. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Summary
handleMcpRequestparsed up to 10 MB of JSON before it checked the credential. Parsing costs far more memory than the size of the body, so that work shouldn't be available to callers without a valid token.New order in managed mode: rate limit → token → session lookup and ownership → read the body.
Behaviour changes
upload_fileneeds it and the tool name is only known after reading the body.docker-compose.yml.Test plan
npm test(401 tests), typecheck, lint and build passtests/authBeforeBody.spec.ts: 6 tests failed before the change. They send a body that never finishes, and the server never answered.--memory=512m: 10 parallel 10 MB requests without a token all get 401, memory stays at 35 MiB🤖 Generated with Claude Code