aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/AppFramework
diff options
context:
space:
mode:
authorRoeland Jago Douma <roeland@famdouma.nl>2020-06-19 09:31:47 +0200
committerRoeland Jago Douma <roeland@famdouma.nl>2020-06-22 08:38:44 +0200
commitfbf9772a3eafeab74cc5b3f76e7ad7cc081991bb (patch)
tree3634d762f08b16e4dbfe8ad737d37f741296ce77 /lib/private/AppFramework
parent6cd224a3a826bef2a666d70a8cf0c4368c81b181 (diff)
downloadnextcloud-server-fbf9772a3eafeab74cc5b3f76e7ad7cc081991bb.tar.gz
nextcloud-server-fbf9772a3eafeab74cc5b3f76e7ad7cc081991bb.zip
Allow to specify the cookie type for appframework responses
In general it is good to set them to Lax. But also to give devs more control over them is not a bad thing. Helps with #21474 Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Diffstat (limited to 'lib/private/AppFramework')
-rw-r--r--lib/private/AppFramework/App.php5
-rw-r--r--lib/private/AppFramework/Http/Output.php16
2 files changed, 18 insertions, 3 deletions
diff --git a/lib/private/AppFramework/App.php b/lib/private/AppFramework/App.php
index e02f372e41c..ea97ea4096d 100644
--- a/lib/private/AppFramework/App.php
+++ b/lib/private/AppFramework/App.php
@@ -151,6 +151,8 @@ class App {
if ($value['expireDate'] instanceof \DateTime) {
$expireDate = $value['expireDate']->getTimestamp();
}
+ $sameSite = $value['sameSite'] ?? 'Lax';
+
$io->setCookie(
$name,
$value['value'],
@@ -158,7 +160,8 @@ class App {
$container->getServer()->getWebRoot(),
null,
$container->getServer()->getRequest()->getServerProtocol() === 'https',
- true
+ true,
+ $sameSite
);
}
diff --git a/lib/private/AppFramework/Http/Output.php b/lib/private/AppFramework/Http/Output.php
index fd95f370360..8777c1970a6 100644
--- a/lib/private/AppFramework/Http/Output.php
+++ b/lib/private/AppFramework/Http/Output.php
@@ -92,8 +92,20 @@ class Output implements IOutput {
* @param bool $secure
* @param bool $httpOnly
*/
- public function setCookie($name, $value, $expire, $path, $domain, $secure, $httpOnly) {
+ public function setCookie($name, $value, $expire, $path, $domain, $secure, $httpOnly, $sameSite = 'Lax') {
$path = $this->webRoot ? : '/';
- setcookie($name, $value, $expire, $path, $domain, $secure, $httpOnly);
+
+ if (PHP_VERSION_ID < 70300) {
+ setcookie($name, $value, $expire, $path, $domain, $secure, $httpOnly);
+ } else {
+ setcookie($name, $value, [
+ 'expires' => $expire,
+ 'path' => $path,
+ 'domain' => $domain,
+ 'secure' => $secure,
+ 'httponly' => $httpOnly,
+ 'samesite' => $sameSite
+ ]);
+ }
}
}