Skip to content

Commit

Permalink
Updating AuthComponent::startup() so that being redirected to loginAc…
Browse files Browse the repository at this point in the history
…tion with no Auth.redirect value in the session and a non empty loginRedirect defined, the Auth.redirect value is not overwritten. This prevents redirection to already accessible pages. Test cases updated.

Fixes #173
  • Loading branch information
markstory committed Jan 12, 2010
1 parent 6147de7 commit a0c3c4b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cake/libs/controller/components/auth.php
Expand Up @@ -337,7 +337,7 @@ function startup(&$controller) {
if ($loginAction == $url) {
$model =& $this->getModel();
if (empty($controller->data) || !isset($controller->data[$model->alias])) {
if (!$this->Session->check('Auth.redirect') && env('HTTP_REFERER')) {
if (!$this->Session->check('Auth.redirect') && !$this->loginRedirect && env('HTTP_REFERER')) {
$this->Session->write('Auth.redirect', $controller->referer(null, true));
}
return false;
Expand Down
25 changes: 25 additions & 0 deletions cake/tests/cases/libs/controller/components/auth.test.php
Expand Up @@ -623,6 +623,31 @@ function testLogin() {
$this->Controller->Session->delete('Auth');
}

/**
* test that being redirected to the login page, with no post data does
* not set the session value. Saving the session value in this circumstance
* can cause the user to be redirected to an already public page.
*
* @return void
*/
function testLoginActionNotSettingAuthRedirect() {
$_referer = $_SERVER['HTTP_REFERER'];
$_SERVER['HTTP_REFERER'] = '/pages/display/about';

$this->Controller->data = array();
$this->Controller->params = Router::parse('auth_test/login');
$this->Controller->params['url']['url'] = 'auth_test/login';
$this->Controller->Session->delete('Auth');

$this->Controller->Auth->loginRedirect = '/users/dashboard';
$this->Controller->Auth->loginAction = 'auth_test/login';
$this->Controller->Auth->userModel = 'AuthUser';

$this->Controller->Auth->startup($this->Controller);
$redirect = $this->Controller->Session->read('Auth.redirect');
$this->assertNull($redirect);
}

/**
* testAuthorizeFalse method
*
Expand Down

0 comments on commit a0c3c4b

Please sign in to comment.