diff --git a/cookbook/security/custom_authentication_provider.rst b/cookbook/security/custom_authentication_provider.rst index 47427e366d3..6328dba8fd3 100644 --- a/cookbook/security/custom_authentication_provider.rst +++ b/cookbook/security/custom_authentication_provider.rst @@ -130,7 +130,7 @@ set an authenticated token in the security context if successful. { $request = $event->getRequest(); - $wsseRegex = '/UsernameToken Username="([^"]+)", PasswordDigest="([^"]+)", Nonce="([^"]+)", Created="([^"]+)"/'; + $wsseRegex = '/UsernameToken Username="([^"]+)", PasswordDigest="([^"]+)", Nonce="([a-zA-Z0-9+/]+={0,2})", Created="([^"]+)"/'; if (!$request->headers->has('x-wsse') || 1 !== preg_match($wsseRegex, $request->headers->get('x-wsse'), $matches)) { return; } @@ -256,14 +256,17 @@ the ``PasswordDigest`` header value matches with the user's password. // Validate that the nonce is *not* used in the last 5 minutes // if it has, this could be a replay attack - if (file_exists($this->cacheDir.'/'.$nonce) && file_get_contents($this->cacheDir.'/'.$nonce) + 300 > time()) { + if ( + file_exists($this->cacheDir.'/'.md5($nonce)) + && file_get_contents($this->cacheDir.'/'.md5($nonce)) + 300 > time() + ) { throw new NonceExpiredException('Previously used nonce detected'); } // If cache directory does not exist we create it if (!is_dir($this->cacheDir)) { mkdir($this->cacheDir, 0777, true); } - file_put_contents($this->cacheDir.'/'.$nonce, time()); + file_put_contents($this->cacheDir.'/'.md5($nonce), time()); // Validate Secret $expected = base64_encode(sha1(base64_decode($nonce).$created.$secret, true));