Skip to content

Fix: Raise the forward proxy's request body cap to 32 MiB - #1290

Merged
esnible merged 1 commit into
rossoctl:mainfrom
esnible:fix/request-size-32mb
Oct 5, 2026
Merged

esnible merged 1 commit into
rossoctl:mainfrom
esnible:fix/request-size-32mb

Conversation

@esnible

@esnible esnible commented Oct 5, 2026 •

Copy link
Copy Markdown
Member

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/messages were 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.

  • Requests get their own cap. The new constant is 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.
  • Responses are unchanged. maxBodySize stays at 10MB and now covers only response bodies and SSE frames. Streamed responses use no more memory than before.
  • Docs. The reverse proxy's comment and 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

  • New TestForwardProxy_RequestOverResponseCap sends 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 with status = 413, want 200.
  • TestForwardProxy_BodyTooLarge now sends maxRequestBodySize+1 and still gets a 413.
  • go build ./..., go vet ./listener/..., gofmt -l listener and go test ./... in core all pass.

Assisted-By: Claude (Anthropic AI) [email protected]

Summary by CodeRabbit

  • New Features
    • Forward-proxy requests up to 32 MiB can now be buffered and passed through; requests exceeding this limit are rejected.
  • Documentation
    • Clarified body-size limits: the forward proxy allows responses up to 10 MB, while the reverse proxy limits bodies in either direction to 1 MB.

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]>
@coderabbitai

coderabbitai Bot commented Oct 5, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

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
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: a1939d54-28a8-4f45-84ef-99d98f6a15ec
📥 Commits

Reviewing files that changed from the base of the PR and between d1ca610 and 5e840cb.

📒 Files selected for processing (4)
  • core/listener/forwardproxy/server.go
  • core/listener/forwardproxy/server_test.go
  • core/listener/reverseproxy/server.go
  • docs/framework-architecture.md

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

The 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.

Changes

Proxy body limits

Layer / File(s) Summary
Forward-proxy request limit and limit documentation
core/listener/forwardproxy/server.go, core/listener/forwardproxy/server_test.go, core/listener/reverseproxy/server.go, docs/framework-architecture.md
Buffered forward-proxy requests use a 32 MiB cap, while response buffering and SSE frames retain the 10 MiB limit. Tests verify that requests above the response cap reach the pipeline and backend intact, and that requests above the request cap are rejected. Comments and architecture documentation describe the forward- and reverse-proxy limits.

Priority: ⬆️ High

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: huang195

Merge Risk: ⚪ Minimal · up to 5e840

No actionable issue remains with this change after normal checks; the existing response and reverse-proxy limits remain unchanged.

Security Architecture Review

Security architecture risk: 🟡 Moderate · up to 5e840

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

  • Medium · security · inferred: The larger ingress cap materially increases memory reachable clients can retain before pipeline controls execute. With a body-reading pipeline, clients can send concurrent incomplete uploads above the old 10 MiB limit and pause before completion. The inspected listener has neither an aggregate buffering budget nor a request-body deadline, so this can threaten process-wide availability. Those missing controls predate the PR; accepting and retaining the larger uploads is the worsened condition. Loopback binding reduces remote exposure, and actual deployment isolation is unknown.
Security review details

Security Blast Radius

  • inferred — The resource-exhaustion scope is a reachable proxy process configured to inspect request bodies. Exhausting its memory could disrupt other listeners hosted in that same process. Local loopback binding restricts initiating clients to local reachability; wildcard binding leaves exposure dependent on network isolation. No cross-process, tenant-wide or fleet-wide impact is established.

Security Findings and Attack Paths

  • inferred — A client able to reach a body-buffering listener can open concurrent uploads, send almost 32 MiB on each and pause before completing them. The head retains those partial buffers before pipeline decisions; the base rejects after 10 MiB. The inspected server's header timeout does not bound this body-read phase. This supports increased denial-of-service potential, not a verified exhaustion event.

Trust Boundaries and Controls

  • observed — The finite byte limit remains ahead of pipeline and upstream execution for buffered requests. Oversize and unreadable bodies terminate early; successful bytes are replayed, and decrypted bridged requests share enforcement. The conditional buffering policy predates the PR and should not be interpreted as a newly introduced universal-cap bypass.

Resilience and Maintainability Implications

  • observed — Separating request and response constants prevents this compatibility increase from also widening response buffering and SSE-frame limits. It preserves those existing controls but does not provide an aggregate request-memory bound.

Hardening Proposals

  • proposed — Consider pairing the 32 MiB per-request ceiling with aggregate buffered-byte admission and an upload-idle deadline. Any reservations should be released on success, read failure and cancellation, without imposing a whole-response timeout on legitimate long-lived streams.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning 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… Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: raising the forward proxy’s request body cap to 32 MiB.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

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.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@huang195 huang195 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 breaks TestForwardProxy_OversizeResponse_RecordsProxyError and TestForwardProxy_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, and gofmt is 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.

Comment on lines +52 to +55
// 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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.Body is never released, and pctx lives until serveOutbound returns (the deferred RunFinish at :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.Pool drained:

    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) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +40 to +41
// in-cluster LLM route through a sidecar — so raise this to match if an
// oversized-body rejection is ever observed here.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit — "raise this to match" no longer says which value to match, now that the forward proxy has two (32 MiB request, 10MB response).

@esnible
esnible merged commit c4bab44 into rossoctl:main Oct 5, 2026
29 checks passed
@esnible
esnible deleted the fix/request-size-32mb branch October 5, 2026 16:40
esnible added a commit that referenced this pull request Oct 5, 2026
…#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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants