Skip to content

Commit

Permalink
SameSite cookie support
Browse files Browse the repository at this point in the history
  • Loading branch information
nanasess committed Apr 23, 2020
1 parent b4f5ce7 commit 9e2da13
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/Eccube/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -236,11 +236,32 @@ public function initLocale()

public function initSession()
{
$root_urlpath = $this['config']['root_urlpath'] ?: '/';
$ua = array_key_exists('HTTP_USER_AGENT', $_SERVER) ? $_SERVER['HTTP_USER_AGENT'] : '';
$targetUaPatterns = array(
'/^.*iPhone; CPU iPhone OS 1[0-2].*$/',
'/^.*iPad; CPU OS 1[0-2].*$/',
'/^.*iPod touch; CPU iPhone OS 1[0-2].*$/',
'/^.*Macintosh; Intel Mac OS X.*Version\/1[0-2].*Safari.*$/',
);
$isUnsupported = array_filter($targetUaPatterns, function ($pattern) use ($ua) {
return preg_match($pattern, $ua);
});
if ($this['config']['force_ssl'] = \Eccube\Common\Constant::ENABLED && !$isUnsupported) {
if (PHP_VERSION_ID >= 70300) {
ini_set('session.cookie_path', $root_urlpath);
ini_set('session.samesite', 'none');
} else {
ini_set('session.cookie_path', $root_urlpath.'; SameSite=none');
}
} else {
ini_set('session.cookie_path', $root_urlpath);
}

$this->register(new \Silex\Provider\SessionServiceProvider(), array(
'session.storage.save_path' => $this['config']['root_dir'].'/app/cache/eccube/session',
'session.storage.options' => array(
'name' => $this['config']['cookie_name'],
'cookie_path' => $this['config']['root_urlpath'] ?: '/',
'cookie_secure' => $this['config']['force_ssl'],
'cookie_lifetime' => $this['config']['cookie_lifetime'],
'cookie_httponly' => true,
Expand Down

0 comments on commit 9e2da13

Please sign in to comment.