Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Only send samesite cookies
This makes the last remaining two cookies lax. The session cookie
itself. And the session password as well (on php 7.3 that is). Samesite
cookies are the best cookies!

Signed-off-by: Roeland Jago Douma <[email protected]>
  • Loading branch information
rullzer committed Feb 6, 2020
commit 2016e57eab1d970e6edd63370e956f462e56c86c
18 changes: 17 additions & 1 deletion lib/private/Session/CryptoWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,23 @@ public function __construct(IConfig $config,
if($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',
]
);
}
}
}
}
Expand Down
12 changes: 10 additions & 2 deletions lib/private/Session/Internal.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function __construct(string $name) {
set_error_handler([$this, 'trapError']);
$this->invoke('session_name', [$name]);
try {
$this->invoke('session_start');
$this->startSession();
} catch (\Exception $e) {
setcookie($this->invoke('session_name'), '', -1, \OC::$WEBROOT ?: '/');
}
Expand Down Expand Up @@ -106,7 +106,7 @@ public function remove(string $key) {
public function clear() {
$this->invoke('session_unset');
$this->regenerateId();
$this->invoke('session_start', [], true);
$this->startSession();
$_SESSION = [];
}

Expand Down Expand Up @@ -214,4 +214,12 @@ private function invoke(string $functionName, array $parameters = [], bool $sile
$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']]);
}
}
}