Skip to content

Commit fa68ee9

Browse files
Merge branch '3.4' into 4.0
* 3.4: [appveyor] set memory_limit=-1 [Console] Keep the modified exception handler [Console] Fix restoring exception handler [Router] Skip anonymous classes when loading annotated routes allow dashes in cwd pathname when running the tests Fixed Request::__toString ignoring cookies Make sure we only build once and have one time the prefix when importing routes [Security] Fix fatal error on non string username [FrameworkBundle] Automatically enable the CSRF if component *+ session* are loaded
2 parents 9f8d083 + 0eea7e9 commit fa68ee9

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

DependencyInjection/Configuration.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use Symfony\Component\Form\Form;
2222
use Symfony\Component\Lock\Lock;
2323
use Symfony\Component\Lock\Store\SemaphoreStore;
24+
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
2425
use Symfony\Component\Serializer\Serializer;
2526
use Symfony\Component\Translation\Translator;
2627
use Symfony\Component\Validator\Validation;
@@ -109,7 +110,14 @@ private function addCsrfSection(ArrayNodeDefinition $rootNode)
109110
$rootNode
110111
->children()
111112
->arrayNode('csrf_protection')
112-
->canBeEnabled()
113+
->treatFalseLike(array('enabled' => false))
114+
->treatTrueLike(array('enabled' => true))
115+
->treatNullLike(array('enabled' => true))
116+
->addDefaultsIfNotSet()
117+
->children()
118+
// defaults to framework.session.enabled && !class_exists(FullStack::class) && interface_exists(CsrfTokenManagerInterface::class)
119+
->booleanNode('enabled')->defaultNull()->end()
120+
->end()
113121
->end()
114122
->end()
115123
;

DependencyInjection/FrameworkExtension.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
1818
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
1919
use Symfony\Bundle\FrameworkBundle\Routing\AnnotatedRouteControllerLoader;
20+
use Symfony\Bundle\FullStack;
2021
use Symfony\Component\Cache\Adapter\AbstractAdapter;
2122
use Symfony\Component\Cache\Adapter\AdapterInterface;
2223
use Symfony\Component\Cache\Adapter\ArrayAdapter;
@@ -63,6 +64,7 @@
6364
use Symfony\Component\Routing\Loader\AnnotationDirectoryLoader;
6465
use Symfony\Component\Routing\Loader\AnnotationFileLoader;
6566
use Symfony\Component\Security\Core\Security;
67+
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
6668
use Symfony\Component\Serializer\Encoder\DecoderInterface;
6769
use Symfony\Component\Serializer\Encoder\EncoderInterface;
6870
use Symfony\Component\Serializer\Mapping\Factory\CacheClassMetadataFactory;
@@ -183,6 +185,11 @@ public function load(array $configs, ContainerBuilder $container)
183185
$this->registerRequestConfiguration($config['request'], $container, $loader);
184186
}
185187

188+
if (null === $config['csrf_protection']['enabled']) {
189+
$config['csrf_protection']['enabled'] = $this->sessionConfigEnabled && !class_exists(FullStack::class) && interface_exists(CsrfTokenManagerInterface::class);
190+
}
191+
$this->registerSecurityCsrfConfiguration($config['csrf_protection'], $container, $loader);
192+
186193
if ($this->isConfigEnabled($container, $config['form'])) {
187194
if (!class_exists('Symfony\Component\Form\Form')) {
188195
throw new LogicException('Form support cannot be enabled as the Form component is not installed.');
@@ -203,8 +210,6 @@ public function load(array $configs, ContainerBuilder $container)
203210
$container->removeDefinition('console.command.form_debug');
204211
}
205212

206-
$this->registerSecurityCsrfConfiguration($config['csrf_protection'], $container, $loader);
207-
208213
if ($this->isConfigEnabled($container, $config['assets'])) {
209214
if (!class_exists('Symfony\Component\Asset\Package')) {
210215
throw new LogicException('Asset support cannot be enabled as the Asset component is not installed.');

0 commit comments

Comments
 (0)