Repository navigation
Read the request body after the source and key checks, with the gateway's 256 MiB as the only limit, v0.64.1 - #296
Merged
Merged
Conversation
…ay's 256 MiB as the only limit The body was taken by axum's `Bytes` extractor, which carries a 2 MB default limit: a conversation holding a few inline screenshots was refused with 413 before reaching the gateway's own 256 MiB check, compaction requests included, and nothing was recorded. The extractor also buffered the whole body before the source and key checks ran. `passthrough` now takes the body unread and reads it once those checks and the POST check pass, counting the bytes actually received. A Content-Length already over the limit is refused without reading. Oversized requests get 413 in the client's own error format (`request_too_large` for Anthropic). Fixes #295 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Fixes #295.
What was wrong
passthroughtook the body with axum'sBytesextractor, which appliesDefaultBodyLimit(2 MB). Any request over 2,097,152 bytes was answered413 Failed to buffer the request bodyduring extraction, so the pipeline's 256 MiB check was unreachable, the error was not in the client's format, and nothing was recorded. A session with a few inline screenshots could no longer be compacted.The extractor also buffered the whole body before the handler ran, i.e. before the source-address and key checks.
Change
passthroughtakesaxum::body::Bodyunread. The body is read inserver::intake::readonly after the source check, key check and POST check pass.readcounts the bytes actually received (http_body_util::Limited); this is the only size limit in the gateway (256 MiB, unchanged).Content-Lengthalready over the limit is refused without reading. The message says the length is declared, since the client wrote it. Understating the length does not lift the limit: hyper frames the body by the declared length, andLimitedstill counts.Source::TooLarge: 413, slugrequest(request_too_largein Anthropic format).forward::check_body_sizeand the pipeline's check are removed.gw.request.body_too_largeis replaced bygw.request.body_declared_too_large,gw.request.body_over_limitandgw.request.body_unreadable(the old one's sentence and arguments changed).Tests
tests/body_size.rs: a 3 MiB request reaches the upstream; a wrong key with a 100 MiB declared length gets 401 without the body being sent; a 300 MiB declared length gets 413 in Anthropic format without the body being sent or forwarded.server::intakeunit tests: at the limit, over the limit without a length, declared over the limit (body never read), declared length understating the body.🤖 Generated with Claude Code