-
Notifications
You must be signed in to change notification settings - Fork 5
docs: add request body limits explanation #138
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 8 commits
1605a3a
5366c75
67cfedd
5279ab7
5f05c51
ac5f5a9
bde6426
349eba7
7c95ecf
d52fbfe
f2ab782
93b8ea9
0d02745
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,257 @@ | ||||||
| --- | ||||||
| title: 'How Big Is Too Big? A Deep Dive into ModSecurity Request Body Limits' | ||||||
| date: '2026-02-22T00:00:00+02:00' | ||||||
| author: airween | ||||||
| --- | ||||||
|
|
||||||
| Have you ever wondered what exactly the request body limits mean in ModSecurity and how they work? | ||||||
|
|
||||||
| <!--more--> | ||||||
|
|
||||||
| As you probably know, ModSecurity has two limits on the size of the request body: [SecRequestBodyLimit](https://github.com/owasp-modsecurity/ModSecurity/wiki/Reference-Manual-(v2.x)#secrequestbodylimit) and [SecRequestBodyNoFilesLimit](https://github.com/owasp-modsecurity/ModSecurity/wiki/Reference-Manual-(v2.x)#secrequestbodynofileslimit). | ||||||
|
|
||||||
| There is also a handler for the case, when the request body size is larger than expected - [SecRequestBodyLimitAction](https://github.com/owasp-modsecurity/ModSecurity/wiki/Reference-Manual-(v2.x)#secrequestbodylimitaction). | ||||||
|
|
||||||
| Two new PRs (for [v3](https://github.com/owasp-modsecurity/ModSecurity/pull/3476) and for [v2](https://github.com/owasp-modsecurity/ModSecurity/pull/3483)) have recently appeared on GH, from Hiroaki Nakamura ([@hnakamur](https://github.com/hnakamur)), where he tried to improve the behavior of these limits. | ||||||
|
|
||||||
|
|
||||||
| We've had a long discussion ([3483](https://github.com/owasp-modsecurity/ModSecurity/pull/3483)) about how the current behaviour can be improved, and we are a bit stuck. | ||||||
|
|
||||||
| I think it would be good to know what the community's expectations are for this feature, but first, let me explain how these restrictions work in reality. | ||||||
|
|
||||||
| #### A really simple example | ||||||
|
|
||||||
| For the following, I've modified the engine a little to demonstrate the behaviour - it always shows the amount by which a limit has been exceeded, and the limit itself. | ||||||
|
|
||||||
| I think the first question to examine is which constraint is "stronger", i.e., which limit does the engine check first. | ||||||
|
|
||||||
| Consider a simple JSON file with a length of 120 bytes: | ||||||
| ```bash | ||||||
| $ cat payloadmin4.json | ||||||
| [1234567890123456,1234567890123456,1234567890123456,1234567890123456,1234567890123456,1234567890123456,1234567890123456] | ||||||
|
|
||||||
| $ ls -l payloadmin4.json | ||||||
| -rw-rw-r-- 1 airween airween 120 febr 15 19.45 payloadmin4.json | ||||||
| ``` | ||||||
|
|
||||||
| Now let's set the limits to very low values to see what happens when I send the above file: | ||||||
| ```apache | ||||||
| SecRequestBodyLimit 115 | ||||||
| SecRequestBodyNoFilesLimit 110 | ||||||
| ``` | ||||||
|
|
||||||
| `SecRequestBodyNoFilesLimit` limit is usually lower than `SecRequestBodyLimit` — we'll see why below. | ||||||
|
|
||||||
| Now let's send the request: | ||||||
| ```bash | ||||||
| $ curl -v -H "Content-Type: application/json" -X POST --data @payloadmin4.json http://localhost | ||||||
| ... | ||||||
| > POST / HTTP/1.1 | ||||||
| > Host: localhost | ||||||
| > User-Agent: curl/8.18.0 | ||||||
| > Accept: */* | ||||||
| > Content-Type: application/json | ||||||
| > Content-Length: 120 | ||||||
| ``` | ||||||
| and check the log: | ||||||
| ```bash | ||||||
| ModSecurity: Request body (Content-Length (120)) is larger than the configured limit (115). | ||||||
| ``` | ||||||
|
|
||||||
| As you can see, the first limit the engine checks is `SecRequestBodyLimit`. If the body is bigger than the configured value, the engine blocks the request immediately. | ||||||
|
|
||||||
| Now we'll set `SecRequestBodyLimit` higher than `SecRequestBodyNoFilesLimit` and check again: | ||||||
|
|
||||||
| ```apache | ||||||
| SecRequestBodyLimit 130 | ||||||
| SecRequestBodyNoFilesLimit 110 | ||||||
| ``` | ||||||
| Send the request again and check the log: | ||||||
| ```bash | ||||||
| ModSecurity: Request body no files data length (120) is larger than the configured limit (110). | ||||||
| ``` | ||||||
| Now the no-files limitation was exceeded — we set the limit to 110, but the payload is 120 bytes. | ||||||
|
|
||||||
| **Conclusion**: The first variable that the engine checks is the `SecRequestBodyLimit`, and the second one is the `SecRequestBodyNoFilesLimit`. | ||||||
|
|
||||||
| #### What's the difference between the two limits on the request body size? | ||||||
|
|
||||||
| The `SecRequestBodyLimit` controls the **entire request body size**, no matter what's the request's `Content-Type`. | ||||||
|
||||||
| The `SecRequestBodyLimit` controls the **entire request body size**, no matter what's the request's `Content-Type`. | |
| The `SecRequestBodyLimit` controls the **entire request body size**, regardless of the request's `Content-Type`. |
airween marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
airween marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
airween marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
airween marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
airween marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
airween marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
airween marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
airween marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
airween marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
airween marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
airween marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
airween marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
airween marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, so the actual problem is that you want to change the behavior of the limits in DetectionOnly mode.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, so the actual problem is that you want to change the behavior of the limits in
DetectionOnlymode.
Behavior of the SecRequestBodyNoFilesLimit. It does not covered yet.
Indeed it can be dangerous if someone use the engine not in DetectionOnly mode (also explained in the blog post).
Uh oh!
There was an error while loading. Please reload this page.