-
Notifications
You must be signed in to change notification settings - Fork 728
Remove MIME Attribute from application/soap+xml Rule 900220 #1717
Conversation
Thanks for this PR @rsbrisci. It is a different approach than I had prepared in my PR. So your approach in this PR is easier. But it's also less strict! But ok for me. Other opinions welcome. You only changed the variable tx.allowed_request_content_type in the commented out part in crs-setup.conf.example. This has not effect. Could you please also change it in the https://github.com/SpiderLabs/owasp-modsecurity-crs/blob/v3.3/dev/rules/REQUEST-901-INITIALIZATION.conf#L171 where the variable is actually set. Please also update the default comment in crs-setup.conf.example: https://github.com/SpiderLabs/owasp-modsecurity-crs/blob/v3.3/dev/crs-setup.conf.example#L392 And could you please also add a regression test for the
|
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.
See comment: #1717 (comment)
Personally I think we should be using strict matching here, relaxing a rule that is meant to restrict what Content-Types are allowed doesn't ring right to me. Also, I just realised that rule 920420 should be using parenthesis around the pattern, otherwise things such as |
Yeah, I was also thinking of that! The problem we are trying to resolve is to get the But that means that I will pursue my PR with the @\within, solve my false negative and push my PR asap. After that we can close this PR. |
I think that'd be best but may I suggest using @\pm instead? |
Yeah without this change I believe my colleagues PR would make the most sense because as the rule stands now you can add -whatever or +whatever to any of these common Content-Types. If going more strict about it, then Word of warning about being strict though, think about all those attributes: also what about the case of charsets set in the Content-Type ? aka |
@fgsch @franbuehler wow! I love how active your community is. I kinda figured you'd want to go with strict matching - and I agree, that's probably a better approach. My colleague @jeremyjpj0916 called it yesterday, but I thought "ahh heck, might as well try". This is especially true considering I don't think the Type/Subtype |
I could be wrong @jeremyjpj0916 - but I think HTTP1.1 treats charsets a lot like ports. edit: And/also isn't there a separate rule which already validates charsets? I think I've helped a customer troubleshoot that already :P |
Ahh I bet under the hood when |
Pretty sure that's how it works - the experts can confirm. Bringing us back to the topic at hand, I'm not sure this PR is the right path forward. Strict validation seems to be the way to go
I'd be happy to try my hand at a strict validation PR if you give me some hints to get started @fgsch @franbuehler , though my capacity to test on apache will be limited. |
Actually forget about this. @\pm will do partial matching. |
Charset is handled in another rule, correct. As for working on this, as she wrote above @franbuehler is working on a PR so you might want to coordinate with her. |
I changed the var This works very well for Apache. The regression tests work, even my new regression tests that I added. But again, it does not work for NGINX. "Doesn't work" means, the rules are loaded, no error, but the requests are not blocked. No bad content-types are blocked. I'm a bit lost and I'm losing patience... I will return to this PR/problem later. Maybe someone else has a suggestion/idea? Or we just shorten the value to application/soap like this PR suggests...? As a reminder: The problem is, that the value Problem description from slack channel: Did you ever stumble over this FP on NGINX only??
The variable in rule 901162 has to be |
I can confirm partially this bug - the only note is that it's not Nginx issue, but the v3. I've made a regression test for v3, and when I changed the In your solution you try to match the transaction variable with regex:
but this is a known bug in v3: the regex's are case sensitive everywhere, including transaction variables. (As the documentation says these are case insensitive.) You can use the form with lowercase:
(IMHO this is the preferred), or put a modifier:
See the issue #1741 and PR #1745. ModSecurity 3 also has a PR (2297 at there) which fixes this bug. Hope this helps. |
Note, that I checked your modifications with
|
Wow, thanks a loooot, @airween !!!! I'm so glad you checked my changes and that you found a solution! I'll change the var to lowercase and propose a PR then! |
Just one more note: is it necessary to add a concatenated TX variable, and match it as regex? I mean this solution is more clear, and I think it works as well too: diff --git a/rules/REQUEST-920-PROTOCOL-ENFORCEMENT.conf b/rules/REQUEST-920-PROTOCOL-ENFORCEMENT.conf
index 5098498..e7b9d81 100644
--- a/rules/REQUEST-920-PROTOCOL-ENFORCEMENT.conf
+++ b/rules/REQUEST-920-PROTOCOL-ENFORCEMENT.conf
@@ -964,9 +964,9 @@ SecRule REQUEST_HEADERS:Content-Type "@rx ^[^;\s]+" \
tag:'PCI/12.1',\
ver:'OWASP_CRS/3.2.0',\
severity:'CRITICAL',\
- setvar:'tx.content_type_%{tx.0}=|%{tx.0}|',\
+ setvar:'tx.content_type=|%{tx.0}|',\
chain"
- SecRule TX:/^CONTENT_TYPE_/ "!@within %{tx.allowed_request_content_type}" \
+ SecRule TX:content_type "!@within %{tx.allowed_request_content_type}" \
"setvar:'tx.anomaly_score_pl1=+%{tx.critical_anomaly_score}'"
(I'm still on your branch, the diff comes from there.) Also a small note, but I think you have to change the diff --git a/rules/REQUEST-903.9003-NEXTCLOUD-EXCLUSION-RULES.conf b/rules/REQUEST-903.9003-NEXTCLOUD-EXCLUSION-RULES.conf
index e1dca51..01b2a3e 100644
--- a/rules/REQUEST-903.9003-NEXTCLOUD-EXCLUSION-RULES.conf
+++ b/rules/REQUEST-903.9003-NEXTCLOUD-EXCLUSION-RULES.conf
@@ -98,7 +98,7 @@ SecRule REQUEST_FILENAME "@contains /remote.php/dav/files/" \
pass,\
t:none,\
nolog,\
- setvar:'tx.allowed_request_content_type=%{tx.allowed_request_content_type}|text/vcard'"
+ setvar:'tx.allowed_request_content_type=%{tx.allowed_request_content_type} |text/vcard'"
# Allow the data type 'application/octet-stream'
@@ -110,7 +110,7 @@ SecRule REQUEST_METHOD "@rx ^(?:PUT|MOVE)$" \
nolog,\
chain"
SecRule REQUEST_FILENAME "@rx /remote\.php/dav/(?:files|uploads)/" \
- "setvar:'tx.allowed_request_content_type=%{tx.allowed_request_content_type}|application/octet-stream'"
+ "setvar:'tx.allowed_request_content_type=%{tx.allowed_request_content_type} |application/octet-stream'"
# Allow data types like video/mp4
@@ -260,7 +260,7 @@ SecRule REQUEST_FILENAME "@contains /remote.php/dav/addressbooks/" \
pass,\
t:none,\
nolog,\
- setvar:'tx.allowed_request_content_type=%{tx.allowed_request_content_type}|text/vcard'"
+ setvar:'tx.allowed_request_content_type=%{tx.allowed_request_content_type} |text/vcard'"
# [ Calendar ]
@@ -273,7 +273,7 @@ SecRule REQUEST_FILENAME "@contains /remote.php/dav/calendars/" \
pass,\
t:none,\
nolog,\
- setvar:'tx.allowed_request_content_type=%{tx.allowed_request_content_type}|text/calendar'"
+ setvar:'tx.allowed_request_content_type=%{tx.allowed_request_content_type} |text/calendar'"
# [ Notes ] What do you think? |
Oh, yes, absolutely! You're right. I will change that! |
The current logic only validates Mime Type (
application
) and Sub-Type (soap
).The Mime Attribute in
application/soap+xml
prevents the following Content-Types from matching:application/soap
application/soap+xml
Whereas the value
application/soap
will allow both:application/soap
application/soap+xml