Skip to content

Commit 76c0473

Browse files
committed
[Security] iscsrftokenvalid-attribute-controller-usage
1 parent b36bab2 commit 76c0473

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

security/csrf.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,20 @@ Suppose you want a CSRF token per item, so in the template you have something li
273273
<button type="submit">Delete item</button>
274274
</form>
275275

276+
In addition :class:`Symfony\\Component\\Security\\Http\\Attribute\\IsCsrfTokenValid`
277+
attribute can be applied to a controller class.
278+
This will cause the CSRF token validation to be executed for all routes defined within the controller::
279+
280+
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
281+
use Symfony\Component\Security\Http\Attribute\IsCsrfTokenValid;
282+
// ...
283+
284+
#[IsCsrfTokenValid('controller')]
285+
final class FooController extends AbstractController
286+
{
287+
// ...
288+
}
289+
276290
The :class:`Symfony\\Component\\Security\\Http\\Attribute\\IsCsrfTokenValid`
277291
attribute also accepts an :class:`Symfony\\Component\\ExpressionLanguage\\Expression`
278292
object evaluated to the id::

0 commit comments

Comments
 (0)