mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-19 02:56:15 +00:00
Fixing expiration conditions on CSRF tokens.
This commit is contained in:
parent
7f7c202f35
commit
d83c51cde9
2 changed files with 6 additions and 3 deletions
|
@ -719,9 +719,9 @@ class SecurityComponent extends Component {
|
|||
* @return An array of nonce => expires.
|
||||
*/
|
||||
protected function _expireTokens($tokens) {
|
||||
$tokenExpiryTime = strtotime($this->csrfExpires);
|
||||
$now = time();
|
||||
foreach ($tokens as $nonce => $expires) {
|
||||
if ($expires < $tokenExpiryTime) {
|
||||
if ($expires < $now) {
|
||||
unset($tokens[$nonce]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1302,12 +1302,15 @@ DIGEST;
|
|||
$this->Security->csrfExpires = '+10 minutes';
|
||||
|
||||
$this->Security->Session->write('_Token.csrfTokens', array(
|
||||
'valid' => strtotime('+30 minutes'),
|
||||
'poof' => strtotime('-11 minutes'),
|
||||
'dust' => strtotime('-20 minutes')
|
||||
));
|
||||
$this->Security->startup($this->Controller);
|
||||
$tokens = $this->Security->Session->read('_Token.csrfTokens');
|
||||
$this->assertEquals(1, count($tokens), 'Too many tokens left behind');
|
||||
$this->assertEquals(2, count($tokens), 'Too many tokens left behind');
|
||||
$this->assertNotEmpty('valid', $tokens, 'Valid token was removed.');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Reference in a new issue