Skip to content

Read the request body only after authentication (v1.9.4) - #26

Merged
christophdb merged 1 commit into
mainfrom
fix/authenticate-before-reading-body
Nov 4, 2026
Merged

christophdb merged 1 commit into
mainfrom
fix/authenticate-before-reading-body

Conversation

@christophdb

Copy link
Copy Markdown
Member

Summary

handleMcpRequest parsed 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.

  • New session: the pre-auth limit and the token check now run before the read. The read happens before the connection slot is taken, so a body that doesn't parse can't hold a slot.
  • Existing session: the lookup now runs before the read, so the session is checked again afterwards. A session that ended while the body was arriving still gets a 404.

Behaviour changes

  • Rejected requests (401, 403, 404, 429) are answered without waiting for the body.
  • Selfhosted mode has no credential to check over HTTP, so there the read only moves behind the session lookup. The 10 MB limit stays for everyone, because upload_file needs it and the tool name is only known after reading the body.
  • No changes to configuration or docker-compose.yml.

Test plan

  • npm test (401 tests), typecheck, lint and build pass
  • tests/authBeforeBody.spec.ts: 6 tests failed before the change. They send a body that never finishes, and the server never answered.
  • Image built locally, managed mode, --memory=512m: 10 parallel 10 MB requests without a token all get 401, memory stays at 35 MiB

🤖 Generated with Claude Code

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>
@christophdb
christophdb merged commit ead5893 into main Nov 4, 2026
5 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.

1 participant