-
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 6 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 a special case, what to do if the 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. | ||||||
|
|
||||||
|
|
||||||
| Under the PR [3483](https://github.com/owasp-modsecurity/ModSecurity/pull/3483) we discussed a lot about how could he make that better, and we are a bit stuck. | ||||||
airween marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
|
|
||||||
| 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 | ||||||
|
|
||||||
| I changed the engine a little to demonstrate the behavior - it always shows the size that exceeds the limit, and the limit itself. | ||||||
airween marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
|
|
||||||
| I think the first question is which constraint is "stronger", what the engine checks first. | ||||||
airween marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
|
|
||||||
| Consider we have a simple JSON file with length of 120 bytes: | ||||||
airween marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| ```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 restrictions to extremely low to see what happens if I send the above file: | ||||||
airween marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| ```apache | ||||||
| SecRequestBodyLimit 115 | ||||||
| SecRequestBodyNoFilesLimit 110 | ||||||
| ``` | ||||||
|
|
||||||
| The `NoFiles` limit is usually lower than the "single" one — we'll see why below. | ||||||
airween marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
|
|
||||||
| 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 limitation the engine checks is `SecRequestBodyLimit`. If the body is bigger than the configured value, the engine blocks the request immediately. | ||||||
airween marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
|
|
||||||
| Now set `SecRequestBodyLimit` higher than the body size and check again: | ||||||
airween marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
|
|
||||||
| ```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 limitations? | ||||||
airween marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
|
|
||||||
| The `SecRequestBodyLimit` controls the **entire request body size**, no matter what's the request's `Content-Type`. | ||||||
airween marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| 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
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.
I don't follow. SecRequestBodyLimitAction applies to all requests and, thus, already covers JSON, XML, and URL-encoded data. The new limit would simply make the actions symmetrical to the limits.
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.
In the blogpost I tried to explain the exact behavior of SecRequestBodyLimit and SecRequestBodyNoFilesLimit directives, and show the differences. As you can see there, SecRequestBodyNoFilesLimit is much lower in general, therefore the payloads reach that limit earlier.
But if the request size reaches this limit, the SecRequestBodyLimitAction won't have any effect, because it applied only if the SecRequestBodyLimit is reached.
It can be true that you mention if the two limits are equal, or NoFiles limit is higher.
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.