@@ -278,6 +278,19 @@ public function load(array $configs, ContainerBuilder $container): void
278
278
$ this ->readConfigEnabled ('profiler ' , $ container , $ config ['profiler ' ]);
279
279
$ this ->readConfigEnabled ('workflows ' , $ container , $ config ['workflows ' ]);
280
280
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
+
281
294
// A translator must always be registered (as support is included by
282
295
// default in the Form and Validator component). If disabled, an identity
283
296
// translator will be used and everything will still work as expected.
@@ -466,10 +479,6 @@ public function load(array $configs, ContainerBuilder $container): void
466
479
$ container ->removeDefinition ('test.session.listener ' );
467
480
}
468
481
469
- // csrf depends on session 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
- }
473
482
$ this ->registerSecurityCsrfConfiguration ($ config ['csrf_protection ' ], $ container , $ loader );
474
483
475
484
// form depends on csrf being registered
@@ -754,10 +763,6 @@ private function registerFormConfiguration(array $config, ContainerBuilder $cont
754
763
{
755
764
$ loader ->load ('form.php ' );
756
765
757
- if (null === $ config ['form ' ]['csrf_protection ' ]['enabled ' ]) {
758
- $ this ->writeConfigEnabled ('form.csrf_protection ' , $ config ['csrf_protection ' ]['enabled ' ], $ config ['form ' ]['csrf_protection ' ]);
759
- }
760
-
761
766
if ($ this ->readConfigEnabled ('form.csrf_protection ' , $ container , $ config ['form ' ]['csrf_protection ' ])) {
762
767
if (!$ container ->hasDefinition ('security.csrf.token_generator ' )) {
763
768
throw new \LogicException ('To use form CSRF protection, "framework.csrf_protection" must be enabled. ' );
0 commit comments