8000 Security/Http: catch Throwable · symfony/symfony@9bb7f79 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9bb7f79

Browse files
committed
Security/Http: catch Throwable
1 parent 0ba3013 commit 9bb7f79

File tree

3 files changed

+60
-0
lines changed

3 files changed

+60
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Security\Http\Exception;
13+
14+
class FatalThrowableError extends \ErrorException
15+
{
16+
17+
public function __construct(\Throwable $e)
18+
{
19+
if ($e instanceof \ParseError) {
20+
$message = 'Parse error: ' . $e->getMessage();
21+
$severity = E_PARSE;
22+
} elseif ($e instanceof \TypeError) {
23+
$message = 'Type error: ' . $e->getMessage();
24+
$severity = E_RECOVERABLE_ERROR;
25+
} else {
26+
$message = 'Fatal error: ' . $e->getMessage();
27+
$severity = E_ERROR;
28+
}
29+
30+
\ErrorException::__construct(
31+
$message,
32+
$e->getCode(),
33+
$severity,
34+
$e->getFile(),
35+
$e->getLine()
36+
);
37+
38+
$this->setTrace($e->getTrace());
39+
}
40+
41+
protected function setTrace($trace)
42+
{
43+
$traceReflector = new \ReflectionProperty('Exception', 'trace');
44+
$traceReflector->setAccessible(true);
45+
$traceReflector->setValue($this, $trace);
46+
}
47+
}

src/Symfony/Component/Security/Http/Firewall/ExceptionListener.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
2323
use Symfony\Component\Security\Core\Exception\InsufficientAuthenticationException;
2424
use Symfony\Component\Security\Core\Exception\LogoutException;
25+
use Symfony\Component\Security\Http\Exception\FatalThrowableError;
2526
use Symfony\Component\Security\Http\HttpUtils;
2627
use Symfony\Component\HttpFoundation\Request;
2728
use Psr\Log\LoggerInterface;
@@ -111,6 +112,8 @@ private function handleAuthenticationException(GetResponseForExceptionEvent $eve
111112
$event->setResponse($this->startAuthentication($event->getRequest(), $exception));
112113
} catch (\Exception $e) {
113114
$event->setException($e);
115+
} catch (\Throwable $e) {
116+
$event->setException(new FatalThrowableError($e));
114117
}
115118
}
116119

@@ -131,6 +134,8 @@ private function handleAccessDeniedException(GetResponseForExceptionEvent $event
131134
$event->setResponse($this->startAuthentication($event->getRequest(), $insufficientAuthenticationException));
132135
} catch (\Exception $e) {
133136
$event->setException($e);
137+
} catch (\Throwable $e) {
138+
$event->setException(new FatalThrowableError($e));
134139
}
135140

136141
return;
@@ -154,6 +159,10 @@ private function handleAccessDeniedException(GetResponseForExceptionEvent $event
154159
$event->setResponse($event->getKernel()->handle($subRequest, HttpKernelInterface::SUB_REQUEST, true));
155160
}
156161
} catch (\Exception $e) {
162+
} catch (\Throwable $e) {
163+
}
164+
165+
if (isset($e)) {
157166
if (null !== $this->logger) {
158167
$this->logger->error('An exception was thrown when handling an AccessDeniedException.', array('exception' => $e));
159168
}

src/Symfony/Component/Security/Http/RememberMe/TokenBasedRememberMeServices.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ protected function processAutoLoginCookie(array $cookieParts, Request $request)
4242
try {
4343
$user = $this->getUserProvider($class)->loadUserByUsername($username);
4444
} catch (\Exception $e) {
45+
} catch (\Throwable $e) {
46+
}
47+
48+
if (isset($e)) {
4549
if (!$e instanceof AuthenticationException) {
4650
$e = new AuthenticationException($e->getMessage(), $e->getCode(), $e);
4751
}

0 commit comments

Comments
 (0)
0