Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Make ModSecurity IIS work with SecStreamInBodyInspection option disabled to prevent memory leak #104

Merged
merged 3 commits into from
Mar 14, 2019

Conversation

vkrivopalov
Copy link

Description

There is a long-time known memory leak that occurs to requests blocked by ModSecurity when SecStreamInBodyInspection. The primary reason for keeping this option is that ModSecurity for IIS needs it turned on - see owasp-modsecurity#538 for details.

This is bad, however, because this flag causes a known memory leak: owasp-modsecurity#1316

We have earlier disabled this option for ModSecurity for Nginx but couldn't do so for IIS for it would break processing.
Now we can leverage the code implemented for processing requests in background for detection-only mode and not depend on SecStreamInBodyInspection being set any longer.

NB: there are some other memory leaks coming from other places even when body processing is disabled. They leak much less memory so are not addressed by this fix but should certainly be chased later.

Testing

I've been using requests with 128Kb body carrying randomly generated payload:

curl -X POST --data-binary '@payload.bin' "http://localhost:8081/?test=/etc/passwd" -o /dev/null -s -w "got HTTP %{http_code} after %{time_total}s\n"

Prevention mode, SecStreamInBodyInspection On


Before any requests: 5.3 Mb
After first request (config loaded): 22.6 Mb
After 100 more requests (101 overall): 36.6 Mb
After another 100 requests (201 overall): 49.1 Mb


Prevention mode, SecStreamInBodyInspection Off


Before any requests: 5.2 Mb
After first request (config loaded): 22.3 Mb
After 100 more requests (101 overall): 23.2 Mb
After another 100 requests (201 overall): 23.6 Mb

allanbomsft
allanbomsft previously approved these changes Mar 13, 2019
@vkrivopalov vkrivopalov requested a review from allanbomsft March 13, 2019 23:54
If we set EOS bucket to the brigade and assign this brigade to APR
request, it causes an error code returned from modsecProcessRequest().
This does not affect detection-only mode because we dismiss the code but
needs to be taken into account for prevention mode.

Signed-off-by: Vladimir Krivopalov <vlkrivop@microsoft.com>
Use the same helper that has been previously only called for
detection-only mode when prevention mode is enabled.

Signed-off-by: Vladimir Krivopalov <vlkrivop@microsoft.com>
Signed-off-by: Vladimir Krivopalov <vlkrivop@microsoft.com>
@vkrivopalov vkrivopalov force-pushed the vlkrivop/disable_stream_in_body_inspection branch from c58266f to 87bd3ad Compare March 13, 2019 23:56
@vkrivopalov vkrivopalov merged commit e1e5ce5 into v2/master Mar 14, 2019
@vkrivopalov vkrivopalov deleted the vlkrivop/disable_stream_in_body_inspection branch March 14, 2019 18:44
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants