Skip to content

Commit

Permalink
Fixing issues with CSRF token failure and requestAction.
Browse files Browse the repository at this point in the history
Fixes #1900
  • Loading branch information
markstory committed Aug 13, 2011
1 parent 1df8de6 commit 3014d3f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/Cake/Controller/Component/SecurityComponent.php
Expand Up @@ -203,17 +203,17 @@ public function startup($controller) {
$this->_authRequired($controller);

$isPost = ($this->request->is('post') || $this->request->is('put'));
$isRequestAction = (
$isNotRequestAction = (
!isset($controller->request->params['requested']) ||
$controller->request->params['requested'] != 1
);

if ($isPost && $isRequestAction && $this->validatePost) {
if ($isPost && $isNotRequestAction && $this->validatePost) {
if ($this->_validatePost($controller) === false) {
return $this->blackHole($controller, 'auth');
}
}
if ($isPost && $this->csrfCheck) {
if ($isPost && $isNotRequestAction && $this->csrfCheck) {
if ($this->_validateCsrf($controller) === false) {
return $this->blackHole($controller, 'csrf');
}
Expand Down
17 changes: 17 additions & 0 deletions lib/Cake/Test/Case/Controller/Component/SecurityComponentTest.php
Expand Up @@ -1036,6 +1036,23 @@ public function testBlackHoleNotDeletingSessionInformation() {
$this->assertTrue($this->Controller->Security->Session->check('_Token'), '_Token was deleted by blackHole %s');
}

/**
* test that csrf checks are skipped for request action.
*
* @return void
*/
public function testCsrfSkipRequestAction() {
$_SERVER['REQUEST_METHOD'] = 'POST';

$this->Security->validatePost = false;
$this->Security->csrfCheck = true;
$this->Security->csrfExpires = '+10 minutes';
$this->Controller->request->params['requested'] = 1;
$this->Security->startup($this->Controller);

$this->assertFalse($this->Controller->failed, 'fail() was called.');
}

/**
* test setting
*
Expand Down

0 comments on commit 3014d3f

Please sign in to comment.