Skip to content

gateway: cap the manifest pull at MAX_MANIFEST_MB so a non-manifest hash cannot cost 64 MiB #2474

Closed

Description

@thiras

Problem

The gateway reads a bundle manifest into memory with Gateway::manifest (crates/cli/src/commands/gateway.rs). That pull uses the gateway's normal --max-blob-mb (default 1 TiB). The 64 MiB MAX_MANIFEST_BYTES check runs only on the bytes already read.

So a request for /<hash>/<path> or /<hash>/, where <hash> is a large non-manifest blob, pays for about 64 MiB plus the pipe read-ahead before it fails with "the manifest is larger than 67108864 bytes". Anyone who can reach the gateway can make it spend the operator's funds this way, once for each distinct hash. Nothing caches the failed hash.

decdn get decdn:<hash>/<path> -o - has the same route and does not have this problem. Since #2467, fetch_entry_hash (crates/cli/src/commands/fetch.rs) clamps the manifest fetch's max_blob_mb to MAX_MANIFEST_MB. The streamer then clamps the size claim before it sizes the fill store, and the drive ends with a typed decdn_client::BlobTooLarge. So the lanes request no bytes past the cap.

Proposed fix

  • In start_pull for a manifest, or in a manifest-specific BlobFetch, clone self.common and set max_blob_mb to MAX_MANIFEST_MB (0 → the cap, otherwise min). This is the same clamp fetch_entry_hash applies. Make MAX_MANIFEST_MB pub(crate).
  • Map BlobTooLarge from that pull to a 4xx response saying the blob is not a bundle manifest. A 502 is wrong here, because nothing upstream failed.
  • Optional: share the entry lookup with fetch::entry_hash(bytes, path). Today Gateway::entry repeats the find(|e| e.path == path) + parse_hash steps, and a malformed hash there does not name its entry. The gateway's not-found case answers with a 404, so the shared piece may only be the lookup on a parsed BundleManifest.

Test

The gateway tests drive pulls through the worker. A test that serves a blob larger than the cap for a manifest request should check that the request fails without the lanes requesting a range past MAX_MANIFEST_BYTES.

Follow-up from the #2467 review.

Activity

  1. added
    kind:feature
    area:cli
    prio:low
    area:payments
    on Oct 16, 2026
  2. self-assigned this
    on Oct 16, 2026
  3. moved this from Backlog to In progress in deCDNon Oct 16, 2026
  4. moved this from In progress to Done in deCDNon Oct 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area:cliarea:paymentskind:featureprio:low

Type

No type

Fields

Priority

None yet

Projects

  • Status
    Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions