1717use Symfony \Bundle \FrameworkBundle \Controller \AbstractController ;
1818use Symfony \Bundle \FrameworkBundle \Controller \Controller ;
1919use Symfony \Bundle \FrameworkBundle \Routing \AnnotatedRouteControllerLoader ;
20+ use Symfony \Bundle \FullStack ;
2021use Symfony \Component \Cache \Adapter \AbstractAdapter ;
2122use Symfony \Component \Cache \Adapter \AdapterInterface ;
2223use Symfony \Component \Cache \Adapter \ArrayAdapter ;
6364use Symfony \Component \Routing \Loader \AnnotationDirectoryLoader ;
6465use Symfony \Component \Routing \Loader \AnnotationFileLoader ;
6566use Symfony \Component \Security \Core \Security ;
67+ use Symfony \Component \Security \Csrf \CsrfTokenManagerInterface ;
6668use Symfony \Component \Serializer \Encoder \DecoderInterface ;
6769use Symfony \Component \Serializer \Encoder \EncoderInterface ;
6870use Symfony \Component \Serializer \Mapping \Factory \CacheClassMetadataFactory ;
@@ -229,6 +231,11 @@ public function load(array $configs, ContainerBuilder $container)
229231 $ this ->registerRequestConfiguration ($ config ['request ' ], $ container , $ loader );
230232 }
231233
234+ if (null === $ config ['csrf_protection ' ]['enabled ' ]) {
235+ $ config ['csrf_protection ' ]['enabled ' ] = $ this ->sessionConfigEnabled && !class_exists (FullStack::class) && interface_exists (CsrfTokenManagerInterface::class);
236+ }
237+ $ this ->registerSecurityCsrfConfiguration ($ config ['csrf_protection ' ], $ container , $ loader );
238+
232239 if ($ this ->isConfigEnabled ($ container , $ config ['form ' ])) {
233240 if (!class_exists ('Symfony\Component\Form\Form ' )) {
234241 throw new LogicException ('Form support cannot be enabled as the Form component is not installed. ' );
@@ -249,8 +256,6 @@ public function load(array $configs, ContainerBuilder $container)
249256 $ container ->removeDefinition ('console.command.form_debug ' );
250257 }
251258
252- $ this ->registerSecurityCsrfConfiguration ($ config ['csrf_protection ' ], $ container , $ loader );
253-
254259 if ($ this ->isConfigEnabled ($ container , $ config ['assets ' ])) {
255260 if (!class_exists ('Symfony\Component\Asset\Package ' )) {
256261 throw new LogicException ('Asset support cannot be enabled as the Asset component is not installed. ' );
0 commit comments