Skip to content

Commit

Permalink
Set default cookie path to webroot instead of base.
Browse files Browse the repository at this point in the history
Refs #5404
  • Loading branch information
ADmad committed Dec 13, 2014
1 parent 43f053f commit 2f3d50b
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/Controller/Component/CookieComponent.php
Expand Up @@ -43,7 +43,7 @@ class CookieComponent extends Component {
* If path is set to '/foo/', the cookie will only be available within the
* /foo/ directory and all sub-directories such as /foo/bar/ of domain.
* The default value is base path of app. For e.g. if your app is running
* under a subfolder "cakeapp" of document root the path would be "/cakeapp"
* under a subfolder "cakeapp" of document root the path would be "/cakeapp/"
* else it would be "/".
* - `domain` - The domain that the cookie is available. To make the cookie
* available on all subdomains of example.com set domain to '.example.com'.
Expand Down Expand Up @@ -137,7 +137,7 @@ public function initialize(array $config) {
}

if (empty($this->_config['path'])) {
$this->config('path', $this->_request->base ?: '/');
$this->config('path', $this->_request->webroot);
}

if ($controller && isset($controller->response)) {
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/Component/CsrfComponent.php
Expand Up @@ -122,7 +122,7 @@ protected function _setCookie(Request $request, Response $response) {
'name' => $this->_config['cookieName'],
'value' => $value,
'expiry' => $this->_config['expiry'],
'path' => $request->base,
'path' => $request->webroot,
'secure' => $this->_config['secure'],
]);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Network/Request.php
Expand Up @@ -168,7 +168,7 @@ public static function createFromGlobals() {
list($base, $webroot) = static::_base();
$sessionConfig = (array)Configure::read('Session') + [
'defaults' => 'php',
'cookiePath' => $base
'cookiePath' => $webroot
];

$config = array(
Expand Down
8 changes: 4 additions & 4 deletions tests/TestCase/Controller/Component/CsrfComponentTest.php
Expand Up @@ -59,7 +59,7 @@ public function testSettingCookie() {
$_SERVER['REQUEST_METHOD'] = 'GET';

$controller = $this->getMock('Cake\Controller\Controller', ['redirect']);
$controller->request = new Request(['base' => '/dir']);
$controller->request = new Request(['webroot' => '/dir/']);
$controller->response = new Response();

$event = new Event('Controller.startup', $controller);
Expand All @@ -69,7 +69,7 @@ public function testSettingCookie() {
$this->assertNotEmpty($cookie, 'Should set a token.');
$this->assertRegExp('/^[a-f0-9]+$/', $cookie['value'], 'Should look like a hash.');
$this->assertEquals(0, $cookie['expiry'], 'session duration.');
$this->assertEquals('/dir', $cookie['path'], 'session path.');
$this->assertEquals('/dir/', $cookie['path'], 'session path.');

$this->assertEquals($cookie['value'], $controller->request->params['_csrfToken']);
}
Expand Down Expand Up @@ -204,7 +204,7 @@ public function testConfigurationCookieCreate() {
$_SERVER['REQUEST_METHOD'] = 'GET';

$controller = $this->getMock('Cake\Controller\Controller', ['redirect']);
$controller->request = new Request(['base' => '/dir']);
$controller->request = new Request(['webroot' => '/dir/']);
$controller->response = new Response();

$component = new CsrfComponent($this->registry, [
Expand All @@ -221,7 +221,7 @@ public function testConfigurationCookieCreate() {
$this->assertNotEmpty($cookie, 'Should set a token.');
$this->assertRegExp('/^[a-f0-9]+$/', $cookie['value'], 'Should look like a hash.');
$this->assertEquals(90, $cookie['expiry'], 'session duration.');
$this->assertEquals('/dir', $cookie['path'], 'session path.');
$this->assertEquals('/dir/', $cookie['path'], 'session path.');
$this->assertTrue($cookie['secure'], 'cookie security flag missing');
}

Expand Down

0 comments on commit 2f3d50b

Please sign in to comment.