-
Notifications
You must be signed in to change notification settings - Fork 1.7k
nginx reverse proxy strips response headers from backend #735
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
Comments
I am facing the same issue. The culprit commit seems to be this one: 177b5b9. |
I am also facing this problem. We are adding a custom header to the response on the backend-servers. But this never returns to the client. |
And one important header "Content-Type" is not passed - this breaks our applications... |
@zimmerle I have tried your fix, but with no luck... |
@scaarup, can you tell me the response headers with and without ModSecurity in play. |
@zimmerle, yes here they are, first with modsecurity and then without. It is actually only content-type which is missing. X-Server-Name and Jokum are custom header fields provided by the apache upstream. So something is working. HTTP/1.1 200 OK HTTP/1.1 200 OK |
I found inside of ngx_http_modsecurity.c, ngx_http_clean_header(r) is called, which deletes all of the output headers. Not sure why this is done, but commenting it out fixes the problem. static ngx_inline ngx_int_t
// WHY ARE HEADERS OUT BEING DELETED?
|
@scaarup, the fix was for ModSecurity + nginx. It won't impact your setup. @ZaleskiR, you can try the patch for ModSecurity Nginx module provided here to solve response headers problem. Commenting the ngx_http_clean_header() will work fine with DetectionOnly mode but with ModSecurity Engine ON, it would require this code to be there to sanitize the response. |
@rmongia I am using ModSecurity + nginx... |
that's interesting. i have tested the scenario with my setup and it seems to work. my setup is a simple recommended configuration with a few custom rules. i am not using OWASP rule set here. My guess is there is some rule which is doing this. You can investigate further by disabling all rules and running the same scenario again. |
Fixed by: #749. |
Hi @zimmerle Has this been included in a release? I've just compiled the latest version of Nginx (1.11.6) with Modsecurity (2.9.1). Nginx is acting as a reverse proxy for a Jetty server. I'm using the default OWASP rules (3.0.0). The Java app is adding headers to the response which are being stripped out by Modsecurity. It was fine before Modsecurity was added. Thanks in advance! |
Hi @davidgenn, Please use the `nginx_refactoring' branch. Or the ModSecurity-nginx connector: |
In a set up like this:
If the backend server adds a new response header, modsec doesn't pass it to the client.
This happens even if all the rules are disabled and
SecRuleEngine Off
is set. It seems anything new that is added by the backend will get dropped.We noticed this because we were trying to byte serve a PDF from the backend. Chrome uses range requests, but modsec drops the
Content-Range
header from the response, so it makes the client download the file forever.I set up a super tiny test environment with
nginx 1.6.0
andmodsec 2.8.0
and could recreate the issue there. Here is a gist with some logs and the configs. We also saw this in another similar set up which wasnginx 1.4.4
andmodsec 2.7.7
.I hope I didn't miss anything, please let me know if any more info is needed.
The text was updated successfully, but these errors were encountered: