Skip to content

Commit 1fe94ae

Browse files
bug symfony#58943 [FrameworkBundle] Revert " Don't auto-register form/csrf when the corresponding components are not installed" (nicolas-grekas)
This PR was merged into the 7.2 branch. Discussion ---------- [FrameworkBundle] Revert " Don't auto-register form/csrf when the corresponding components are not installed" | Q | A | ------------- | --- | Branch? | 7.2 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | - | License | MIT As discussed in symfony#58937 (comment) This still keeps https://github.com/symfony/symfony/pull/58937/files#diff-041b166c698c254a3f61cfc6390785d4f5097794b77a4b2f3f888996729cbce4R214 to make symfony/recipes#1361 work out of the box. Commits ------- 05149ae Revert "bug symfony#58937 [FrameworkBundle] Don't auto-register form/csrf when the corresponding components are not installed (nicolas-grekas)"
2 parents 4c7d3bf + 05149ae commit 1fe94ae

File tree

11 files changed

+12
-27
lines changed

11 files changed

+12
-27
lines changed

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -237,12 +237,8 @@ private function addFormSection(ArrayNodeDefinition $rootNode, callable $enableI
237237
->children()
238238
->arrayNode('form')
239239
->info('Form configuration')
240-
->treatFalseLike(['enabled' => false])
241-
->treatTrueLike(['enabled' => true])
242-
->treatNullLike(['enabled' => true])
243-
->addDefaultsIfNotSet()
240+
->{$enableIfStandalone('symfony/form', Form::class)}()
244241
->children()
245-
->scalarNode('enabled')->defaultNull()->end() // defaults to !class_exists(FullStack::class) && class_exists(Form::class)
246242
->arrayNode('csrf_protection')
247243
->treatFalseLike(['enabled' => false])
248244
->treatTrueLike(['enabled' => true])

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -278,19 +278,6 @@ public function load(array $configs, ContainerBuilder $container): void
278278
$this->readConfigEnabled('profiler', $container, $config['profiler']);
279279
$this->readConfigEnabled('workflows', $container, $config['workflows']);
280280

281-
// csrf depends on session or stateless token ids being registered
282-
if (null === $config['csrf_protection']['enabled']) {
283-
$this->writeConfigEnabled('csrf_protection', ($config['csrf_protection']['stateless_token_ids'] || $this->readConfigEnabled('session', $container, $config['session'])) && !class_exists(FullStack::class) && ContainerBuilder::willBeAvailable('symfony/security-csrf', CsrfTokenManagerInterface::class, ['symfony/framework-bundle']), $config['csrf_protection']);
284-
}
285-
286-
if (null === $config['form']['enabled']) {
287-
$this->writeConfigEnabled('form', !class_exists(FullStack::class) && ContainerBuilder::willBeAvailable('symfony/form', Form::class, ['symfony/framework-bundle']), $config['form']);
288-
}
289-
290-
if (null === $config['form']['csrf_protection']['enabled']) {
291-
$this->writeConfigEnabled('form.csrf_protection', $config['csrf_protection']['enabled'], $config['form']['csrf_protection']);
292-
}
293-
294281
// A translator must always be registered (as support is included by
295282
// default in the Form and Validator component). If disabled, an identity
296283
// translator will be used and everything will still work as expected.
@@ -479,6 +466,10 @@ public function load(array $configs, ContainerBuilder $container): void
479466
$container->removeDefinition('test.session.listener');
480467
}
481468

469+
// csrf depends on session or stateless token ids being registered
470+
if (null === $config['csrf_protection']['enabled']) {
471+
$this->writeConfigEnabled('csrf_protection', ($config['csrf_protection']['stateless_token_ids'] || $this->readConfigEnabled('session', $container, $config['session'])) && !class_exists(FullStack::class) && ContainerBuilder::willBeAvailable('symfony/security-csrf', CsrfTokenManagerInterface::class, ['symfony/framework-bundle']), $config['csrf_protection']);
472+
}
482473
$this->registerSecurityCsrfConfiguration($config['csrf_protection'], $container, $loader);
483474

484475
// form depends on csrf being registered
@@ -763,6 +754,10 @@ private function registerFormConfiguration(array $config, ContainerBuilder $cont
763754
{
764755
$loader->load('form.php');
765756

757+
if (null === $config['form']['csrf_protection']['enabled']) {
758+
$this->writeConfigEnabled('form.csrf_protection', $config['csrf_protection']['enabled'], $config['form']['csrf_protection']);
759+
}
760+
766761
if ($this->readConfigEnabled('form.csrf_protection', $container, $config['form']['csrf_protection'])) {
767762
if (!$container->hasDefinition('security.csrf.token_generator')) {
768763
throw new \LogicException('To use form CSRF protection, "framework.csrf_protection" must be enabled.');

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/form_csrf_disabled.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
'annotations' => false,
55
'csrf_protection' => false,
66
'form' => [
7-
'enabled' => true,
87
'csrf_protection' => true,
98
],
109
'http_method_override' => false,

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/form_no_csrf.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
'handle_all_throwables' => true,
77
'php_errors' => ['log' => true],
88
'form' => [
9-
'enabled' => true,
109
'csrf_protection' => [
1110
'enabled' => false,
1211
],

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/full.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
'enabled_locales' => ['fr', 'en'],
77
'csrf_protection' => true,
88
'form' => [
9-
'enabled' => true,
109
'csrf_protection' => [
1110
'field_name' => '_csrf',
1211
],

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/form_csrf_disabled.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<framework:annotations enabled="false"/>
1313
<framework:php-errors log="true" />
1414
<framework:csrf-protection enabled="false"/>
15-
<framework:form enabled="true">
15+
<framework:form>
1616
<framework:csrf-protection enabled="true"/>
1717
</framework:form>
1818
</framework:config>

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/form_no_csrf.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<framework:config http-method-override="false" handle-all-throwables="true">
1010
<framework:annotations enabled="false" />
1111
<framework:php-errors log="true" />
12-
<framework:form enabled="true">
12+
<framework:form>
1313
<framework:csrf-protection enabled="false" />
1414
</framework:form>
1515
</framework:config>

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/full.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<framework:enabled-locale>fr</framework:enabled-locale>
1111
<framework:enabled-locale>en</framework:enabled-locale>
1212
<framework:csrf-protection />
13-
<framework:form enabled="true">
13+
<framework:form>
1414
<framework:csrf-protection field-name="_csrf"/>
1515
</framework:form>
1616
<framework:esi enabled="true" />

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/form_csrf_disabled.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ framework:
22
annotations: false
33
csrf_protection: false
44
form:
5-
enabled: true
65
csrf_protection: true
76
http_method_override: false
87
handle_all_throwables: true

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/form_no_csrf.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,5 @@ framework:
55
php_errors:
66
log: true
77
form:
8-
enabled: true
98
csrf_protection:
109
enabled: false

0 commit comments

Comments
 (0)