-
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
Parsing error when submitting file with an apostrophe (') in filename #2352
Comments
Hi @studersi , Since you're using a fairly old ModSecurity (v3.0.0), I would suggest upgrading to a more recent version like v3.0.4. I'm fairly sure that the issue you describe does not exist there -- or in the previous version (v3.0.3) for that matter. |
Thank you for your reply! I just confirmed it with the following versions:
The behaviour is the same:
|
Ah, ok, my mistake. You're hitting the multipart strict check (rule 200003) -- specifically triggered by the invalid quoting condition ('IQ 1'). The condition you're hitting shouldn't hamper parsing of the remainder of the request body (at least not in 3.0.4), so you could probably just turn off the rule detection of this condition. One way to do this is to just remove/comment-out rule 200003. A generally safer approach is to remove 200003, but replace it with rules that check for each of the individual conditions except for the one(s) that are causing you well-understood false positives. A member of the community has posted a sample of this approach near the bottom of this issue: #2267 |
Indeed but this appears to be more of a workaround for an underlying problem. I do not see why an apostrophe should trigger unmatched quotation error. Correct me if I am wrong but it appears to me that according to Section 4.1 of RFC 6266 the apostrophe should be a perfectly normal character in the filename-parm value as defined in Section 3.6 RFC 2616 and Section 2.2 RFC 2616. So it should not be flagged as a violation during parsing. |
Hi @studersi , ' ... more of a workaround ... ' It sure is. As a general note, the individual conditions tested within MULTIPART_STRICT_ERROR are not all violations of the standard. By design, they test things that may indeed be perfectly RFC-compliant. But these same things are (or at least were historically) uncommon/unexpected, and hence might be indicators of suspicious activity. It's certainly appropriate to reassess the MULTIPART_STRICT_ERROR conditions to see whether adjustments ought to be made. Input from the community on what false positives are causing a nuisance is useful to such reassessment, so thanks for raising your case. |
I have looked into this a bit more, so by way of update ... First, I'll agree that it would be nice to loosen this restriction somewhat if possible. Even in English, use cases for a single quote (particularly when used as an apostrophe) are not trivially rare -- particularly when using certain proper names (e.g. filename="o'toole.txt") And this can be even more common in other languages where apostrophe usage is more frequent -- either in the native language, or as a consequence of transliteration from non-Roman alphabets. I have identified when and why this more restrictive form of 'invalid quoting' checking was introduced. It was back in 2013, and it was done quite intentionally to avoid a possible bypass related to how php performs multipart parsing (#460) . I have examined the php code (only briefly thus far), and I suspect that we can loosen this detection in cases where the entire value is enclosed in double-quotes. But further work would be required to confirm that we would not be inadvertently re-introducing a security bypass. |
If refusing single quotes is a security feature, I think it's a mistake. this should be implemented by a rule, so it can be managed correctly. |
That's (mostly/sort of) exactly what happens now. The presence of a single quote within the value does not halt parsing. Any block of the transaction will occur as a result of a rule that checks either MULTIPART_STRICT_ERROR ( as rule 200003 in modsecurity.conf-recommended does) or a more specific check for the value of MULTIPART_INVALID_QUOTING). In other words this already can be managed by rule adjustment. Having said that, I did consider the possibility of removing the check for this use case from the parser. There are some points in favour of that possibility:
On the other hand there are some arguments against:
|
We can check that with a chained rule |
By which I guess you mean, the first rule in the chain checks that the overall Content-Type was indeed multipart (or more likely checking REQBODY_PROCESSOR) and then the second rule in the chain checks for single-quote chars. That's fair. But then a separate rule is needed to also check filename content, for example. I'm still not completely sold that this approach would overall yield a cleaner solution. Worth thinking about though. |
That's the goal of the FILES_NAMES collection |
I didn't mean that a second chained rule pair comparable to the first one was required. Merely that an additional rule would be needed. |
And it's normal to use an additional rule to perform a separate functional check ;-) |
I have a situation where a form submitting to PHP has |
Hi @andrewroazen , Please see the earlier comment in this thread #2352 (comment) . Yes, the check was made more stringent due to idiosyncrasies -- and hence potential evasions -- due to PHP's parsing. The reason this ticket is still open is because the current behaviour is indeed inconvenient and probably unnecessarily restrictive. In the meantime, a workaround available to you is to exclude IQ from your rule tests. |
Where's the documentation as to how this is done, I commented out some lines and restarted httpd but the errors still occur on filenames with |
There is no recompilation involved. The detection in question happens because of rules, so the way to turn 'off' this detection is to modify your rules. Have you had a look at discussion in #2267 ? (This was referenced earlier in this issue -- in the July 7 comment). That goes over some options. |
I have recently both:
... and I'm fairly confident that there is no risk with loosening this restriction, at least to the extent of my comment on Dec. 2. Specifically, if the entire value is within double-quotes, then the presence of single-quote characters within the value should not trigger the IQ condition. I'll plan to put together a pull request sometime within the next couple of weeks. |
Just FYI I had a look at the proposed solution in #2267 but this supposes you have direct access to the .conf file. As I am adding/removing the rules through annotations in my ingress the syntax didnt work. Specifically it did not like single quotes within double quotes. So for example, the following fails with a parsing error:
and
is accepted and works to re-enable a single rule after removing the block (200003). This removes single quotes from around the id: value and swaps single quotes to backticks for the msg: content. |
Hello @willc-work , (Note that I will be closing this issue shortly since a software change to address it is already available in v2, and is expected to shortly be likewise in v3. But given what you've written, I'll assume that you cannot independently upgrade your code.) First, I'm not really sure what you mean by your 'ingress'. If you are using some other software to manage ModSecurity configuration, you might want to consult documentation for that other software. It's quite possible that there is some useful notes there -- perhaps using backslash-escaping? But, If you really cannot use single quotes for rule updates in your situation one option could be to just not use them. For the specification of "id:", I'm not aware of any situations where the single quotes are required. You can simply specify (as you did in your second example): id:200011. Avoiding single quotes entirely may mean abandoning use of the 'msg' action. This would be quite disadvantageous if using something that is the equivalent of 200003 because it is desirable to know which of the variables within MULTIPART_STRICT_ERROR was flagged. However if you are using the style of one rule per individual variable as in the example here: ... then one could argue there is limited value in including the msg at all, since you can tell by the Rule id number reported which specific condition was hit. Alternatively, if you really do think you need a more human-readable message, you still use the msg action, but with a message that avoids creating the need for single quotes -- for example by avoiding whitespace characters:
In fact, you may even be able to leave spaces intact. Try experimenting. |
Describe the bug
When submitting a file with an apostrophe (') in the filename, ModSecurity fails to parse the request body causing the ModSecurity Recommended Rules to deny the request.
Logs and dumps
To Reproduce
curl -F "filename=@its_a_test.txt" localhost
curl -F "filename=@it's_a_test.txt" localhost
Expected behavior
See working request above. ModSec should not intervene.
Server (please complete the following information):
Rule Set (please complete the following information):
Using minimal configuration:
The text was updated successfully, but these errors were encountered: