-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Security] Fix ExceptionListener to catch correctly AccessDeniedException if is not first exception #9823
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
Conversation
Error 500 instead of 403 if previous exception is provided to AccessDeniedException
|
||
return; | ||
} else { | ||
if (null === $exception->getPrevious()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you should use elseif
the loop should stop once you find an exception being handled by this listener. Otherwise it can create really weird behavior if you have a security exception which has another security exception as previous exception |
So I shoud add breake in every if(instance) before closing bracket? I have tested this with this code and get first security exception (ADExc 2): $e1 = new \Exception('one');
$e2 = new AccessDeniedException('ADExc', $e1);
$e3 = new AccessDeniedException('ADExc 2', $e2);
throw new \Exception('tree', 555, $e3); |
please provide a title for the Pr |
@karion yes you should break. Otherwise, in the case of starting the authentication for instance, you would start several times |
$this->logger->debug(sprintf('Access is denied (and user is neither anonymous, nor remember-me) by "%s" at line %s', $exception->getFile(), $exception->getLine())); | ||
} | ||
break; | ||
} elseif ($exception instanceof AccessDeniedException) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to do elseif
just if
as you do break;
line above.
Also add new line before break;
.
Closing in favor of #9879 where I fixed CS, refactored the code a bit, and added some unit tests. |
…eniedException if is not first exception (fabpot) This PR was merged into the 2.3 branch. Discussion ---------- [Security] Fix ExceptionListener to catch correctly AccessDeniedException if is not first exception | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #9544, #8467?, #9823 | License | MIT | Doc PR | Same as #9823 but with some refactoring of the code and with some unit tests. When merging to 2.4, the unit tests can be simplified a bit. Commits ------- 172fd63 [Security] made code easier to understand, added some missing unit tests 616b6c5 [Security] fixed error 500 instead of 403 if previous exception is provided to AccessDeniedException
My after HackingDay contribution :) @jakzal.
The problem was with "while" loop which extracts only the first exception.
Now the Listener walks through all exceptions and checks if there are any security exceptions