Skip to content

Issues while using error_page and location #55

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

Closed
zimmerle opened this issue Jun 27, 2017 · 20 comments
Closed

Issues while using error_page and location #55

zimmerle opened this issue Jun 27, 2017 · 20 comments
Assignees

Comments

@zimmerle
Copy link
Contributor

According to the original report (Ehsan Mahdavi) the audit logs are not working for custom error pages (using: error_page or location). In that scenario the logs are not written.

Ehsan Mahdavi also said that in case of SecRuleEngine is set to DetectionOnly everything works like expected.

@intelbg
Copy link

intelbg commented Oct 10, 2017

Hello, is there a plan to be fixed? The issue still exists and it's very serious. Also, audit_logging now works without the custom 403 page only in serial mode, not in concurrent. Thank you in advance. I think fixing this will solve many other issues and will help many people like me.

@intelbg
Copy link

intelbg commented Oct 10, 2017

In addition, the problem with concurrent logging was my mistake. It works. Remains the problem with custom 403 page only.

@intelbg
Copy link

intelbg commented Oct 11, 2017

If you don't plan to fix it can you please tell me which file and function is related to this problem ?

@victorhora
Copy link
Contributor

@averges @intelbg

Have you tried enabling the intercept_errors directives (e.g. proxy_intercept_errors) directive in Nginx?

@intelbg
Copy link

intelbg commented Oct 12, 2017

hi @victorhora! Thanks about the reply. I tried - in server block and in location. but didn't help. Logging didn't work with it too with custom 403 page.

@averges
Copy link

averges commented Oct 17, 2017

@victorhora, yes, I've tried with intercept_errors directives but no luck.

Thank you for looking into this error.

@cauealvesbraz
Copy link

@zimmerle Here too

It's enabled the proxy_intercept_errors and returns the same problem.

@cauealvesbraz
Copy link

Maybe, have some problem in this code: https://github.com/SpiderLabs/ModSecurity-nginx/blob/master/src/ngx_http_modsecurity_module.c#L164-L186

I'm trying to understand it

@intelbg
Copy link

intelbg commented Oct 28, 2017

@ceasbz I think that the problem is in this chunk of code too, but I a can't understand and fix it. If you do it please share the fix. I will appreciate it!

@zimmerle
Copy link
Contributor Author

Hi,

Notice the configurations [1] and [2]. They are different by the error_block location.

In [1] the error was specified inside the location block. In that case the ModSecurity rules specified for the location block will be also applied to the error. That is different from [2] where we have no ModSecurity rules configured for the error block.

In my tests, having the configuration in the right place, I managed to have ModSecurity working as expected. I am closing the bug assuming that it was a configuration issue. If you think otherwise, please re-open.

@rm3nchaca
Copy link

Hi!
I've tested the 2 example configs, the 1 is not showing the custom error page but is logging as expected, the 2 displays the custom error page but is not logging.

@AirisX
Copy link
Contributor

AirisX commented Feb 15, 2018

Hi @rm3nchaca,

Try to consider suggestions in this thread #76

@intelbg
Copy link

intelbg commented Feb 21, 2018

Hello @AirisX! I replaced the files with yours and recompiled nginx with the new modsecurity-nginx files. Logging seems to work, but uid parameter is no more logged in the audit log. UID parameter is a uid cookie set in nginx with userid module like follows:

userid on;
userid_name uid;
userid_expires 1s;
userid_path /;
Then when you are blocked on the page it's shown:
403 Forbidden by TU2Xb1qNgCOsXwgwAwMDAg==

And this should be logged in audit logs too as it was before your patch. Can you please give me an advice how to proceed?

@AirisX
Copy link
Contributor

AirisX commented Feb 21, 2018

Hello @intelbg,

Could you provide your config? Please, also show an example of the audit log entries before and after patch.

@intelbg
Copy link

intelbg commented Feb 23, 2018

@AirisX Thank you about your reply!
Here is the config file, the log file now and screenshot of log file before the patch where there is a line cookie with the uid value. Do you think that this is related to the patch? If you prefer I can write you on a private message/email.

config.txt
log_after_patch.txt
screen shot 2017-08-12 at10 10 56 am

@AirisX
Copy link
Contributor

AirisX commented Feb 27, 2018

Hello @intelbg,

Could you clarify, do you mean uid cookie in the request header? As I can see from you screenshot of the log file, you are talking about request header. In this case this may be due to the parameter userid_expires which sets the expiration time to 1s and the next client request after this time may not contain this cookie. Therefore, if you make 2 (or more) requests per second the second and subsequent audit entries will contain the uid cookie.

@intelbg
Copy link

intelbg commented Mar 1, 2018

@AirisX you are right! But no matter what value it's set in some moment there is a point that no uid cookie is logged and I can't understand why. In the time of expiration it should provide and log immediately a different cookie, right?

@AirisX
Copy link
Contributor

AirisX commented Mar 1, 2018

@intelbg Yes, while the uid cookie is not expired, it should be logged. Try to increase the userid_expires value to 1 hour, to exclude other reasons.

@intelbg
Copy link

intelbg commented Mar 2, 2018

@AirisX even with 1 hour settings for expiration, the first request for example does not log the uid cookie. With the second and third there is no problem (I attached the log).
auditlog.txt
Also, if it's with big expiration time one uid cookie will match / parse more than one matched/blocked rule as I want to have separate uid cookie value for every different block hit. How can achive it? Is it possible and why in case of expiration it's not logged as it should immediately assign another uid cookie hash. Sorry it it's already out of the topic but technically I really can't understand this and need solution.

@AirisX
Copy link
Contributor

AirisX commented Mar 2, 2018

@intelbg of course, the first request doesn't contain the uid cookie, since for achieve this it must be set by the first Set-Cookie server response header. How else the client software must to know about this cookie!?
I wrote about it earlier in comment #55 (comment):

Therefore, if you make 2 (or more) requests per second the second and subsequent audit entries will contain the uid cookie.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants