-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
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
4668 document isCsrfTokenValid #5325
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -440,7 +440,7 @@ If you want to redirect the user to another page, use the ``redirectToRoute()`` | |
} | ||
|
||
.. versionadded:: 2.6 | ||
The ``redirectToRoute()`` method was added in Symfony 2.6. Previously (and still now), you | ||
The ``redirectToRoute()`` method was introduced in Symfony 2.6. Previously (and still now), you | ||
could use ``redirect()`` and ``generateUrl()`` together for this (see the example above). | ||
|
||
Or, if you want to redirect externally, just use ``redirect()`` and pass it the URL:: | ||
|
@@ -803,6 +803,29 @@ 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\\Bundle\\FrameworkBundle\\Controller\\Controller::isCsrfTokenValid` | ||
method to check the CSRF token:: | ||
|
||
if ($this->isCsrfTokenValid('token_id', $submittedToken)) { | ||
// ... do something, like deleting an object | ||
} | ||
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. For consistency with other parts of the doc, there should be a comment showing the alternative not using the shortcut |
||
|
||
.. versionadded:: 2.6 | ||
The ``isCsrfTokenValid()`` shortcut method was introduced in Symfony 2.6. | ||
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 prefer something like this: .. versionadded:: 2.6
The ``isCsrfTokenValid()`` shortcut method was introduced in Symfony 2.6.
It is equivalent to executing the following code::
use Symfony\Component\Security\Csrf\CsrfToken;
$this->get('security.csrf.token_manager')->isTokenValid(new CsrfToken('token_id', 'TOKEN')); |
||
|
||
Previously you would use:: | ||
|
||
use Symfony\Component\Security\Csrf\CsrfToken; | ||
|
||
$this->get('security.csrf.token_manager')->isTokenValid(new CsrfToken('token_id', 'TOKEN')); | ||
|
||
Final Thoughts | ||
-------------- | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 think "[...] to use the Symfony Form component." is better