Skip to content

Commit 769cccd

Browse files
committed
Merge branch '2.3' into 2.7
* 2.3: migrate session after remember me authentication prevent timing attacks in digest auth listener mitigate CSRF timing attack vulnerability fix potential timing attack issue
2 parents 45fbe35 + ae55dcd commit 769cccd

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

Extension/Csrf/CsrfProvider/DefaultCsrfProvider.php

Lines changed: 13 additions & 1 deletion
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
@trigger_error('The '.__NAMESPACE__.'\DefaultCsrfProvider is deprecated since version 2.4 and will be removed in version 3.0. Use the \Symfony\Component\Security\Csrf\TokenStorage\NativeSessionTokenStorage class instead.', E_USER_DEPRECATED);
1517

1618
/**
@@ -61,7 +63,17 @@ public function generateCsrfToken($intention)
6163
*/
6264
public function isCsrfTokenValid($intention, $token)
6365
{
64-
return $token === $this->generateCsrfToken($intention);
66+
$expectedToken = $this->generateCsrfToken($intention);
67+
68+
if (function_exists('hash_equals')) {
69+
return hash_equals($expectedToken, $token);
70+
}
71+
72+
if (class_exists('Symfony\Component\Security\Core\Util\StringUtils')) {
73+
return StringUtils::equals($expectedToken, $token);
74+
}
75+
76+
return $token === $expectedToken;
6577
}
6678

6779
/**

0 commit comments

Comments
 (0)