Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Security] Add usage example for IsCsrfTokenValid attribute on controller classes #20975

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: 7.3
Choose a base branch
Loading
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions 14 security/csrf.rst
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,20 @@ Suppose you want a CSRF token per item, so in the template you have something li
<button type="submit">Delete item</button>
</form>

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::
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.