diff --git a/cookbook/security/custom_authentication_provider.rst b/cookbook/security/custom_authentication_provider.rst index b3e8c2535ae..fdbb4fe2a42 100644 --- a/cookbook/security/custom_authentication_provider.rst +++ b/cookbook/security/custom_authentication_provider.rst @@ -201,6 +201,7 @@ the ``PasswordDigest`` header value matches with the user's password. use Symfony\Component\Security\Core\Exception\AuthenticationException; use Symfony\Component\Security\Core\Exception\NonceExpiredException; use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; + use Symfony\Component\Security\Core\Util\StringUtils; use Acme\DemoBundle\Security\Authentication\Token\WsseUserToken; class WsseProvider implements AuthenticationProviderInterface @@ -260,7 +261,7 @@ the ``PasswordDigest`` header value matches with the user's password. // Validate Secret $expected = base64_encode(sha1(base64_decode($nonce).$created.$secret, true)); - return $digest === $expected; + return StringUtils::equals($expected, $digest); } public function supports(TokenInterface $token) @@ -277,6 +278,14 @@ the ``PasswordDigest`` header value matches with the user's password. provider for the given token. In the case of multiple providers, the authentication manager will then move to the next provider in the list. +.. note:: + + The comparsion of the expected and the provided digests uses a constant + time comparison provided by the + :method:`Symfony\\Component\\Security\\Core\\Util\\StringUtils::equals` + method of the ``StringUtils`` class. It is used to mitigate possible + `timing attacks`_. + The Factory ----------- @@ -604,3 +613,4 @@ in the factory and consumed or passed to the other classes in the container. .. _`WSSE`: http://www.xml.com/pub/a/2003/12/17/dive.html .. _`nonce`: http://en.wikipedia.org/wiki/Cryptographic_nonce +.. _`timing attacks`: http://en.wikipedia.org/wiki/Timing_attack