Open vizovitin opened 1 week ago
Hi @vizovitin,
thanks for provided info. We try to investigate the root cause soon, but probably the given patch would be enough at first.
@marcstern what do you think?
JFYI: There might be a few other places in the same file with similar issue, but since I'm not acquainted with the code and they don't seem to trigger any issues, I chose to keep the patch to a minimum (i.e. patch only one usage).
I wonder if the cause is not that modsecurity_request_body_end_raw() is called with a body that's not chunked-encoded. Why is it called inside modsecurity_request_body_end_urlencoded(), thus when body is url-encoded, and not when multipart-encoding is used? Shouldn't we solve the problem at a higher level (and add assert() all over the place)?
@vizovitin: can you show us an example of problematic request?
Unfortunately, I don't think I can. It is from a production server I don't control. The request itself is rather large and includes various authentication and other potentially private data.
If you need to check something specific I may still be able to check it.
Can we have the request headers (you can remove any specific one, like cookies)?
Sure. I've redacted some stuff (mostly marked as REDACTED
). Also POST data is a lot larger. I've also changed the domain address.
curl 'https://abcde.example.net/wp-json/wplms/v2/create/13377?post' \
-H 'accept: */*' \
-H 'accept-language: en-US,en;q=0.9' \
-H 'content-type: text/plain;charset=UTF-8' \
-H 'cookie: wordpress_test_cookie=WP%20Cookie%20check; wp_lang=en_US; other_cookies=REDACTED' \
-H 'origin: https://abcde.example.net' \
-H 'priority: u=1, i' \
-H 'referer: https://abcde.example.net/' \
-H 'sec-ch-ua: "Not/A)Brand";v="8", "Chromium";v="123", "Google Chrome";v="123"' \
-H 'sec-ch-ua-mobile: ?0' \
-H 'sec-ch-ua-platform: "Windows"' \
-H 'sec-fetch-dest: empty' \
-H 'sec-fetch-mode: cors' \
-H 'sec-fetch-site: same-origin' \
-H 'user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/512.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/512.36' \
--data-raw '{"course":"REDACTED","object":["REDACTED"],"token":"REDACTED","course_id":13377}'
Can we have the headers "Content-Type" and "Transfer-Encoding" from the original request?
Content-Type is listed above. There was no Transfer-Encoding, apparently.
Sorry, I meant Content-Length. As there was no Transfer-Encoding, I assume Content-Length was present. Can you check with curl -v? Also, what are the values of SecRequestBodyLimitAction, SecRequestBodyLimit, SecRequestBodyNoFilesLimit in your config? Is the body bigger than SecRequestBodyLimit/SecRequestBodyNoFilesLimit?
I just copied the request data from a browser developer console. So if the header is not there - I suppose it wasn't present.
There are no specified directives in the configuration:
# egrep -R '^\s*SecRequestBody' /etc/apache2/
/etc/apache2/plesk.conf.d/server.conf: SecRequestBodyAccess Off
/etc/apache2/plesk.conf.d/server.conf.bak: SecRequestBodyAccess Off
/etc/apache2/conf-available/modsec2.imunify.conf: SecRequestBodyAccess On
/etc/apache2/conf-enabled/zz999_modsec2.imunify.conf: SecRequestBodyAccess On
Can you check with curl -v?
content-length: 70888
You can also see above in the issue, which might be useful:
(gdb) print msr->msc_reqbody_length
$5 = 128070
Describe the bug
Segmentation fault in ModSecurity 2.9.7 for Apache on very specific POST requests.
Logs and dumps
I cannot provide full core dump or request parameters due to potential inclusion of information from a production server. However, here's the stack trace:
To Reproduce
N/A
Reproduced only on production server with very specific steps in a very customized WordPress. ModSecurity for Apache, blocking, with Comodo (free) ruleset, in Fast mode, with 210710 and 222212 security rule IDs switched off.
Actual behavior
Request fails with 502 Bad Gateway served by nginx (reverse proxy before Apache). In the backend the following is logged:
Expected behavior
Apache children should not crash due to ModSecurity.
Server (please complete the following information):
Rule Set (please complete the following information):
Additional context
Unfortunately, I cannot test the issue on 2.9.8 (as it is production server I don't own).
The following patch alleviates the issue, although it is most certainly "incorrect":