Skip to content

Commit

Permalink
Blackhole requests when the action is the blackhole callback.
Browse files Browse the repository at this point in the history
When a user requests the blackhole callback as an action we should
blackhole that request. The blackhole callback should not be URL
accessible.

Fixes #3496
  • Loading branch information
markstory committed Dec 29, 2012
1 parent 2ba117e commit 1117ad2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lib/Cake/Controller/Component/SecurityComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,10 @@ public function startup(Controller $controller) {
$controller->request->params['requested'] != 1
);

if ($this->_action == $this->blackHoleCallback) {
return $this->blackhole($controller, 'auth');
}

if ($isPost && $isNotRequestAction && $this->validatePost) {
if ($this->_validatePost($controller) === false) {
return $this->blackHole($controller, 'auth');
Expand Down Expand Up @@ -309,11 +313,10 @@ public function requireAuth() {
* @throws BadRequestException
*/
public function blackHole(Controller $controller, $error = '') {
if ($this->blackHoleCallback == null) {
if (!$this->blackHoleCallback) {
throw new BadRequestException(__d('cake_dev', 'The request has been black-holed'));
} else {
return $this->_callback($controller, $this->blackHoleCallback, array($error));
}
return $this->_callback($controller, $this->blackHoleCallback, array($error));
}

/**
Expand Down
16 changes: 16 additions & 0 deletions lib/Cake/Test/Case/Controller/Component/SecurityComponentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,22 @@ public function testBlackholeWithBrokenCallback() {
$this->Controller->Security->blackHole($this->Controller, 'csrf');
}

/**
* Ensure that directly requesting the blackholeCallback as the controller
* action results in an exception.
*
* @return void
*/
public function testExceptionWhenActionIsBlackholeCallback() {
$this->Controller->request->addParams(array(
'controller' => 'posts',
'action' => 'fail'
));
$this->assertFalse($this->Controller->failed);
$this->Controller->Security->startup($this->Controller);
$this->assertTrue($this->Controller->failed, 'Request was blackholed.');
}

/**
* test that initialize can set properties.
*
Expand Down

0 comments on commit 1117ad2

Please sign in to comment.