Skip to content

Commit e858abf

Browse files
committed
bug #9673 Fixed BC break in csrf protection (WouterJ)
This PR was merged into the 2.4 branch. Discussion ---------- Fixed BC break in csrf protection | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #9429 | License | MIT | Doc PR | n/a Commits ------- d00954a Default form.csrf_protection.enabled to csrf_protection.enabled
2 parents 413221e + e05b80a commit e858abf

File tree

6 files changed

+25
-4
lines changed

6 files changed

+25
-4
lines changed

DependencyInjection/Configuration.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,12 @@ private function addFormSection(ArrayNodeDefinition $rootNode)
120120
->canBeEnabled()
121121
->children()
122122
->arrayNode('csrf_protection')
123-
->canBeDisabled()
123+
->treatFalseLike(array('enabled' => false))
124+
->treatTrueLike(array('enabled' => true))
125+
->treatNullLike(array('enabled' => true))
126+
->addDefaultsIfNotSet()
124127
->children()
128+
->booleanNode('enabled')->defaultNull()->end() // defaults to framework.csrf_protection.enabled
125129
->scalarNode('field_name')->defaultNull()->end()
126130
->end()
127131
->end()

DependencyInjection/FrameworkExtension.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,10 @@ public function load(array $configs, ContainerBuilder $container)
162162
private function registerFormConfiguration($config, ContainerBuilder $container, XmlFileLoader $loader)
163163
{
164164
$loader->load('form.xml');
165+
if (null === $config['form']['csrf_protection']['enabled']) {
166+
$config['form']['csrf_protection']['enabled'] = $config['csrf_protection']['enabled'];
167+
}
168+
165169
if ($this->isConfigEnabled($container, $config['form']['csrf_protection'])) {
166170
$loader->load('form_csrf.xml');
167171

Tests/DependencyInjection/ConfigurationTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ protected static function getBundleDefaultConfig()
9696
'form' => array(
9797
'enabled' => false,
9898
'csrf_protection' => array(
99-
'enabled' => true,
99+
'enabled' => null, // defaults to csrf_protection.enabled
100100
'field_name' => null,
101101
),
102102
),

Tests/DependencyInjection/Fixtures/php/csrf.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
<?php
22

33
$container->loadFromExtension('framework', array(
4+
'csrf_protection' => array(
5+
'enabled' => false,
6+
),
47
'form' => array(
58
'enabled' => true,
9+
'csrf_protection' => array(
10+
'enabled' => true,
11+
),
612
),
713
'session' => array(
814
'handler_id' => null,

Tests/DependencyInjection/Fixtures/xml/csrf.xml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@
77
http://symfony.com/schema/dic/symfony http://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
88

99
<framework:config>
10-
<framework:form />
10+
<framework:csrf-protection enabled="false" />
11+
12+
<framework:form>
13+
<framework:csrf-protection />
14+
</framework:form>
15+
1116
<framework:session />
1217
</framework:config>
1318
</container>
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
framework:
2+
csrf_protection: false
23
secret: s3cr3t
3-
form: ~
4+
form:
5+
csrf_protection: true
46
session: ~
57
# CSRF is disabled by default
68
# csrf_protection: ~

0 commit comments

Comments
 (0)