feat(gateway): add content size limits for responses#1138
Open
feat(gateway): add content size limits for responses#1138
Conversation
Codecov Report❌ Patch coverage is
@@ Coverage Diff @@
## main #1138 +/- ##
==========================================
+ Coverage 62.99% 63.02% +0.03%
==========================================
Files 266 266
Lines 26661 26698 +37
==========================================
+ Hits 16794 16827 +33
- Misses 8153 8155 +2
- Partials 1714 1716 +2
... and 13 files with indirect coverage changes 🚀 New features to boost your workflow:
|
Add two new Config options for gateway operators to limit responses based on content size read from the UnixFS root block: - MaxDeserializedResponseSize: caps deserialized responses only, trustless formats (raw, CAR) are not affected - MaxUnixFSDAGResponseSize: caps all response formats including raw blocks, CAR, and TAR Both return 501 Not Implemented with a message directing users to run their own IPFS node for large content. - gateway.go: add config fields with documentation - handler.go: add exceedsMax* helper methods - handler_defaults.go: check both limits using bytesSize - handler_block.go: check DAG limit using existing block size - handler_codec.go: check DAG limit using existing block size - handler_car.go: conditional Head call only when limit is set - handler_tar.go: check DAG limit using existing file.Size() - gateway_test.go: tests for both limits across all formats - CHANGELOG.md: document new config options
7d04de7 to
50371cd
Compare
1 task
lidel
added a commit
to ipfs/rainbow
that referenced
this pull request
Apr 10, 2026
Wire boxo gateway size limit options as CLI flags: - --max-deserialized-response-size / RAINBOW_MAX_DESERIALIZED_RESPONSE_SIZE - --max-unixfs-dag-response-size / RAINBOW_MAX_UNIXFS_DAG_RESPONSE_SIZE Both disabled by default (0). When set, content exceeding the limit returns 501 directing users to run their own IPFS node. Depends on ipfs/boxo#1138.
410 Gone is heuristically cacheable per RFC 9110 and cached by CDNs (Cloudflare, Fastly) by default, unlike 501 which is not cached in practice. This is consistent with how denylist blocking already uses 410 in this codebase. Set Cache-Control with 1 week max-age and 31 day stale-while-revalidate (same as generated directory listings) so CDN edges cache the rejection without repeated backend hits.
guillaumemichel
approved these changes
Apr 13, 2026
Contributor
|
Triage: test in staging before including in release. |
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.
Add two new Config options for gateway operators to limit responses based on content size read from the UnixFS root block:
MaxDeserializedResponseSize: caps deserialized responses only, trustless formats (raw, CAR) are not affectedMaxUnixFSDAGResponseSize: caps all response formats including raw blocks, CAR, and TARBoth return 410 Gone with a message directing users to run their own IPFS node for large content.
Integration points