Closed
Description
Symfony version(s) affected: 5.3 beta2
Description
A csrf token put inside a twig template with the csrf_token()
helper can't be validated any-more. This only occurs when using the test environment (PHPUnit 7.5.20) .
How to reproduce
Twig :
<input type="hidden" name="_token" value="{{ csrf_token('delete'~event.id) }}">
Controller :
if ($this->isCsrfTokenValid('delete'.$event->getId(), $request->request->get('_token'))) {
Test :
$csrfToken = self::getContainer()->get('security.csrf.token_manager')->getToken('delete1')->getValue();
echo $csrfToken;
$client->request('DELETE', '/event/delete/1', [
'_token' => $csrfToken,
]);
Possible Solution
Seems related to the test environment as everything works correctly in dev or prod.
Additional context
- Everything was OK with 5.2.6.
- The problem occurs everywhere
csrf_token(
is used in a template