-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Security + JSON_LOGIN return an HTTP 500 instead of an HTTP 403 #25806
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
…oduce the issue described in symfony/symfony#25806
Well, the message says it received a |
@stof, yes indeed i've seen this error, but my AccessDeniedHandler implemented the AccessDeniedHandlerInterface because it's in the documentation here : https://symfony.com/doc/current/security/access_denied_handler.html But in fact, when i've face that error, i've changed my AccessDeniedHandler to implement the AuthenticationFailureHandlerInterface (sorry i missed to afdd that informations) and this time, Symfony never walk throught my handler and i get back at the initial issue. Here is my Handler:
So i still have the probem |
@Rebolon the doc also says to configure it under |
@stof not sure that the documentation is up to date and compatible with json_login coz it returns this:
Whereas with the failure_handler (defined in symfony/security-bundle/DependencyInjection/Security/Factory/JsonLoginFactory.php L90) there is no Exception thrown by the framework And if i move it under I don't know where to look for, thanks for help |
|
Documentation may be lacking (see symfony/symfony-docs#4258) |
@chalasr thx, now i have identified that in fact my route had 'html' as default format. So it requires to set manually in the action annotation or generally in the routing.yaml
Now, when i try to a access the uri without be authentified i receive json content instead of html content, but the result is still a 500... I understand what you said about the difference between I modified the security.yaml to get a simple one (in_memory user... and both error handlers):
With Xdebug, i can see that the this listener is catching the call : But then, it is the
Because the config, status is null so it retuen the AccessDeniedException instead of the HttpException But at no moment my Handler is catching something with handle (failure_handler) or onAuthenticationFailure (access_denied_handler) I'm sure that i'm missing something... I'v put breakpoints on Listeners that implements AuthenticationFailureHandlerInterface |
it still fail coz my handlers are not managed by symfony
@Rebolon My guess is that removing the |
@chalasr so you mean i should remove this annotation and do it programatically ? i'll give it a try and give you a feedback |
yea, just to confirm the issues comes from there. Thanks |
Here is the action:
And my handlers are still not used (and i get the same exception as before). Should i set my AccessDeniedHandler in my services.yaml ? i don't think so coz the security.yaml should declare it as listeners thanks to configurations |
Hey, maybe i've found why my handler (based on configuration failure_handler) is not managed: Symfony\Component\Security\Http\Authentication\CustomAuthenticationFailureHandler::_construct L31 it checks if it has a setOptions methods
I'll confirm this (but why a programatic checks, instead of a hard typing based on Interface ? AuthenticationFailureHandlerInterface should not deinfe the setOptions ?) |
Argh |
Ok after more investigation i understand that the json_login.failure_handler is called when the check_path route is called and that the authentification failed (wrong user or password). And i can say that the failure_handler is working as expected. So now i can focus on the access_denied_handler that is never called when i have an AccessDeniedException. |
In symfony/security/Http/Firewall/ExceptionListener::handleAcessDeniedException::L120 there is a check on When i look at the isFullFledged method i can see that it will check the token. This token is a Symfony\Component\Security\Core\Authentification\Token\AnonymousToken so it's anonymous, but it's not a rememberMe token so the test will prevent to continue to the accessDeniedException. If someone can give me more information about how to configure the Security Component to allow the access_denied_handler to run, that would be cool. |
I am afraid I am of not much help here. |
Using a Guard authentication solve my problem (but i still don't find if it's a problem on my side or on symfony side). But if this is the 'standard way' of using json_login (or another way) it should be specified in the documentation. For instance a json_login system in security component will always throw a 500 InsufficientAuthenticationException (i've just tried again on a new clean project with SF 4.0.4 and it's still the same behavior). If i'm wrong, tell me why :-) |
We have the same problem with json_login (double exception resulting in a 500 instead of 401) I don't understand why in Maybe @dunglas (being the author of |
actually this problem is dated back to 2013 to fix: you need to create class:
and security.yaml:
so that entrypoint in of course there is no info about that: or here: https://symfony.com/doc/current/security/json_login_setup.html not to mention that this kind of error should not be 500 inernal server error, just HTTP 401 unauthorised that indicates, reasonably, that user do is now anonymous, and therefore requires authorization to gain access to route where exception happened |
I'm using the Security component with the (marked as experimental) json_login system that has been introduced in Symfony 3.3
It works quite well, but when i access a route protected by this firewall i get a 500 Symfony\Component\Security\Core\Exception\InsufficientAuthentificationException coming from an Symfony\Component\Security\Core\Exception\AccessDeniedException whereas i expect to get a 403 HTTPException (or something like this).
I've looked at the web and finally i'm looking at the source code. I can see that json_login can expect a failure_handler config but when i follow the official documentation i got a 500 with a json string :
And when i implements what is said on the previous message i return to my 500 .
Here is a part of the security.yaml:
What's wrong ? coz the handler is never used when i run throught Xdebug
The project is available here : https://github.com/Rebolon/php-sf-flex-webpack-encore-vuejs/tree/fix/31-auth-500-instead-of-403
The route to test and reproduce is
/demo/login/json/issue/sf-25806
The text was updated successfully, but these errors were encountered: