Skip to content

Commit dbf6185

Browse files
committed
added better and missing wording on CSRF expiry
1 parent 3653d54 commit dbf6185

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

src/Controller/Component/CsrfComponent.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,14 +121,14 @@ public function implementedEvents()
121121
*/
122122
protected function _setCookie(Request $request, Response $response)
123123
{
124-
$expires = new Time($this->_config['expiry']);
124+
$expiry = new Time($this->_config['expiry']);
125125
$value = Security::hash(Text::uuid(), 'sha1', true);
126126

127127
$request->params['_csrfToken'] = $value;
128128
$response->cookie([
129129
'name' => $this->_config['cookieName'],
130130
'value' => $value,
131-
'expire' => $expires->format('U'),
131+
'expire' => $expiry->format('U'),
132132
'path' => $request->webroot,
133133
'secure' => $this->_config['secure'],
134134
]);

tests/TestCase/Controller/Component/CsrfComponentTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ public function testConfigurationCookieCreate()
274274
$cookie = $controller->response->cookie('token');
275275
$this->assertNotEmpty($cookie, 'Should set a token.');
276276
$this->assertRegExp('/^[a-f0-9]+$/', $cookie['value'], 'Should look like a hash.');
277-
$this->assertWithinRange((new Time('+1 hour'))->format('U'), $cookie['expire'], 1);
277+
$this->assertWithinRange((new Time('+1 hour'))->format('U'), $cookie['expire'], 1, 'session duration.');
278278
$this->assertEquals('/dir/', $cookie['path'], 'session path.');
279279
$this->assertTrue($cookie['secure'], 'cookie security flag missing');
280280
}

0 commit comments

Comments
 (0)