-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
REQUEST_BODY_LENGTH is only available in phase 3, causing rule execution issues in earlier phases #3346
Comments
Hi @Ablfantastic, thanks for reporting this. Could you explain some details about your environment? Eg. library version, etc... And please take a look at the issue template, where we ask these information: ...
**Server (please complete the following information):**
- ModSecurity version (and connector): [e.g. ModSecurity v3.0.8 with nginx-connector v1.0.3]
- WebServer: [e.g. nginx-1.18.0]
- OS (and distro): [e.g. Linux, archlinux] Anyway, I think this is important because I'm not able to reproduce your issue. I checked the explained behavior with these rules:
and did that on mod_security2 and libmodsecurity3 (3.0.14) and Nginx (1.26.3) on Debian SID. This is what I see in logs:
Just for the record: here are the lines from Apache's log:
As you can see, the value is available in phase:2 in both engines.
Yes, this would be a very problematic, if the mentioned variable appeared in phase:3. But I think I see what's the problem here. As I understand, you want to exclude rule I assume the problem is this. Could you confirm it? The solution could be if you add your exclusion before the rule that you want to exclude. (I have to tell you I don't see the reason why do you want to ignore rule |
@Ablfantastic any news? Could you check my suspicion above? |
I have updated the issue I mentioned above with the correct system specifications. I wanted to ignore rule 200002 when the request body is valid but exceeds the I will investigate the issue further and report back once I reach a more solid conclusion. Thank you very much, Abel |
Hi @airween, I've used your solution to remove the rule in the cases where I needed it. Thank you for your feedback! |
REQUEST_BODY_LENGTH is only available in phase 3, causing rule execution issues in earlier phases
Describe the bug
REQUEST_BODY_LENGTH is only available in phase 3, but certain security rules (e.g., request body validation) execute in phase 2. This timing issue makes it impossible to properly use REQUEST_BODY_LENGTH to control rule execution before request body validation occurs. This prevents rules from being dynamically disabled or modified based on body size before enforcement.
Logs and dumps
To Reproduce
Steps to reproduce:
Set a rule that attempts to remove another rule based on REQUEST_BODY_LENGTH:
SecRule REQUEST_BODY_LENGTH "@gt 100" "id:10019,phase:1,nolog,pass,ctl:ruleRemoveById=200002"
Observe that REQUEST_BODY_LENGTH is only assigned a value in phase 3.
A rule like 200002 (executing in phase 2) cannot be dynamically removed based on body size, as the value is not available yet.
This issue is problematic for setups where large request bodies need to be conditionally exempt from strict ModSecurity enforcement. If REQUEST_BODY_LENGTH remains unavailable in phase 1 or 2, certain security mechanisms will always trigger before exclusions can be applied.
Would it be possible to make REQUEST_BODY_LENGTH accessible earlier in the request processing cycle?
Server:
Rule Set (please complete the following information):
The text was updated successfully, but these errors were encountered: