Skip to content

Commit

Permalink
AuthComponent should only compare paths.
Browse files Browse the repository at this point in the history
request->getRequestTarget() returns query string data in addition to the
path. This causes comparison issues with loginAction that is generally
path only.

Refs #11943
  • Loading branch information
markstory committed Apr 17, 2018
1 parent 887dc4d commit 55d8332
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Controller/Component/AuthComponent.php
Expand Up @@ -439,8 +439,8 @@ protected function _loginActionRedirectUrl()
*/
protected function _isLoginAction(Controller $controller)
{
$url = $controller->request->getRequestTarget();
$url = Router::normalize($url);
$uri = $controller->request->getUri();
$url = Router::normalize($uri->getPath());
$loginAction = Router::normalize($this->_config['loginAction']);

return $loginAction === $url;
Expand Down
30 changes: 30 additions & 0 deletions tests/TestCase/Controller/Component/AuthComponentTest.php
Expand Up @@ -830,6 +830,36 @@ public function testNoLoginRedirectForAuthenticatedUser()
$this->assertNull($this->Controller->testUrl);
}

/**
* testNoLoginRedirectForAuthenticatedUser method
*
* @return void
* @triggers Controller.startup $this->Controller
*/
public function testStartupLoginActionIgnoreQueryString()
{
$request = new ServerRequest([
'params' => [
'plugin' => null,
'controller' => 'auth_test',
'action' => 'login'
],
'query' => ['redirect' => '/admin/articles'],
'url' => '/auth_test/login?redirect=%2Fadmin%2Farticles',
'session' => $this->Auth->session
]);
$this->Controller->request = $request;

$this->Auth->session->clear();
$this->Auth->setConfig('authenticate', ['Form']);
$this->Auth->setConfig('authorize', false);
$this->Auth->setConfig('loginAction', ['controller' => 'auth_test', 'action' => 'login']);

$event = new Event('Controller.startup', $this->Controller);
$return = $this->Auth->startup($event);
$this->assertNull($return);
}

/**
* Default to loginRedirect, if set, on authError.
*
Expand Down

0 comments on commit 55d8332

Please sign in to comment.