Browse Source

Merge pull request #12472 from cakephp/digest-sidechannel

Fix potential timing side channel in digest auth.
Mark Story 7 years ago
parent
commit
e8a70612a0
1 changed files with 9 additions and 2 deletions
  1. 9 2
      src/Auth/BaseAuthenticate.php

+ 9 - 2
src/Auth/BaseAuthenticate.php

@@ -117,8 +117,15 @@ abstract class BaseAuthenticate implements EventListenerInterface
         $result = $this->_query($username)->first();
 
         if (empty($result)) {
-            $hasher = $this->passwordHasher();
-            $hasher->hash((string)$password);
+            // Waste time hashing the password, to prevent
+            // timing side-channels. However, don't hash
+            // null passwords as authentication systems
+            // like digest auth don't use passwords
+            // and hashing *could* create a timing side-channel.
+            if ($password !== null) {
+                $hasher = $this->passwordHasher();
+                $hasher->hash($password);
+            }
 
             return false;
         }