Skip to content

[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

Closed
wants to merge 4 commits into from

Conversation

karion
Copy link
Contributor

@karion karion commented Dec 19, 2013

Q A
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #9544
License MIT
Doc PR

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

Error 500 instead of 403 if previous exception is provided to
AccessDeniedException

return;
} else {
if (null === $exception->getPrevious()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should use elseif

@stof
Copy link
Member

stof commented Dec 19, 2013

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

@karion
Copy link
Contributor Author

karion commented Dec 19, 2013

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);

@cordoval
Copy link
Contributor

please provide a title for the Pr

@stof
Copy link
Member

stof commented Dec 19, 2013

@karion yes you should break. Otherwise, in the case of starting the authentication for instance, you would start several times

@karion
Copy link
Contributor Author

karion commented Dec 19, 2013

@stof I have added breaks in de2564a

$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) {
Copy link
Contributor

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;.

@fabpot
Copy link
Member

fabpot commented Dec 28, 2013

Closing in favor of #9879 where I fixed CS, refactored the code a bit, and added some unit tests.

@fabpot fabpot closed this Dec 28, 2013
fabpot added a commit that referenced this pull request Dec 29, 2013
…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
@karion karion deleted the 2.3 branch December 29, 2013 17:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy