Skip to content

Commit

Permalink
Hash nonce when using as file name
Browse files Browse the repository at this point in the history
  • Loading branch information
wouterj committed Feb 6, 2016
1 parent 5f125f3 commit 673fd71
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions cookbook/security/custom_authentication_provider.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down

0 comments on commit 673fd71

Please sign in to comment.