diff --git a/security/csrf.rst b/security/csrf.rst index 21496aac1f8..70c88d8df85 100644 --- a/security/csrf.rst +++ b/security/csrf.rst @@ -273,6 +273,20 @@ Suppose you want a CSRF token per item, so in the template you have something li +In addition :class:`Symfony\\Component\\Security\\Http\\Attribute\\IsCsrfTokenValid` +attribute can be applied to a controller class. +This will cause the CSRF token validation to be executed for all routes defined within the controller:: + + use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; + use Symfony\Component\Security\Http\Attribute\IsCsrfTokenValid; + // ... + + #[IsCsrfTokenValid('controller')] + final class FooController extends AbstractController + { + // ... + } + The :class:`Symfony\\Component\\Security\\Http\\Attribute\\IsCsrfTokenValid` attribute also accepts an :class:`Symfony\\Component\\ExpressionLanguage\\Expression` object evaluated to the id::