Skip to content

Commit 9f1ef22

Browse files
committed
security #4183 WSSE Auth: Timing safe comparison (merk)
This PR was merged into the 2.3 branch. Discussion ---------- WSSE Auth: Timing safe comparison | Q | A | ------------- | --- | Doc fix? | yes | New docs? | no | Applies to | 2.3+ | Fixed tickets | n/a I believe we should be providing examples that use timing safe operations when comparing password hashes, or any other kind of sensitive comparison that could leak timing information. Commits ------- 822f91a Add note about the constant time comparison 098afc3 WSSE Auth: Timing safe comparison
2 parents e36faec + 822f91a commit 9f1ef22

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

cookbook/security/custom_authentication_provider.rst

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ the ``PasswordDigest`` header value matches with the user's password.
202202
use Symfony\Component\Security\Core\Exception\NonceExpiredException;
203203
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
204204
use AppBundle\Security\Authentication\Token\WsseUserToken;
205+
use Symfony\Component\Security\Core\Util\StringUtils;
205206
206207
class WsseProvider implements AuthenticationProviderInterface
207208
{
@@ -260,7 +261,7 @@ the ``PasswordDigest`` header value matches with the user's password.
260261
// Validate Secret
261262
$expected = base64_encode(sha1(base64_decode($nonce).$created.$secret, true));
262263
263-
return $digest === $expected;
264+
return StringUtils::equals($expected, $digest);
264265
}
265266
266267
public function supports(TokenInterface $token)
@@ -277,6 +278,14 @@ the ``PasswordDigest`` header value matches with the user's password.
277278
provider for the given token. In the case of multiple providers, the
278279
authentication manager will then move to the next provider in the list.
279280

281+
.. note::
282+
283+
The comparsion of the expected and the provided digests uses a constant
284+
time comparison provided by the
285+
:method:`Symfony\\Component\\Security\\Core\\Util\\StringUtils::equals`
286+
method of the ``StringUtils`` class. It is used to mitigate possible
287+
`timing attacks`_.
288+
280289
The Factory
281290
-----------
282291

@@ -608,3 +617,4 @@ in the factory and consumed or passed to the other classes in the container.
608617

609618
.. _`WSSE`: http://www.xml.com/pub/a/2003/12/17/dive.html
610619
.. _`nonce`: http://en.wikipedia.org/wiki/Cryptographic_nonce
620+
.. _`timing attacks`: http://en.wikipedia.org/wiki/Timing_attack

0 commit comments

Comments
 (0)