Skip to content

Navigation Menu

Sign in
Appearance settings

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

Commit b77538c

Browse filesBrowse files
committed
Disable CSP header on exception pages only in debug
Same condition is used by default TwigBridge ExceptionController to evaluate if styled exception page is supposed to be shown.
1 parent 1b92f06 commit b77538c
Copy full SHA for b77538c

File tree

3 files changed

+6
-3
lines changed
Filter options

3 files changed

+6
-3
lines changed

‎src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@
129129
<tag name="monolog.logger" channel="request" />
130130
<argument>%twig.exception_listener.controller%</argument>
131131
<argument type="service" id="logger" on-invalid="null" />
132+
<argument>%kernel.debug%</argument>
132133
</service>
133134

134135
<service id="twig.controller.exception" class="%twig.controller.exception.class%">

‎src/Symfony/Component/HttpKernel/EventListener/ExceptionListener.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpKernel/EventListener/ExceptionListener.php
+4-2Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,13 @@ class ExceptionListener implements EventSubscriberInterface
3232
{
3333
protected $controller;
3434
protected $logger;
35+
protected $debug;
3536

36-
public function __construct($controller, LoggerInterface $logger = null)
37+
public function __construct($controller, LoggerInterface $logger = null, $debug = false)
3738
{
3839
$this->controller = $controller;
3940
$this->logger = $logger;
41+
$this->debug = $debug;
4042
}
4143

4244
public function onKernelException(GetResponseForExceptionEvent $event)
@@ -71,7 +73,7 @@ public function onKernelException(GetResponseForExceptionEvent $event)
7173

7274
$event->setResponse($response);
7375

74-
if ($eventDispatcher instanceof EventDispatcherInterface) {
76+
if ($this->debug && $eventDispatcher instanceof EventDispatcherInterface) {
7577
$cspRemovalListener = function (FilterResponseEvent $event) use (&$cspRemovalListener, $eventDispatcher) {
7678
$event->getResponse()->headers->remove('Content-Security-Policy');
7779
$eventDispatcher->removeListener(KernelEvents::RESPONSE, $cspRemovalListener);

‎src/Symfony/Component/HttpKernel/Tests/EventListener/ExceptionListenerTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpKernel/Tests/EventListener/ExceptionListenerTest.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ public function testCSPHeaderIsRemoved()
134134
return new Response($request->getRequestFormat());
135135
}));
136136

137-
$listener = new ExceptionListener('foo', $this->getMockBuilder('Psr\Log\LoggerInterface')->getMock());
137+
$listener = new ExceptionListener('foo', $this->getMockBuilder('Psr\Log\LoggerInterface')->getMock(), true);
138138

139139
$dispatcher->addSubscriber($listener);
140140

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.