Skip to content

Commit 7de11e5

Browse files
committed
Merge #463: [bitreq] Add default size limits for headers, status line, and body
dfa0ce9 [bitreq] Set a default max-response limit of 1 GiB (Matt Corallo) 704fe64 [bitreq] Set default max header/status line limits (Matt Corallo) Pull request description: I realize we also don't have default size limits for the total response headers or status line, which is quite a large footgun. Instead, here we adopt the default response header limit from chrome and set a status line limit of 1/4 of that. Also adds a 1GiB default body response just to have *some* limit even if its incredibly high and we still document that folks should really set it. IMO we should cut this as 0.3.1. ACKs for top commit: jamillambert: ACK dfa0ce9 tcharding: ACK dfa0ce9 Tree-SHA512: b21c184baa0f1f7cc387a2cb07712062192af23a1f3ccba6b01f375be87e5776f7a7df0b0379b34b111e1fcaf3cf5f4de867121f83ef9e61bcf9ea0472e96f76
2 parents a9fdfb8 + dfa0ce9 commit 7de11e5

1 file changed

Lines changed: 14 additions & 8 deletions

File tree

bitreq/src/request.rs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,14 @@ impl Request {
117117
body: None,
118118
timeout: None,
119119
pipelining: false,
120-
max_headers_size: None,
121-
max_status_line_len: None,
122-
max_body_size: None,
120+
// Default matches chrome as of 2022-11:
121+
// https://groups.google.com/a/chromium.org/g/chromium-os-discuss/c/in-f59OKYAE/m/uVanwcXkAgAJ
122+
// https://source.chromium.org/chromium/chromium/src/+/refs/heads/main:net/http/http_stream_parser.h;l=164-168;drc=66941d1f0cfe9155b400aef887fe39a403c1f518
123+
max_headers_size: Some(256 * 1024),
124+
// Probably could be 128 bytes, but set conservatively for good measure.
125+
max_status_line_len: Some(64 * 1024),
126+
// Picked somewhat randomly
127+
max_body_size: Some(1024 * 1024 * 1024),
123128
max_redirects: 100,
124129
#[cfg(feature = "proxy")]
125130
proxy: None,
@@ -221,8 +226,7 @@ impl Request {
221226
///
222227
/// `None` disables the cap, and may cause the program to use any
223228
/// amount of memory if the server responds with a lot of headers
224-
/// (or an infinite amount). The default is None, so setting this
225-
/// manually is recommended when talking to untrusted servers.
229+
/// (or an infinite amount). The default is 256KiB.
226230
pub fn with_max_headers_size<S: Into<Option<usize>>>(mut self, max_headers_size: S) -> Request {
227231
self.max_headers_size = max_headers_size.into();
228232
self
@@ -239,8 +243,7 @@ impl Request {
239243
///
240244
/// `None` disables the cap, and may cause the program to use any
241245
/// amount of memory if the server responds with a long (or
242-
/// infinite) status line. The default is None, so setting this
243-
/// manually is recommended when talking to untrusted servers.
246+
/// infinite) status line. The default is 64 KiB.
244247
pub fn with_max_status_line_length<S: Into<Option<usize>>>(
245248
mut self,
246249
max_status_line_len: S,
@@ -259,7 +262,10 @@ impl Request {
259262
///
260263
/// `None` disables the cap, and may cause the program to use any
261264
/// amount of memory if the server responds with a large (or
262-
/// infinite) body. The default is None, so setting this
265+
/// infinite) body.
266+
///
267+
/// The default is 1 GiB, which is likely to cause an
268+
/// out-of-memory condition in many cases so setting this
263269
/// manually is recommended when talking to untrusted servers.
264270
pub fn with_max_body_size<S: Into<Option<usize>>>(mut self, max_body_size: S) -> Request {
265271
self.max_body_size = max_body_size.into();

0 commit comments

Comments
 (0)