Skip to content

Commit

Permalink
added better and missing wording on CSRF expiry
Browse files Browse the repository at this point in the history
  • Loading branch information
Schlaefer committed Jun 29, 2015
1 parent 3653d54 commit dbf6185
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/Controller/Component/CsrfComponent.php
Expand Up @@ -121,14 +121,14 @@ public function implementedEvents()
*/
protected function _setCookie(Request $request, Response $response)
{
$expires = new Time($this->_config['expiry']);
$expiry = new Time($this->_config['expiry']);
$value = Security::hash(Text::uuid(), 'sha1', true);

$request->params['_csrfToken'] = $value;
$response->cookie([
'name' => $this->_config['cookieName'],
'value' => $value,
'expire' => $expires->format('U'),
'expire' => $expiry->format('U'),
'path' => $request->webroot,
'secure' => $this->_config['secure'],
]);
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase/Controller/Component/CsrfComponentTest.php
Expand Up @@ -274,7 +274,7 @@ public function testConfigurationCookieCreate()
$cookie = $controller->response->cookie('token');
$this->assertNotEmpty($cookie, 'Should set a token.');
$this->assertRegExp('/^[a-f0-9]+$/', $cookie['value'], 'Should look like a hash.');
$this->assertWithinRange((new Time('+1 hour'))->format('U'), $cookie['expire'], 1);
$this->assertWithinRange((new Time('+1 hour'))->format('U'), $cookie['expire'], 1, 'session duration.');
$this->assertEquals('/dir/', $cookie['path'], 'session path.');
$this->assertTrue($cookie['secure'], 'cookie security flag missing');
}
Expand Down

0 comments on commit dbf6185

Please sign in to comment.