diff --git a/app/Core/Session/SessionManager.php b/app/Core/Session/SessionManager.php index 0ce0254..7628992 100644 --- a/app/Core/Session/SessionManager.php +++ b/app/Core/Session/SessionManager.php @@ -79,6 +79,18 @@ class SessionManager extends Base session_destroy(); } + /** + * Get the session cookie path, without the trailing slash + * + * @access public + * @return string + */ + public function getCookiePath() + { + $path = rtrim((string) $this->helper->url->dir(), '/'); + return $path === '' ? '/' : $path; + } + /** * Define session settings * @@ -89,7 +101,7 @@ class SessionManager extends Base // Session cookie: HttpOnly and secure flags session_set_cookie_params( SESSION_DURATION, - $this->helper->url->dir() ?: '/', + $this->getCookiePath(), null, $this->request->isHTTPS(), true diff --git a/tests/units/Core/Session/SessionManagerTest.php b/tests/units/Core/Session/SessionManagerTest.php new file mode 100644 index 0000000..f2dbb0a --- /dev/null +++ b/tests/units/Core/Session/SessionManagerTest.php @@ -0,0 +1,38 @@ +assertEquals('/', $this->buildSessionManager('/index.php')->getCookiePath()); + } + + public function testCookiePathInSubDirectoryHasNoTrailingSlash() + { + $this->assertEquals('/kanboard', $this->buildSessionManager('/kanboard/index.php')->getCookiePath()); + } + + public function testCookiePathInNestedSubDirectoryHasNoTrailingSlash() + { + $this->assertEquals('/apps/kanboard', $this->buildSessionManager('/apps/kanboard/index.php')->getCookiePath()); + } + + private function buildSessionManager($phpSelf) + { + $this->container['request'] = new Request( + $this->container, + array( + 'PHP_SELF' => $phpSelf, + 'REQUEST_METHOD' => 'GET', + ) + ); + + return new SessionManager($this->container); + } +}