Skip to content

Commit 94abb8e

Browse files
committed
Refine docs
1 parent e77dba7 commit 94abb8e

1 file changed

Lines changed: 14 additions & 34 deletions

File tree

docs/advanced/request-body-limiting.md

Lines changed: 14 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
# Request Body Limiting
22

3-
The `max_tx_bytes` feature allows you to limit the total size of HTTP requests (headers + body) sent to upstream servers. This is useful for:
3+
The `max_tx_bytes` feature allows you to limit the total size of HTTP requests sent to upstream servers.
44

5-
- **Preventing large uploads**: Limit file upload sizes to specific endpoints
6-
- **Cost control**: Prevent expensive large requests to metered APIs
7-
- **Security**: Mitigate data exfiltration through large POST requests
5+
This is primarily designed for mitigating code exfiltration attacks through covert channels.
6+
7+
## Size Calculation
8+
9+
The `max_tx_bytes` limit applies to **complete** HTTP requests, including:
10+
11+
1. **Request line**: `METHOD /path HTTP/1.1\r\n`
12+
2. **Headers**: Each header as `Name: Value\r\n`
13+
3. **Header separator**: Final `\r\n` between headers and body
14+
4. **Body**: Request body bytes
815

916
## Response Format
1017

@@ -30,8 +37,8 @@ The limiting behavior depends on whether the request includes a `Content-Length`
3037

3138
When the request includes a `Content-Length` header (most standard HTTP clients):
3239

33-
1. **Early Detection**: httpjail calculates the total request size (headers + Content-Length)
34-
2. **Immediate Rejection**: If the total exceeds `max_tx_bytes`, the client receives a `413 Payload Too Large` error immediately
40+
1. **Early Detection**: httpjail calculates the total request size
41+
2. **Immediate Rejection**: If it exceeds `max_tx_bytes`, the client receives a `413 Payload Too Large` error immediately
3542
3. **No Upstream Contact**: The upstream server is never contacted, preventing unnecessary load
3643
4. **Clear Feedback**: The error message indicates the actual size and limit
3744

@@ -48,7 +55,7 @@ Request body size (5000 bytes) exceeds maximum allowed (1024 bytes)
4855
When the request uses chunked encoding or doesn't include `Content-Length`:
4956

5057
1. **Stream Truncation**: The request body is truncated at the limit during streaming
51-
2. **Upstream Receives Partial**: The upstream server receives exactly `max_tx_bytes` total bytes (headers + truncated body)
58+
2. **Upstream Receives Partial**: The upstream server receives exactly `max_tx_bytes` total bytes (url + headers + truncated body)
5259
3. **Connection Closes**: The connection terminates after reaching the limit
5360

5461
## Examples
@@ -90,33 +97,6 @@ for line in sys.stdin:
9097
sys.stdout.flush()
9198
```
9299

93-
## Size Calculation
94-
95-
The `max_tx_bytes` limit includes:
96-
97-
1. **Request line**: `METHOD /path HTTP/1.1\r\n`
98-
2. **Headers**: Each header as `Name: Value\r\n`
99-
3. **Header separator**: Final `\r\n` between headers and body
100-
4. **Body**: Request body bytes
101-
102-
### Example Calculation
103-
104-
For this request:
105-
```http
106-
POST /upload HTTP/1.1\r\n
107-
Host: example.com\r\n
108-
Content-Length: 500\r\n
109-
\r\n
110-
[500 bytes of body data]
111-
```
112-
113-
Total size:
114-
- Request line: `POST /upload HTTP/1.1\r\n` = 24 bytes
115-
- Host header: `Host: example.com\r\n` = 19 bytes
116-
- Content-Length header: `Content-Length: 500\r\n` = 21 bytes
117-
- Header separator: `\r\n` = 2 bytes
118-
- Body: 500 bytes
119-
- **Total: 566 bytes**
120100

121101
## Use Cases
122102

0 commit comments

Comments
 (0)