Skip to content

Commit f9eefa3

Browse files
xabbuhfabpot
authored andcommitted
mitigate CSRF timing attack vulnerability
1 parent 5de5aa2 commit f9eefa3

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

Extension/Csrf/CsrfProvider/DefaultCsrfProvider.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
namespace Symfony\Component\Form\Extension\Csrf\CsrfProvider;
1313

14+
use Symfony\Component\Security\Core\Util\StringUtils;
15+
1416
/**
1517
* Default implementation of CsrfProviderInterface.
1618
*
@@ -54,6 +56,16 @@ public function generateCsrfToken($intention)
5456
*/
5557
public function isCsrfTokenValid($intention, $token)
5658
{
59+
$expectedToken = $this->generateCsrfToken($intention);
60+
61+
if (function_exists('hash_equals')) {
62+
return hash_equals($expectedToken, $token);
63+
}
64+
65+
if (class_exists('Symfony\Component\Security\Core\Util\StringUtils')) {
66+
return StringUtils::equals($expectedToken, $token);
67+
}
68+
5769
return $token === $this->generateCsrfToken($intention);
5870
}
5971

0 commit comments

Comments
 (0)