-
Notifications
You must be signed in to change notification settings - Fork 43
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
500 instead of 401 on unauthenticated requests #83
Comments
It might be related to #71. It feels we have an issue with redirection. |
I discovered that using coraza-caddy in conjunction with the caddy-ratelimit module also causes it to return 500 instead of 429 when coraza is enabled.
This prompted me to do some more experimentation and troubleshooting. I found that replacing I'm currently using that as a workaround, although I'm sure there are good reasons why you recommend making The WAF still seems to detect and handle violations correctly at least...
|
And just now I encountered the 500 instead of 401 issue again in a situation where I have I use |
@mholt do you have any idea about why our module is generating issues to other modules? How should we handle the modules order when there are more modules? |
I don't know of any way to automatically put modules in the right order. I think it's ultimately up to the user to ensure they go in the right order. It sounds like this module needs to run after basicauth but before rate_limit. Usually, handler modules should recommend a default order in their docs, as if theirs is the only extra module, for example, my rate limit module recommends: I am not sure how well defining a concrete order like this for every plugin handler is going to scale. It's intended for just one or two plugins, which is 99% of use cases. The use of You can always see how the order of your handlers are being evaluated by using |
@rasschaert first of all, thanks a lot for the detailed report and the example caddyfile. It took me a few minutes to find the error by trying it. The problem comes from https://github.com/corazawaf/coraza-caddy/blob/main/coraza.go#L131 where we receive an error to interrupt the flow and we basically overide that error with an own (and return 500 status code) which shouldn't be the case. I opened #85 to fix that. I believe the fact that middlewares in caddy return errors is to interrupt the flow which is exactly what is happening here, the auth breaks the flow on request and we should be respecting that and passthrough the error. I don't think there is any problem with specific ordering of middlewares, this middleware shouldn't be conflicting with auth or ratelimiting, ideally should not conflicted with any middleware whose action is to interrupt the flow (if the middleware does not interrupt the flow but does write headers or body will indeed be a problem) @mholt I wonder which is better, for us to write status 500 in the response writer and return |
…eaks the user experience. Currently when a later in the chain middleware returned an error with a certain status code, we attempted to wrap that error with an own error which lead to misleading behaviours e.g. #83.
It is working: https://tosso.io/experiment/basicauth username: foouser, password: foopassword My settings:
|
…eaks the user experience. (#85) * chore: keep the handler error instead of trying to hijack it as it breaks the user experience. Currently when a later in the chain middleware returned an error with a certain status code, we attempted to wrap that error with an own error which lead to misleading behaviours e.g. #83. * chore: returns error to interrupt flow.
Glad to see you were able to find a fix for it :)
Almost always better to return a |
I am really sorry to re-comment on this post, but the behavior described above actually brought me here. I could not find a combination, where As far as I understand Caddys ordering, I think it would be wise to have I manually tested some ordering cases via a
I could continue, but ordering So did #85 fix this issue or did #85 only fix the error message? As far as I could ascertain, |
I think rate_limit should come before coraza. Also, would you provide a caddyfile that reproduces the problem and how are you compiling it? |
Dockerfile:
Caddyfile:
I pass |
If coraza-caddy is enabled, Caddy responds with 500 to unauthenticated requests on paths that require
basicauth
.Here's my stripped-down Caddyfile.
With coraza-caddy, 500:
Without coraza-caddy: 401, the expected behaviour:
I asked for assistance on the OWASP Slack and Matteo helpfully suggested these debugging tricks:
SecRuleEngine DetectionOnly
SecDebugLogLevel 3
These are very helpful suggestions. I can report the issue still occurrs even without the Include statements and in
DetectionOnly
mode, and no additional logging was produced on level 3.The text was updated successfully, but these errors were encountered: