diff options
author | blizzz <blizzz@arthur-schiwon.de> | 2020-06-22 13:00:12 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-22 13:00:12 +0200 |
commit | 859941db3228286be0bea1692ce39624df3236f6 (patch) | |
tree | 4d144da8d7ba82a2f23e06f1fd7c8d64e1062018 /lib | |
parent | a899b4775d3d5843bd5c83af8e74cab2219c71d1 (diff) | |
parent | fbf9772a3eafeab74cc5b3f76e7ad7cc081991bb (diff) | |
download | nextcloud-server-859941db3228286be0bea1692ce39624df3236f6.tar.gz nextcloud-server-859941db3228286be0bea1692ce39624df3236f6.zip |
Merge pull request #21479 from nextcloud/fix/21474/allow_specifying_cookie_type
Allow to specify the cookie type for appframework responses
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/AppFramework/App.php | 5 | ||||
-rw-r--r-- | lib/private/AppFramework/Http/Output.php | 16 | ||||
-rw-r--r-- | lib/public/AppFramework/Http/IOutput.php | 3 | ||||
-rw-r--r-- | lib/public/AppFramework/Http/Response.php | 5 |
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..39543dc9bf1 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 20) * @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; } |