Skip to content

Commit

Permalink
fix secure cookie (#4566)
Browse files Browse the repository at this point in the history
  • Loading branch information
aynsix authored Dec 20, 2024
1 parent 342bf69 commit 0e0b8d2
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
16 changes: 15 additions & 1 deletion lib/Alchemy/Phrasea/Controller/Root/RootController.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,21 @@ public function getRoot()
public function setLocale($locale)
{
$response = $this->app->redirectPath('root');
$response->headers->setCookie(new Cookie('locale', $locale, 0, '/', null, true, false));

$cookiePath = ini_get('session.cookie_path');
$cookieDomain = ini_get('session.cookie_domain');
$cookieHttpOnly = ini_get('session.cookie_httponly');
$cookieSecure = ini_get('session.cookie_secure');

$response->headers->setCookie(new Cookie(
'locale',
$locale,
0,
$cookiePath,
empty($cookieDomain)? null : $cookieDomain,
$cookieSecure ? true: false,
$cookieHttpOnly ? true : false
));

$authenticatedUser = $this->getAuthenticatedUser();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,20 @@ public function addLocaleCookie(FilterResponseEvent $event)
$cookies = $event->getRequest()->cookies;

if (isset($this->locale) && (false === $cookies->has('locale') || $cookies->get('locale') !== $this->locale)) {
$event->getResponse()->headers->setCookie(new Cookie('locale', $this->locale, 0, '/', null, true, false));
$cookiePath = ini_get('session.cookie_path');
$cookieDomain = ini_get('session.cookie_domain');
$cookieHttpOnly = ini_get('session.cookie_httponly');
$cookieSecure = ini_get('session.cookie_secure');

$event->getResponse()->headers->setCookie(new Cookie(
'locale',
$this->locale,
0,
$cookiePath,
empty($cookieDomain)? null : $cookieDomain,
$cookieSecure ? true: false,
$cookieHttpOnly ? true : false
));
}
}
}

0 comments on commit 0e0b8d2

Please sign in to comment.