-
Notifications
You must be signed in to change notification settings - Fork 283
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
Modsec can OOM nginx in a container with large response bodies #115
Comments
Hi @jimbobhickville, Have you tried tuning SecResponseBodyLimit and related directives to see if it makes a difference? |
I can try tomorrow, but the docs said the default was 512K, and I'm talking about hundreds of megabytes or gigabytes of memory being used. So either the docs are wrong or that setting is also not being obeyed. |
This is also an |
Well, I'll be darned, adding:
Fixed it. So there's a bug still in that it's not obeying the defaults on those settings and it's ignoring the whole |
Hi @jimbobhickville, We appreciate the feedback :) This is interesting. Afaik, SecResponseBodyAccess off should be enough to not buffer output body. You've mentioned you're running the latest codebase of ModSecurity (and the connector) right? (Just to be on the safe side, can you confirm you also have #1643 patch on your codebase?) There is a known issue with Response Body processing discussed at #84 which might be related with the issue you're facing that's worth having a look. Also, I've just noticed this comment on ModSecurity-nginx which I'm wondering if it might explain the issue still persisting even with SecResponseBodyAccess disabled. Anyways, as there might be a bug there indeed I'm tagging this one properly and leaving it open for now until we have more time to look into it. |
The default values are not actually part of the code, but in the recommended configuration: In the config we can find:
Without it, there is no limit. |
ModSecurity-nginx v1.0.3 (rules loaded inline/local/remote: 0/0/0) I ran my app in container |
Hello @astrcomp , Your question is a little different from what this closed issue was dealing with. In any case, I'm not sure I have a good suggestion for you. If you are retaining the uploaded files via SecUploadKeepFiles, the code basically assumes that you want to examine the content with FILES_TMP_CONTENT -- which means reading the content into memory. It seems likely that you're hitting your memory limit. There are some options, but whether they might work for you would depend on what your needs are. For example:
As I said, it depends on what your current configuration is and what your needs are. But those are a couple of possibilities anyway. |
I have the latest version of nginx, modsecurity, and modsecurity-nginx built in a containerized environment. It seems that modsecurity is buffering responses in memory even when looking at responses is disabled (i.e.
SecResponseBodyAccess Off
), causing the nginx container to be killed by the OS (Memory cgroup out of memory: Kill process 2553 (nginx) score 1990 or sacrifice child
).If I reconfigure nginx with
modsecurity off
I'm able to download the large file without running out of memory, so it's not nginx itself that's the culprit here.Steps to reproduce:
I should note that I was hitting a similar issue with the statically-compiled version of nginx+modsec, but it would OOM before the download even started. I had hoped that this dynamic module would behave better. It does, in some sense, in that it will start to download, but it still OOMs after the amount downloaded exceeds the memory limit.
I'm happy to help debug this issue further as it's breaking websites that we host, but I'm not much of a C programmer, so I could use some pointers on how to go about helping.
The text was updated successfully, but these errors were encountered: