@@ -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. ' );
0 commit comments