chadtmiller.com/group-host
atmosphere group host
Take files up to BLOB_UPLOAD_LIMIT, not axum's 2 MB
MergedThis sets the uploadBlob route's body limit to BLOB_UPLOAD_LIMIT and adds xrpc::body. An oversize body now gets a 413 with BlobTooLarge in XRPC's shape. The change is small and the test covers both sides of the old 2 MB cap.
Two things, neither blocking:
- Body is read before authentication.
upload_blobnow reads the body first and callshost.actingafter. Before, the same ordering held, but the cap was 2 MB. Now an unauthenticated caller can make the host buffer up to 50 MiB per request before it is refused. Consider authenticating before the body is read, or at least say in the body that this is accepted. The auth check uses only headers, so it can move ahead of the read if the extractor takes the rawRequestor aBytesread in the handler. - Coverage gate. The
"InvalidRequest"branch inxrpc::body(a body rejection that isn't a 413) has no test that I can see. The 100% line gate will probably fail on it. The gate enforces that, so I'm not withholding approval for it.
crates/group-host/src/token_writes.rsline 420Outdated
These lines can no longer be read.
This buffers up to the full limit (default 50 MiB) before host.acting checks the caller's token. An unauthenticated request can now make the host hold 50 MiB. Consider authenticating first.
crates/group-host/src/xrpc.rsline 66Outdated
These lines can no longer be read.
No test reaches this non-413 branch, so the line gate will likely flag it.
This sets uploadBlob's body limit to BLOB_UPLOAD_LIMIT. It adds xrpc::body, so an oversize body gets a 413 with BlobTooLarge in XRPC's shape. The test covers both sides of the old 2 MB cap and looks right.
My earlier round raised two points, and neither is addressed in this diff.
- Body read before authentication.
upload_blobstill reads the body, up to 50 MiB, beforehost.actingruns. An unauthenticated caller can make the host buffer that much per request. I'd still move auth ahead of the read or say in the body that this is accepted. I'm not blocking on it. - Coverage. The
InvalidRequestfallback inxrpc::bodystill has no test. The coverage gate enforces that, so I'm not withholding approval for it.
This sets uploadBlob's limit to BLOB_UPLOAD_LIMIT through a new xrpc::read_body. An oversize or cut-off body now gets a 413 with BlobTooLarge in XRPC's shape.
Both earlier points are addressed:
- Auth before the read.
upload_blobtakes a rawBodyand callshost.acting, then the scope check, thenread_body. An unauthenticated caller can no longer make the host buffer 50 MiB. The new test sends a 3.5 MB body with no token and expects a 401. - Coverage.
read_bodyno longer has a separateInvalidRequestbranch, so there is nothing untested there. Every failure maps to the onetoo_largecode, and the test covers it.
The test covers both sides of the old 2 MB cap and the 403 path. I found nothing that needs changing.
What changes
com.atproto.repo.uploadBlobtakes a file up toBLOB_UPLOAD_LIMIT(50 MiB unless set), asdocs/reference/config.mdalready said it did. A body past the limit is refused with a 413 andBlobTooLarge, in XRPC's{error, message}, rather than axum's plain text. The body is read only after the caller's token is checked: one without a token, or with one not letting it upload that type, is turned away before any of its body is read.xrpc::read_bodyreads a body so for any method that takes one raw;importAccountSpaceis next to use it.Why
axum 0.8 holds every
Bytesbody to 2 MB unless its route says otherwise, and none did. So any file over 2 MB an app uploaded as a group was refused, with a plain-text 413 before the handler's own check ran. I found it while reading whatimportAccountSpacewould take.Raising the limit on the route instead would have had axum read the whole body, up to 50 MiB, before the handler checked who was asking. The first review caught that. So the handler takes the body unread, and reads it with the limit once the caller may send one.
How it was checked
tokens.rs's upload test runs with the limit set to 3 MB:BlobTooLarge;Without the change, the 2.5 MB file is refused with a 413; I ran it both ways.
Shortcomings
uploadImagekeeps axum's default, since its own limit (1 MB) is under it.🤖 Generated with Claude Code