Closed gridpane closed 4 years ago
Hello @gridpane ,
One thing to note is that the fastcgi_param called REMOTE_ADDR is not the same as the ModSecurity variable REMOTE_ADDR. They happen to have the same name but they don't refer to the same set of bytes, nor is one sourced from the other.
I don't believe there is any way to reassign the value of ModSecurity's REMOTE_ADDR.
What you can do is, if the real ip is supplied in a request header, set a custom variable to hold that value and then do any ip-address-related rule functionality using that variable.
There's a slightly longer discussion of the general idea in https://github.com/SpiderLabs/ModSecurity/issues/1620
Thanks Martin
We are running ModSec behind an Nginx Reverse Proxy, but not Nginx -> Apache.
We have Nginx up front as a caching reverse proxy, and we are passing back to an Nginx FastCGI/PHP-FPM Backend.
ModSec sits on the back, guarding the dynamic requests only. In general its turned out to be an excellent solution, inspired from Trustwaves performance recommendations but without needing to involve anything else in the stack, rather its just an interesting Nginx configuration. https://www.trustwave.com/en-us/resources/blogs/spiderlabs-blog/modsecurity-performance-recommendations/
Any cached requests fly, with only dynamic requests suffering from the ModSec weight.
However... the inability to access and rewrite
REMOTE_ADDR
in the back is problematic.Basic config:
So the problem is that when an event happens, its logged as the localhost
127.0.0.1
This is not so much of a big deal, as i can target rule exceptions using the ID and things like headers, or setting cookie values:
But... modsec sees everything as 127.0.0.1 - this is the source IP - the REMOTE_ADDR.
Now I can rewrite this for PHP functions quite easily using the fastcgi_param directive. I can set this in values up front even and pass back through, variety of ways one for example:
So using a test.php file
I can output things and see that as far as PHP processing is concerned I have managed to rewrite the REMOTE_ADDR value back to the real IP... however doing this with fastcgi_params is all post Modsec.
It seems ModSec runs phase earlier. Is there anyway to rewrite this prior to ModSec accessing the value?
The real issue is having to set the DOS functions to deal with the fact that ModSec sees every single request as coming from the same IP.
Am I missing something, is there a reason that ModSec can't access these values after fastcgi_params has adjusted them?