-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
document old way of checking validity of CSRF token #5818
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
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -794,6 +794,22 @@ Just like when creating a controller for a route, the order of the arguments of | |
order of the arguments, Symfony will still pass the correct value to each | ||
variable. | ||
|
||
Checking the Validity of a CSRF Token | ||
------------------------------------- | ||
|
||
Sometimes you want to use CSRF protection in an action where you don't want to use a | ||
Symfony form. | ||
|
||
If, for example, you're doing a DELETE action, you can use the | ||
:method:`Symfony\\Component\\Form\\Extension\\Csrf\\CsrfProvider\\DefaultCsrfProvider::isCsrfTokenValid` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this should link to the method in the interface instead (it doesn't matter which implementation is registered as the service). |
||
method to check the CSRF token:: | ||
|
||
$csrf = $this->container->get('form.csrf_provider'); | ||
$intention = 'authenticate'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does it make sense to show this without showing a template? When you generate the CSRF token in the template, you would need to also include |
||
$token = $csrf->generateCsrfToken($intention); | ||
|
||
$csrf->isCsrfTokenValid($intention, $token); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about an if (!$csrf->isCsrfTokenValid($intention, $token)) {
// CSRF token invalid! Do something, like redirect with an error
} |
||
|
||
Final Thoughts | ||
-------------- | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DELETE in backticks?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I checked the docs for mentions of HTTP methods. In a sentence they are never in backticks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍