@@ -278,6 +278,19 @@ 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+
281294 // A translator must always be registered (as support is included by
282295 // default in the Form and Validator component). If disabled, an identity
283296 // translator will be used and everything will still work as expected.
@@ -466,10 +479,6 @@ public function load(array $configs, ContainerBuilder $container): void
466479 $ container ->removeDefinition ('test.session.listener ' );
467480 }
468481
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- }
473482 $ this ->registerSecurityCsrfConfiguration ($ config ['csrf_protection ' ], $ container , $ loader );
474483
475484 // form depends on csrf being registered
@@ -754,10 +763,6 @@ private function registerFormConfiguration(array $config, ContainerBuilder $cont
754763 {
755764 $ loader ->load ('form.php ' );
756765
757- if (null === $ config ['form ' ]['csrf_protection ' ]['enabled ' ]) {
758- $ this ->writeConfigEnabled ('form.csrf_protection ' , $ config ['csrf_protection ' ]['enabled ' ], $ config ['form ' ]['csrf_protection ' ]);
759- }
760-
761766 if ($ this ->readConfigEnabled ('form.csrf_protection ' , $ container , $ config ['form ' ]['csrf_protection ' ])) {
762767 if (!$ container ->hasDefinition ('security.csrf.token_generator ' )) {
763768 throw new \LogicException ('To use form CSRF protection, "framework.csrf_protection" must be enabled. ' );
0 commit comments