Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[HttpKernel] Preserve security exceptions #27515

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 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
<argument>%kernel.debug%</argument>
<argument>%kernel.charset%</argument>
<argument>%debug.file_link_format%</argument>
<argument type="collection" /> <!-- silent ignored exceptions -->
</service>

<service id="validate_request_listener" class="Symfony\Component\HttpKernel\EventListener\ValidateRequestListener">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Symfony\Component\DependencyInjection\Alias;
use Symfony\Component\DependencyInjection\Argument\IteratorArgument;
use Symfony\Component\DependencyInjection\ChildDefinition;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\Compiler\ServiceLocatorTagPass;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
Expand All @@ -28,6 +29,9 @@
use Symfony\Component\Config\FileLocator;
use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface;
use Symfony\Component\Security\Core\Encoder\Argon2iPasswordEncoder;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use Symfony\Component\Security\Core\Exception\AuthenticationException;
use Symfony\Component\Security\Core\Exception\LogoutException;
use Symfony\Component\Security\Core\User\UserProviderInterface;
use Symfony\Component\Security\Http\Controller\UserValueResolver;

Expand All @@ -37,7 +41,7 @@
* @author Fabien Potencier <fabien@symfony.com>
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
*/
class SecurityExtension extends Extension
class SecurityExtension extends Extension implements CompilerPassInterface
{
private $requestMatchers = array();
private $expressions = array();
Expand Down Expand Up @@ -121,6 +125,21 @@ public function load(array $configs, ContainerBuilder $container)
->addTag('security.voter');
}

public function process(ContainerBuilder $container)
Copy link
Member

Choose a reason for hiding this comment

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

I would rather put this compiler pass in a dedicated class.

We have lots of different passes in each of our bundles, and this logic is not more related to the DI extension than other passes (rather less)

{
$silentExceptions = array(
AuthenticationException::class,
AccessDeniedException::class,
LogoutException::class,
);
if ($container->hasDefinition('http_exception_listener') && 6 === count(($definition = $container->getDefinition('http_exception_listener'))->getArguments())) {
$definition->replaceArgument(5, array_merge($definition->getArgument(5), $silentExceptions));
}
if ($container->hasDefinition('twig.exception_listener') && 6 === count(($definition = $container->getDefinition('twig.exception_listener'))->getArguments())) {
$definition->replaceArgument(5, array_merge($definition->getArgument(5), $silentExceptions));
}
}

private function createRoleHierarchy(array $config, ContainerBuilder $container)
{
if (!isset($config['role_hierarchy']) || 0 === count($config['role_hierarchy'])) {
Expand Down
3 changes: 3 additions & 0 deletions 3 src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@
<argument>%twig.exception_listener.controller%</argument>
<argument type="service" id="logger" on-invalid="null" />
<argument>%kernel.debug%</argument>
<argument>%kernel.charset%</argument>
<argument>%debug.file_link_format%</argument>
<argument type="collection" /> <!-- silent ignored exceptions -->
</service>

<service id="twig.controller.exception" class="Symfony\Bundle\TwigBundle\Controller\ExceptionController" public="true">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,28 @@ class ExceptionListener implements EventSubscriberInterface
protected $debug;
private $charset;
private $fileLinkFormat;
private $silentIgnore;

public function __construct($controller, LoggerInterface $logger = null, $debug = false, $charset = null, $fileLinkFormat = null)
public function __construct($controller, LoggerInterface $logger = null, $debug = false, $charset = null, $fileLinkFormat = null, array $silentIgnore = array())
{
$this->controller = $controller;
$this->logger = $logger;
$this->debug = $debug;
$this->charset = $charset;
$this->fileLinkFormat = $fileLinkFormat;
$this->silentIgnore = $silentIgnore;
}

public function logKernelException(GetResponseForExceptionEvent $event)
{
$exception = $event->getException();
$request = $event->getRequest();
$exception = $prev = $event->getException();
do {
foreach ($this->silentIgnore as $class) {
if ($prev instanceof $class) {
return;
}
}
} while (null !== $prev = $exception->getPrevious());

$this->logException($exception, sprintf('Uncaught PHP Exception %s: "%s" at %s line %s', get_class($exception), $exception->getMessage(), $exception->getFile(), $exception->getLine()));
}
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.