Repository navigation
fix(api): parse request bodies after auth - #3833
Conversation
Body parsers ran globally with a 32 MB limit before any auth check, so an anonymous caller could make the API buffer and parse 32 MB per request before getting a 401. Parsing now runs after each auth middleware; authenticated callers keep 32 MB, and login, register and team setup take up to 100 KB. Fixes #3831
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
🦋 Changeset detectedLatest commit: e360a7e The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
🔴 Tier 4 — CriticalTouches authentication, tenancy data models, the public API or shipped database config — or substantially changes the query rendering engine, background tasks, the OTel pipeline, image build, or release CI. Why this tier:
Review process: Deep review from a domain expert. Synchronous walkthrough may be required. Stats
|
Duplicate code analysisNo new duplicate code introduced by this PR. jscpd compared this branch against |
PR Review
2 finding(s): 🔴 0 P0/P1 · 🟡 0 P2 · 🔵 2 P3 No inline comments. 2 P3 folded at the bottom. 🔵 2 P3 — no action needed before merge
Priority comes from a separate grading pass over the finished review. P3 is folded here instead of posted inline. No finding blocks merge automatically; a maintainer decides. |
There was a problem hiding this comment.
Auto-approved by the AI review gate on 3222596. Details in the approver's comment on this pull request.
AI review gate — auto-approved
History (latest 5 heads, newest first)
|
E2E Test Results✅ All tests passed • 478 passed • 1 skipped • 1141s
Tests ran across 4 shards in parallel. |
Deep Review✅ No critical issues found. Eleven reviewers traced every route mount, middleware ordering, the proxy 🟡 P2 -- recommended
🔵 P3 nitpicks (5)
Pre-existing (non-blocking)
Reviewers (11): correctness, security, adversarial, api-contract, reliability, testing, maintainability, kieran-typescript, project-standards, agent-native, learnings-researcher. Testing gaps:
No finding blocks merge automatically. A maintainer will expect P0/P1 findings in code this PR changes to be fixed; P2/P3 are your call -- fix or reply. Never fix findings about surrounding code here; reply instead. Do not widen the PR. How to respond |
Summary
The API parsed JSON, text and form bodies up to 32 MB on every route before checking auth, so anyone could make it buffer and parse 32 MB per request and only then get a 401. Bodies are now parsed after the auth check.
/api/v2,/mcp) and local mode keep the 32 MB limit.Breaking changes: none for authenticated callers. A client posting more than 100 KB to login, register or team setup is now rejected.
Implementation detail
parseBodyafterisUserAuthenticatedorvalidateUserAccessKey. A new route that takes a body outside those mounts has to addparsePublicBodyitself./mcpusesexpress()plus the SDK'slocalhostHostValidationinstead ofcreateMcpExpressApp, whose built-in JSON parser ran before the access key check.captureProxyBodymatches onbaseUrl + path, because the parser now runs inside the/clickhouse-proxymount, wherereq.pathdrops the mount prefix.bodyParser.int.test.tsand the fullpackages/apiintegration suite.How to reproduce
Starting point:
yarn dev, withAPIset to the API URL. Malformed JSON shows whether the body was parsed before auth.On
main:400: the body was parsed before the auth check.On this branch:
401: the request is rejected before the body is read.The issue has a repro that shows the memory growth from four 32 MB requests.
How to test on Vercel preview
N/A, non-UI change.
References
Note
Medium Risk
Touches global Express middleware ordering for all body-bearing routes; miswired mounts could break login or proxy forwarding, but behavior is covered by new integration tests.
Overview
Request bodies are no longer parsed globally up to 32 MB. Protected routes (
/dashboards,/api/v2/*,/mcp, etc.) runparseBodyonly after session or API-key auth, so anonymous POSTs get 401 without reading the body (fixes unauthenticated large-body abuse).Pre-auth routes (
login/password,register/password,team/setup/:token) useparsePublicBodywith a 100 KB cap instead of the old global limit. Oversized register/team-setup payloads return 413; login still surfaces oversize via redirect.The MCP router drops
createMcpExpressApp’s built-in JSON parser and parses aftervalidateUserAccessKey.captureProxyBodymatches ClickHouse proxy paths viabaseUrl + pathbecause parsing now lives inside the/clickhouse-proxymount. Integration tests assert anonymous 401 without parse, public 100 KB caps, and authenticated 32 MB behavior.Reviewed by Cursor Bugbot for commit e360a7e. Bugbot is set up for automated code reviews on this repo. Configure here.