~ knotless Search/
↑↓ move↵ open⇧↵ all results
0
0

Take files up to BLOB_UPLOAD_LIMIT, not axum's 2 MB

Merged
Merged chadtmiller.com asked to merge into main from chadtmiller.com/group-host:host/body-limit

What changes

com.atproto.repo.uploadBlob takes a file up to BLOB_UPLOAD_LIMIT (50 MiB unless set), as docs/reference/config.md already said it did. A body past the limit is refused with a 413 and BlobTooLarge, 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_body reads a body so for any method that takes one raw; importAccountSpace is next to use it.

Why

axum 0.8 holds every Bytes body 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 what importAccountSpace would 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:

  • a 2.5 MB file is taken;
  • a 3.5 MB one is refused as BlobTooLarge;
  • a 3.5 MB body with no token gets a 401, not a 413, so it is turned away before being read.

Without the change, the 2.5 MB file is refused with a 413; I ran it both ways.

Shortcomings

uploadImage keeps axum's default, since its own limit (1 MB) is under it.

🤖 Generated with Claude Code

Approved

This 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_blob now reads the body first and calls host.acting after. 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 raw Request or a Bytes read in the handler.
  • Coverage gate. The "InvalidRequest" branch in xrpc::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.

review.knotless.dev

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.

review.knotless.dev

No test reaches this non-413 branch, so the line gate will likely flag it.

Approved

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_blob still reads the body, up to 50 MiB, before host.acting runs. 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 InvalidRequest fallback in xrpc::body still has no test. The coverage gate enforces that, so I'm not withholding approval for it.
Approved

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_blob takes a raw Body and calls host.acting, then the scope check, then read_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_body no longer has a separate InvalidRequest branch, so there is nothing untested there. Every failure maps to the one too_large code, 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.

Merged as 8f57ab9