8000 document old way of checking validity of CSRF token by snoek09 · Pull Request #5818 · symfony/symfony-docs · GitHub
[go: up one dir, main page]

Skip to content

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

Closed
wants to merge 5 commits into from
Closed
Changes from 1 commit
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
Next Next commit
document old way of checking validity of CSRF token
  • Loading branch information
Henry Snoek committed Oct 20, 2015
commit d6cfb3699eb034cfa733639529a4bd27c12a4227
16 changes: 16 additions & 0 deletions book/controller.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DELETE in backticks?

Copy link
Author

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

:method:`Symfony\\Component\\Form\\Extension\\Csrf\\CsrfProvider\\CsrfProviderAdapter::isTokenValid`
method to check the CSRF token::

use Symfony\Component\Security\Csrf\CsrfToken;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The security-csrf component does not exist in 2.3


$this->get('security.csrf.token_manager')->isTokenValid(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this service only exists in Symfony 2.4+

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, will change this to form.csrf_provider.

new CsrfToken('token_id', 'TOKEN')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would use a real secret instead of the string TOKEN

);

Final Thoughts
--------------

Expand Down
0