10000 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
Prev Previous commit
Next Next commit
use generateCsrfToken()
  • Loading branch information
Henry Snoek committed Oct 22, 2015
commit 73209d05ff21c223374a21668a40492fa591db1f
5 changes: 4 additions & 1 deletion book/controller.rst
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,10 @@ If, for example, you're doing a DELETE action, you can use the
method to check the CSRF token::

$csrf = $this->container->get('form.csrf_provider');
$csrf->isCsrfTokenValid('authenticate', new CsrfToken('token_id', 'TOKEN'));
$intention = 'authenticate';
Copy link
Member

Choose a reason for hiding this comment

The 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 authenticate then, right?

$token = $csrf->generateCsrfToken($intention);

$csrf->isCsrfTokenValid($intention, $token);
Copy link
Member

Choose a reason for hiding this comment

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

How about an if statement to be more realistic:

if (!$csrf->isCsrfTokenValid($intention, $token)) {
    // CSRF token invalid! Do something, like redirect with an error
}


Final Thoughts
--------------
Expand Down
0