Skip to content

WSSE Auth: Timing safe comparison #4183

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

Merged
merged 2 commits into from
Mar 22, 2015
Merged
Changes from all commits
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
12 changes: 11 additions & 1 deletion cookbook/security/custom_authentication_provider.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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
-----------

Expand Down Expand Up @@ -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