Skip to content
Snippets Groups Projects
Unverified Commit 3b14cec7 authored by Roeland Jago Douma's avatar Roeland Jago Douma Committed by GitHub
Browse files

Merge pull request #17075 from nextcloud/enh/samesitecookies

Only send samesite cookies
parents 730af001 2016e57e
No related branches found
No related tags found
No related merge requests found
...@@ -86,7 +86,23 @@ class CryptoWrapper { ...@@ -86,7 +86,23 @@ class CryptoWrapper {
if($webRoot === '') { if($webRoot === '') {
$webRoot = '/'; $webRoot = '/';
} }
setcookie(self::COOKIE_NAME, $this->passphrase, 0, $webRoot, '', $secureCookie, true);
if (PHP_VERSION_ID < 70300) {
setcookie(self::COOKIE_NAME, $this->passphrase, 0, $webRoot, '', $secureCookie, true);
} else {
setcookie(
self::COOKIE_NAME,
$this->passphrase,
[
'expires' => 0,
'path' => $webRoot,
'domain' => '',
'secure' => $secureCookie,
'httponly' => true,
'samesite' => 'Lax',
]
);
}
} }
} }
} }
......
...@@ -56,7 +56,7 @@ class Internal extends Session { ...@@ -56,7 +56,7 @@ class Internal extends Session {
set_error_handler([$this, 'trapError']); set_error_handler([$this, 'trapError']);
$this->invoke('session_name', [$name]); $this->invoke('session_name', [$name]);
try { try {
$this->invoke('session_start'); $this->startSession();
} catch (\Exception $e) { } catch (\Exception $e) {
setcookie($this->invoke('session_name'), '', -1, \OC::$WEBROOT ?: '/'); setcookie($this->invoke('session_name'), '', -1, \OC::$WEBROOT ?: '/');
} }
...@@ -106,7 +106,7 @@ class Internal extends Session { ...@@ -106,7 +106,7 @@ class Internal extends Session {
public function clear() { public function clear() {
$this->invoke('session_unset'); $this->invoke('session_unset');
$this->regenerateId(); $this->regenerateId();
$this->invoke('session_start', [], true); $this->startSession();
$_SESSION = []; $_SESSION = [];
} }
...@@ -214,4 +214,12 @@ class Internal extends Session { ...@@ -214,4 +214,12 @@ class Internal extends Session {
$this->trapError($e->getCode(), $e->getMessage()); $this->trapError($e->getCode(), $e->getMessage());
} }
} }
private function startSession() {
if (PHP_VERSION_ID < 70300) {
$this->invoke('session_start');
} else {
$this->invoke('session_start', [['cookie_samesite' => 'Lax']]);
}
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment