You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(gateway): add content size limits for responses
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
Copy file name to clipboardExpand all lines: CHANGELOG.md
+3Lines changed: 3 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -16,6 +16,9 @@ The following emojis are used to highlight certain changes:
16
16
17
17
### Added
18
18
19
+
-`gateway`: `Config.MaxDeserializedResponseSize` allows setting a maximum file/directory size for deserialized gateway responses. Content exceeding this limit returns `501 Not Implemented`, directing users to run their own IPFS node. Trustless response formats (`application/vnd.ipld.raw`, `application/vnd.ipld.car`) are not affected. The size is read from the UnixFS root block, so no extra block fetches are needed for the check. [#1129](https://github.com/ipfs/boxo/pull/1129)
20
+
-`gateway`: `Config.MaxUnixFSDAGResponseSize` allows setting a maximum content size applied to all response formats (deserialized, raw blocks, CAR, TAR). Content exceeding this limit returns `501 Not Implemented`. For most handlers the check reuses size information already available in the request path; for CAR responses a lightweight `Head` call is made only when the limit is configured. [#1129](https://github.com/ipfs/boxo/pull/1129)
err:=fmt.Errorf("responses are not supported for content larger than %d bytes: for large content, run your own IPFS node (https://docs.ipfs.tech/install/)", i.config.MaxUnixFSDAGResponseSize)
1135
+
i.webError(w, r, err, http.StatusNotImplemented)
1136
+
returntrue
1137
+
}
1138
+
returnfalse
1139
+
}
1140
+
1141
+
// exceedsMaxDeserializedResponseSize checks whether sz exceeds the configured
1142
+
// MaxDeserializedResponseSize. If it does, it writes a 501 error and returns true.
1143
+
// Returns false (no-op) when the limit is disabled or not exceeded.
err:=fmt.Errorf("deserialized responses are not supported for content larger than %d bytes: for large content, run your own IPFS node (https://docs.ipfs.tech/install/)", i.config.MaxDeserializedResponseSize)
0 commit comments