Repository navigation
Fix: Raise the forward proxy's request body cap to 32 MiB - #1290
Conversation
The forward proxy rejected request bodies over 10MB with a 413 before the pipeline ran. Claude Code conversations outgrow that: one laptop logged 30 rejected POST api.anthropic.com/v1/messages in a week, from 10,489,160 to 12,284,233 bytes, all well under the 32 MB Anthropic documents for the Messages API. Requests now get their own cap, maxRequestBodySize, at 32 MiB. The docs do not say whether "32 MB" means 10^6 or 2^20 bytes; the larger reading lets the provider judge a body near the line rather than us. maxBodySize stays at 10MB and now bounds only response bodies and SSE frames, so streamed responses cost no more memory than before. TestForwardProxy_RequestOverResponseCap sends the largest rejected size and checks it reaches the pipeline and the upstream whole; it fails with a 413 against the old cap. The reverse proxy's comment and docs/framework-architecture.md described the old limit and are updated. Refs rossoctl#1250 Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Ed Snible <[email protected]>
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configuration
📒 Files selected for processing (4)
Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review. 📝 WalkthroughWalkthroughThe forward proxy now allows buffered request bodies up to 32 MiB, separate from its 10 MiB response and SSE-frame limit. The reverse proxy remains at 1 MiB. Tests and documentation describe these limits. ChangesProxy body limits
Priority: ⬆️ High Estimated code review effort: 2 (Simple) | ~10 minutes Change: Bug fix Suggested reviewers: Merge Risk: ⚪ Minimal · up to No actionable issue remains with this change after normal checks; the existing response and reverse-proxy limits remain unchanged. Security Architecture ReviewSecurity architecture risk: 🟡 Moderate · up to The larger limit supports legitimate requests but also increases memory that reachable clients can occupy before request processing. Concurrent stalled uploads could affect the whole proxy process. Local-only operation limits exposure; network-exposed deployments need stronger resource containment. Retained concerns
Security review detailsSecurity Blast Radius
Security Findings and Attack Paths
Trust Boundaries and Controls
Resilience and Maintainability Implications
Hardening Proposals
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Full details: Docstring CoverageExplanation Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 3 files. (1 skipped: 1 unsupported.)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
huang195
left a comment
There was a problem hiding this comment.
No must-fix: the change is correct and complete.
serveOutbound(:377) is the only place the forward proxy buffers a request body, and bridged CONNECT and transparent-redirect TLS both go through it.- The response side stays on
maxBodySize. Pointing it at the new constant breaksTestForwardProxy_OversizeResponse_RecordsProxyErrorandTestForwardProxy_FallbackBuffered_BufferingFailures, so it stays protected. - With the old 10MB cap put back, the new test fails with
413, want 200. - I found no stale 10MB/1MB references elsewhere, and the Anthropic link does list 32 MB for the Messages API.
- The touched tests pass under
-race, andgofmtis clean.
Inline: 2 suggestions (the memory/lifetime comment, which includes measurements and the in-cluster 384Mi sidecar limit; and pinning the 32 MiB boundary) and 3 nits.
Pre-existing, not this PR's to fix, but relevant to #1250's "how do users find out" question: agentop's /v1/events parser caps an SSE line at 4 MiB (cmd/agentop/apiclient/sse.go:130). The live stream sends full events, because view=summary only applies to the snapshot endpoint, and a request event's JSON is about the size of its body. So any request over about 4 MiB fails the scanner with bufio.Scanner: token too long, and the stream drops into reconnect backoff. That was already true for 4–10 MB requests. This PR adds 10–32 MiB requests to the set that get recorded; before, they got a 413 and no row.
| // limit also decides whether telemetry is recorded at all. The whole body is | ||
| // held while the pipeline runs, so one in-flight request can hold this much | ||
| // on the request side, on top of the response-side cost described at | ||
| // maxBodySize. |
There was a problem hiding this comment.
suggestion — this understates both how long the body is held and how much it costs.
-
How long: "held while the pipeline runs" is too short.
pctx.Bodyis never released, andpctxlives untilserveOutboundreturns (the deferredRunFinishat :370 captures it). So the buffered request stays in memory through the upstream call and the whole response relay, including a minutes-long SSE stream. -
How much: one request through this proxy, heap measured after GC with
sync.Pooldrained:body pipeline live during request allocated 10 MiB ReadsBody recorder 10.1 MiB 22.6 MiB 10 MiB inference-parser 21.0 MiB 45.3 MiB 31 MiB ReadsBody recorder 31.0 MiB 72.9 MiB 31 MiB inference-parser 64.9 MiB 143.0 MiB With a parser in the pipeline, which is the usual reason a body gets buffered, the request side holds about 2x the body, not 1x.
This matters beyond the laptop. The same constant governs every in-cluster AuthBridge sidecar, whose default memory limit is 384Mi (rossoctl/operator internal/webhook/config/defaults.go:104), and nothing in this tree sets GOMEMLIMIT. A couple of concurrent near-cap requests is now enough to OOM-kill the sidecar, where at 10MB it took about three times as many. Worth saying here and in the PR body.
Optional: a rejected request still reads the full 32 MiB before answering 413, even when Content-Length already announced the overrun (the test log shows read=33554432 ... contentLength=33554433). Checking r.ContentLength > maxRequestBodySize before reading would avoid that.
| // refused at the old shared 10MB cap (#1250) — a Claude Code conversation the | ||
| // Anthropic API would have taken — so it must now reach both the pipeline and | ||
| // the upstream whole. | ||
| func TestForwardProxy_RequestOverResponseCap(t *testing.T) { |
There was a problem hiding this comment.
suggestion — no test pins the 32 MiB value itself.
This test proves the cap is above 12,284,233 bytes. TestForwardProxy_BodyTooLarge sends maxRequestBodySize+1, so it tracks whatever the constant is. Mutation: with the reader at server.go:377 set to 16<<20, the whole forwardproxy package still passes.
The comment's specific promise is that a body near the line reaches the provider rather than being judged by us. A case at exactly maxRequestBodySize that expects a 200 and the full length upstream would pin that boundary. It costs about what BodyTooLarge already does (~0.5s).
| Every mutation path also **clears `Content-Encoding`**: the framework can't know whether the plugin decompressed a gzipped body before rewriting, so shipping plain bytes without the old encoding header beats shipping a malformed archive. Auto-decompress/recompress is a possible future feature, explicitly out of scope today. | ||
|
|
||
| **Body-size limits.** Bodies over `maxBodySize` (1 MB) are rejected by the listener at buffer time — before the mutator sees anything. Plugins don't need to guard against oversized input. | ||
| **Body-size limits.** Bodies over the listener's buffer cap are rejected at buffer time — before the mutator sees anything. On the forward proxy that is 32 MiB for a request (`maxRequestBodySize`) and 10 MB for a response (`maxBodySize`); on the reverse proxy it is 1 MB either way. Plugins don't need to guard against oversized input. |
There was a problem hiding this comment.
nit — this sentence now names the forward and reverse proxies but drops extproc, which the old "1 MB" wording covered.
- Extproc returns a 413 for a request over 1 MB (
extproc/server.go:219). - It truncates a response instead of rejecting it (
appendBoundedBody,extproc/server.go:1302). So "rejected at buffer time ... Plugins don't need to guard against oversized input" is not true for extproc responses.
Also, "32 MiB" sits next to "10 MB", but maxBodySize is 10<<20, which is 10 MiB.
|
|
||
| // Send body larger than maxBodySize (1MB) | ||
| bigBody := strings.Repeat("x", maxBodySize+1) | ||
| bigBody := strings.Repeat("x", maxRequestBodySize+1) |
There was a problem hiding this comment.
nit — this test builds recorder but never asserts on it, so it shows the upstream was skipped but not that the pipeline was. One line would cover it: if recorder.receivedBody != nil { t.Error("plugin should not see an oversized body") }. This predates the PR, but the PR edits this test.
| // in-cluster LLM route through a sidecar — so raise this to match if an | ||
| // oversized-body rejection is ever observed here. |
There was a problem hiding this comment.
nit — "raise this to match" no longer says which value to match, now that the forward proxy has two (32 MiB request, 10MB response).
…#1293) A forward-proxy request whose body could not be buffered got its 413 (or 400) and recorded nothing, because the early return ran before the session was resolved. On plain HTTP that left no row at all. On a bridged tunnel, the path Claude Code takes to api.anthropic.com, the only rows were the tunnel's own open and a close saying 200, in the default bucket, so a request the client saw fail looked healthy. The return now records the request row and a paired failure row, in the session the client's headers name. bodyread.Failure classifies it: - over maxRequestBodySize: 413, proxy_error, with the announced size and the limit in the message - the client hung up mid-upload: 499, client_canceled - anything else unreadable: 400, a new kind, request_unreadable On a bridged tunnel the request row takes the tunnel's open with it, as any recorded request does, so no misleading close is recorded. Neither the pipeline nor a Finisher runs, so the request row carries no parse. From the #1290 review: - TestForwardProxy_RequestBodyCapIs32MiB pins the cap with literals: exactly 32 MiB reaches the plugin and the upstream whole, and one byte more gets a 413. It fails with the reader at 16 MiB and with the constant at 64 MiB, which the constant-relative tests did not. - TestForwardProxy_BodyTooLarge now asserts the plugin never saw the body. Refs #1250 Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Ed Snible <[email protected]>
Summary
The forward proxy rejected any request body over 10MB with a 413, before the pipeline ran. Claude Code conversations grow past that. On one laptop, 30
POST api.anthropic.com/v1/messageswere rejected in a week, ranging from 10,489,160 to 12,284,233 bytes. All of them were well under the 32 MB limit Anthropic documents for the Messages API.maxRequestBodySize = 32 << 20. The docs don't say whether "32 MB" means 10^6 or 2^20 bytes. Taking the larger reading means a body near the limit is judged by the provider, which knows its own limit, rather than rejected by us.maxBodySizestays at 10MB and now covers only response bodies and SSE frames. Streamed responses use no more memory than before.docs/framework-architecture.md, which still said 1 MB, now describe the actual limits.Refs #1250. This doesn't close it. The 120 oversized download responses in that issue are still rejected at 10MB, and the issue's question of how to tell users their traffic was affected is still open.
Test plan
TestForwardProxy_RequestOverResponseCapsends 12,284,233 bytes, the largest request rejected in Research Cortex size limit vs what agents really send #1250, and checks that the pipeline and the upstream both receive all of it. With the old 10MB cap put back, it fails withstatus = 413, want 200.TestForwardProxy_BodyTooLargenow sendsmaxRequestBodySize+1and still gets a 413.go build ./...,go vet ./listener/...,gofmt -l listenerandgo test ./...incoreall pass.Assisted-By: Claude (Anthropic AI) [email protected]
Summary by CodeRabbit