Skip to content

Commit

Permalink
Fixing Router::reverse() serializing all of _Token.
Browse files Browse the repository at this point in the history
Removing CSRF tokens from the parameters SecurityComponent exports.
Updating tests for both Router and SecurityComponent.
Fixes #1697
  • Loading branch information
markstory committed May 17, 2011
1 parent f2e953d commit 6289f20
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 3 deletions.
5 changes: 4 additions & 1 deletion lib/Cake/Controller/Component/SecurityComponent.php
Expand Up @@ -495,8 +495,11 @@ protected function _generateToken($controller) {
if ($this->csrfCheck && ($this->csrfUseOnce || empty($tokenData['csrfTokens'])) ) {
$token['csrfTokens'][$authKey] = strtotime($this->csrfExpires);
}
$controller->request->params['_Token'] = $token;
$this->Session->write('_Token', $token);
$controller->request->params['_Token'] = array(
'key' => $token['key'],
'disabledFields' => $token['disabledFields']
);
return true;
}

Expand Down
3 changes: 2 additions & 1 deletion lib/Cake/Routing/Router.php
Expand Up @@ -1029,7 +1029,8 @@ public static function reverse($params, $full = false) {

unset(
$params['pass'], $params['named'], $params['paging'], $params['models'], $params['url'], $url['url'],
$params['autoRender'], $params['bare'], $params['requested'], $params['return']
$params['autoRender'], $params['bare'], $params['requested'], $params['return'],
$params['_Token']
);
$params = array_merge($params, $pass, $named);
if (!empty($url)) {
Expand Down
Expand Up @@ -996,6 +996,7 @@ function testCsrfSettings() {
$token = $this->Security->Session->read('_Token');
$this->assertEquals(count($token['csrfTokens']), 1, 'Missing the csrf token.');
$this->assertEquals(strtotime('+10 minutes'), current($token['csrfTokens']), 'Token expiry does not match');
$this->assertEquals(array('key', 'disabledFields'), array_keys($this->Controller->request->params['_Token']), 'Keys don not match');
}

/**
Expand Down
3 changes: 2 additions & 1 deletion lib/Cake/Test/Case/Routing/RouterTest.php
Expand Up @@ -2285,7 +2285,8 @@ function testRouterReverse() {
'autoRender' => 1,
'bare' => 1,
'return' => 1,
'requested' => 1
'requested' => 1,
'_Token' => array('key' => 'sekret')
);
$result = Router::reverse($params);
$this->assertEqual($result, '/posts/view/1');
Expand Down

0 comments on commit 6289f20

Please sign in to comment.