summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorRoeland Jago Douma <rullzer@users.noreply.github.com>2020-06-23 14:04:53 +0200
committerGitHub <noreply@github.com>2020-06-23 14:04:53 +0200
commit6b5db20fc9f101478809c0d34f630d35dfcd9d93 (patch)
tree9507b14784f6e9e3d9db9bb1e8c911d39afe3058 /lib
parent86fdf17eedef0974162e09c9cf906bc49bcffd05 (diff)
parent002e1f1ed266f8f038fbb41c9142e3842340c1f1 (diff)
downloadnextcloud-server-6b5db20fc9f101478809c0d34f630d35dfcd9d93.tar.gz
nextcloud-server-6b5db20fc9f101478809c0d34f630d35dfcd9d93.zip
Merge pull request #21526 from nextcloud/backport/21479/stable19
[stable19] Allow to specify the cookie type for appframework responses
Diffstat (limited to 'lib')
-rw-r--r--lib/private/AppFramework/App.php5
-rw-r--r--lib/private/AppFramework/Http/Output.php16
-rw-r--r--lib/public/AppFramework/Http/IOutput.php3
-rw-r--r--lib/public/AppFramework/Http/Response.php5
4 files changed, 23 insertions, 6 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
+ ]);
+ }
}
}
diff --git a/lib/public/AppFramework/Http/IOutput.php b/lib/public/AppFramework/Http/IOutput.php
index 888c9f45b23..a162b528dbe 100644
--- a/lib/public/AppFramework/Http/IOutput.php
+++ b/lib/public/AppFramework/Http/IOutput.php
@@ -72,7 +72,8 @@ interface IOutput {
* @param string $domain
* @param bool $secure
* @param bool $httpOnly
+ * @param string $sameSite (added in 19.0.1)
* @since 8.1.0
*/
- public function setCookie($name, $value, $expire, $path, $domain, $secure, $httpOnly);
+ public function setCookie($name, $value, $expire, $path, $domain, $secure, $httpOnly, $sameSite = 'Lax');
}
diff --git a/lib/public/AppFramework/Http/Response.php b/lib/public/AppFramework/Http/Response.php
index 6f418e42553..832e0b96247 100644
--- a/lib/public/AppFramework/Http/Response.php
+++ b/lib/public/AppFramework/Http/Response.php
@@ -133,11 +133,12 @@ class Response {
* @param \DateTime|null $expireDate Date on that the cookie should expire, if set
* to null cookie will be considered as session
* cookie.
+ * @param string $sameSite The samesite value of the cookie. Defaults to Lax. Other possibilities are Strict or None
* @return $this
* @since 8.0.0
*/
- public function addCookie($name, $value, \DateTime $expireDate = null) {
- $this->cookies[$name] = ['value' => $value, 'expireDate' => $expireDate];
+ public function addCookie($name, $value, \DateTime $expireDate = null, $sameSite = 'Lax') {
+ $this->cookies[$name] = ['value' => $value, 'expireDate' => $expireDate, 'sameSite' => $sameSite];
return $this;
}