-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
KeyAuth Middleware perhaps should return 500 when validator return an error #1846
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
This is not all correct. You have to check in what case For example Line 116 in bb7f222
returns error when there is no header for key or header is with not matching auth scheme. Those are cases when client is doing something that is not allowed. 500 is more for cases when server does something unexpected. |
@aldas Validator is totally user defined, when valid, err := config.Validator(key, c) is reached, the middleware have got a key. Now the first bool return value means the key is valid or not. If the key is "invalid key", like this line Line 104 in bb7f222
said, I should just return When I return an error, it's must be a server error, like db is down. |
If middleware just pass this error to c.Error(), everything is all right too. |
you are correct I'm still personally convinced that it should be 401. For security related stuff it is better to return by default unambitious 401 as it would make attacker harder to blackbox application logic/state. If you really want to know what that original error then just take it form httpError he : = err.(echo.HttpErrror)
if he.Code == http.StatusUnauthorized && he.Internal != nil {
... |
I've done like your suggesting before but feel a bit stupid myself... |
well, you could send PR to add errorhandler as options for this middleware. something similar to Line 213 in bb7f222
|
Thank you, I'll try it. |
I would advise against extracting those errors and sending then to the client. It is totally OK and even advisable to log them but you are exposing your internals to unauthorized clients. Lets imagine that you use header value on SQL query and do not escape it properly - you could be exposing/leaking information about sql injection to the attacker. Or you return third party library errors directly and from them attack can deduce library and version you are potentially using and use vulnerabilities from them. |
@aldas Yes, thank you, I should not extract errors to client when it is not debug mode. I've change it better. |
Now I can't throw a ServerError when validate tokens.
The text was updated successfully, but these errors were encountered: