-
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
Custom error page not shown when ModSecurity found something. #76
Comments
Hello, logging actions are performed in the Let's say we defining the custom error page like this:
In this case after ModSecurity found something the request will be redirected to our custom page. Error page will be shown correctly. But there are no audit log entries because |
Hi @LeeShan87, I'm trying to fix this problem here #90. Could you apply this patch and check changes in you case? |
@AirisX - Following the compilation recipe for CentOS 7 here: And using the altered src/ngx_http_modsecurity_module.c file suggested in your patch, I am unable to compile nginx.
Are the errors generated, happy to help test this patch for you as I'm interested in having custom error pages too, let me know if there are any updates to this :) Thanks, |
Hi @met3or, Are you sure that proposed patch applied correctly? For example you have undeclared directive Thank you! |
Hi @AirisX - I'll copy the file across so I'm using the exact one, I'll try another time and feedback :) Thanks for getting back in touch! |
Hi @AirisX - Apologies for my hasty attempt earlier, using the correct patch I am able to successfully log a ModSecurity rule whilst also displaying the custom error page. Looks good so far! 👍 |
Hi @AirisX - Just to confirm that I'm able to get this working as I had expected however, when running modsecurity outside of the location block in the configuration the custom defined error page does not display. I feel this is worth mentioning. Otherwise experiencing great results! |
@met3or could you provide your config here? |
Hi @met3or, In order to resolve this problem you need to set
The problem is that if ModSecurity is enabled in the server context, all of its locations inherit these settings. When ModSecurity will finds something nasty and thrown 403 response, the internal redirection mechanism will redirects this response to a location with a custom error page. Since this location also includes ModSecurity, the custom error page is not displayed. The request is checked again (as you can see in audit log entries). Of course, this is not the expected behavior. To change this you should disable ModSecurity at a location that contains custom error page. |
Maybe recursive_error_pages would change the inheritance behaviour as suggested at owasp-modsecurity/ModSecurity#1672 (comment) |
@victorhora recursive_error_pages do not change the inheritance behaviour in this case. |
Hi guys,
So now, when ModSecurity throws 403 and the internal redirect happens, the rules don't run and a custom page is shown. Any better way to skip the rules than mentioned above? |
Sorry, my bad. Jumped to conclusion too early. The issue persists, the original audit log still does not appear. It was the audit log by skipAfter rules that was passing the test cases. :( |
I've tried using rules similar to those described in your post, and whilst they achieve what I want (the custom error page displays) I seem to lose the reason for the 403 in the logs. Has anyone managed to find a suitable workaround to this? |
Any news on this? I do not want to lose audit logs. |
So far it has been either audit log or the custom error page - I sacrificed custom error page for audit logging. Would be great to have both though |
I fixed it by storing my blocked page in my asset directory, and turning off modsecurity there. |
@hazcod |
@msamad Have you got the good idea to solve this problem, what you just comment is like |
@meigea #76 (comment) was me jumping to conclusion too early. See #76 (comment) right after that. |
I tried it like this , i move the
|
@msamad i tried it like i just comment and it work well. you can test and have a try. my venv
|
@meigea thanks for that, I'll give it a try. |
@meigea tried your configuration and it doesn't work - I lose modsecurity audit log. Are you sure you are not seeing info/debug logs instead of audit log. https://www.nginx.com/blog/modsecurity-logging-and-debugging/ |
@msamad i'm sorry. it's also no use. i see the log is that produced long ago. for log we can only do it that set the sorry not to help ... i wait for your options . i have seen the debug log but log is so many that i can't find the line that save auditlog in |
Hi all! After almost a year since I opened this issue it is still opened. I found a suitable workaround, but as a developer I wouldn't accept it as an answer. The simple answer, if you want to have auditlog with custom error page (and with ModSecurity CRS) all built and released with the current upstream you cannot achieve it. Same goes for mirroring. :( The basic issue is (my opinion) modsecurity configuration belongs to a location. So if you DENY a request it will be blocked. But error page and mirror location... well it's a different location. Your request will not get to it. (Ok you caught me cheating. But this way it's easier to present the issue.) So what is my workaround? I don't deny requests. I just REDIRECT them. How it can be achived? (first point why I not recommend this solution)
The second part in your nginx.conf (second part I don't recommend)
This type of configuration workaround currently working on nearly 800 production servers. How does this workaround looks like a security point of view? When ModSecurity triggers the attacker will receive HTTP 302 response code with the location of the error page. It will be logged and this is what matters for a SecOps/Ops. After this point it's up to the attacker to follow the redirection or not. If it follows the custom error page will be presented and the currently active keep alive connection will be terminated. Don't forget libmodsecurity is still in childhood. We have to be cleaver and contribute in this great product. PS.: @victorhora could you review this? |
I was trying to reproduce the scenario presented here but I'm not too sure if I got it right. I could not reproduce the scenario where audit logs are lost with the latest code from both libModSecurity and the nginx-connector. Could someone please provide a minimalist nginx/ModSecurity configuration that presents this behaviour? Thanks :) |
Sorry @LeeShan87, I didn't see your comment prior to mine :) So from your comment, I'm assuming the issue still persists with the latest code of libModSecurity? There were some recent big changes including SecRuleUpdateActionByID should be working (owasp-modsecurity/ModSecurity@85ecd19) |
yeeeee ^^ This is a feature I missed a very log time ago. I will definitely try it out. I will try to create a minimalist config for a fail and workaround solution. (It's not so easy if you created a custom build and a config generator for ModSecurity :S) |
I have created a minimalist fail and success config for this issue. One of our current released build: $(pwd)/nginx -V I have changed the output of the command. (This is not the place of self promotion.) |
The logs produced in PR #90 unfortunately falsely publish the |
Hi guys, server {
} |
Thanks for this! I just implemented this in a test environment and it seems to be doing the trick.
If I'm understanding this fix correctly, it leaves modsec on but sets the mode to detection only so it doesn't continue to redirect to the nginx default error page. |
Just hit this issue. Is there any ETA on a permanent fix? It seems the MR has stalled too. |
Fixed on ModSecurity-nginx |
Hi All,
I want to show a custom error page to our clients, when and only when our WAF block their request.
Something like: Your request made something nasty. If you think this was a false positive alert, please contact with our support.
Our current configuration:
Nginx: 1.12.0
Modsecurity: v3/master
Modsecurity-nginx: master
An example Nginx config:
I already tried:
https://github.com/SpiderLabs/ModSecurity/issues/1459
https://github.com/SpiderLabs/ModSecurity-nginx/issues/55
The text was updated successfully, but these errors were encountered: