coreruleset: False positive when charset=utf-8\x0d\x0a in content-type header
Hello CRS team,
some actions in my mobile application are triggering this rule and block request. I didnt set in APP charset=utf-8\x0d\x0a,
so maybe its coming from android.
When I exclude this rule SecRuleRemoveById 922110
then its fine, but I want to exclude it for everything
and could not figure out any exception:
I tried this:
tx.allowed_request_content_type_charset=|utf-8| |utf-8\x0d\x0a| |iso-8859-1| |iso-8859-15| |windows-1252|'
and also this:
SecRule REQUEST_HEADERS:Content-Type "text/plain; charset=utf-8\x0d\x0a" \
"phase:1,nolog,pass,id:6,t:none,ctl:ruleRemoveById=922110"
I checked 922110 rule and it cant match above with regex defined there. Anyone can help me to understand this issue please ?
Many thanks
ModSecurity: Warning. Matched "Operator `Rx' with parameter `^(?:(?:\*|[^\"(),\/:;<=>?![\x5c\]{}]+)\/(?:\*|[^\"(),\/:;<=>?![\x5c\]{}]+))(?:\s*+;\s*+(?:(?:charset\s*+=\s*+(?:\"?(?:iso-8859-15?|windows-1252|utf-8)\b\"?))|(?:(?:c(?:h(?:a(?:r(?:s(?:e[^t\"(),\/:;<=> (714 characters omitted)' against variable `TX:1' (Value: `text/plain; charset=utf-8\x0d\x0a' ) [file "/usr/local/coreruleset-3.3.4/rules/REQUEST-922-MULTIPART-ATTACK.conf"] [line "51"] [id "922110"] [rev ""] [msg "Illegal MIME Multipart Header content-type: charset parameter"] [data "Matched Data: text/plain; charset=utf-8\x0d\x0a found within Content-Type multipart form"] [severity "2"] [ver "OWASP_CRS/3.3.4"] [maturity "0"] [accuracy "0"] [tag "application-multi"] [tag "language-multi"] [tag "platform-multi"] [tag "attack-protocol"] [tag "OWASP_CRS"] [tag "capec/272/220"] [tag "paranoia-level/1"] [hostname "10.151.0.2"] [uri "/something.json"] [unique_id "167059009818.061175"] [ref "o0,41o14,27v974,41t:lowercaset:lowercase"],
- CRS version: 3.3.4
- Paranoia level setting:1
- ModSecurity version: 3.0.8
- Web Server and version: nginx
- Operating System and version: alpine
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 40 (24 by maintainers)
I try to find the bug and send a PR to fix it. If do not have time, I just open an issue.
It definitely looks like an illegal request to me.
\r\n
is the separation token for headers, so if it show up in the value then there are either more than there should be or they have been badly encoded. Do you have the ability to inspect the HTTP traffic, e.g. withtcpdump
or Wireshark?Just FYI: the sent patch above for libmodsecurity3 has been merged.
Thank you everyone for finding solution to this. Really appreciate
Thank you for your patience.
Looks like libmodsecurity3 handles buggy the multipart content types (too?), because it keeps the trailing white space chars, namely
\r
and\n
in our case.What can you do now?
I’ve found a workaround, this patch worked for me:
so added the
t:removeWhiteSpace
transformation solved the problem, and rule 922110 didn’t trigger.(ping @fzipi as author of the rule: what do you think? Does it make sense to add this permanently?)
If you want to avoid the unwanted other
REQUEST_BODY
matches, you can add something similar:@mikegoatly - thanks.
I was able to reproduce the issue on Nginx + libmodsecurty3 3.0.8 and CRS 3.3.4.
Let me investigate the reasons, why happens this (and why does not with Apache).
ingress-nginx
should be a container image, right? If you can get hold of the image, or the definition, you should be able to find out.@mikegoatly, I tried to reproduce your issue, also with your suggested way (REST client for VSCode - thanks for the tip), but no luck.
now I made a small Python script which sends the raw format of your request, you can see that here. First, please check that, and let me know if there is something not well.
Then could you try it against your application? (I see you use HTTPS, but actually in my dev env I do not have any HTTPS, and it’s more convenient to try the raw requests like this without HTTPS).
This is what I see when I run the script:
and this is what I see in my log:
or with Nginx+libmodsecurity3:
So as you can see there is only one rule triggered in phase 2 with id 200002 (with both implementations):
and
I’m using CRS with Apache 2.9.7, and Nginx 1.18 and libmodsecurity3 3.0.8.
Could you check that script with your application, and align it to reproduce the issue?
@theseion thanks a lot for a hint. I’ve been all the time using phase 1, but in this case it has to be phase:2 as it is already part of the body. Now exception works well 😃
@theseion working on it, hopefully will get data soon