Bug #77612 [Com]: setcookie() sets incorrect SameSite header if all of its options filled
| From: | pmmaga@php.net | Date: | Wed, 13 Feb 2019 13:02:47 +0000 |
| Subject: | Bug #77612 [Com]: setcookie() sets incorrect SameSite header if all of its options filled | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-219555@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=77612&edit=1
ID: 77612
Comment by: pmmaga@php.net
Reported by: yura3d at tut dot by
Summary: setcookie() sets incorrect SameSite header if all of
its options filled
Status: Verified
Type: Bug
Package: HTTP related
Operating System: Debian 9.7/Kernel 4.9.0
PHP Version: 7.3.2
Block user comment: N
Private report: N
New Comment:
That doesn't sound right as the description of the issue mentions "This behavior
doesn't depend on cookie value length." and this case is tested in https://github.com/php/php-src/blob/c53852dc0a0e553a7d879eefe489c1c327d5bed2/ext/standard/tests/network/setcookie.phpt#L37
Previous Comments:
------------------------------------------------------------------------
[2019-02-13 13:02:36] yohgaki@php.net
Why does not it use smart_str? It's more robust and common in PHP.
------------------------------------------------------------------------
[2019-02-13 12:57:04] yohgaki@php.net
It seems this feature hasn't tested well.
Just need more buffer. Patch attached.
------------------------------------------------------------------------
[2019-02-13 12:19:36] yura3d at tut dot by
Description:
------------
If I call setcookie(string $name, string $value, array $options) with all of options passed
(expires, path, domain, secure, httponly, samesite), PHP generates incorrect Set-Cookie HTTP header:
SameSite parameter is empty if I set "Lax", or "Str" if I set
"Strict". But if I miss, for example, one option for setcookie (let it be
"path"), everything is fine. This behavior doesn't depend on cookie value length.
Test script:
---------------
setcookie('key', 'value', [
'expires' => time() + 31536000,
'path' => '/',
'domain' => 'example.com',
'secure' => true,
'httponly' => true,
'samesite' => 'Lax'
]);
// Expected:
// Set-Cookie: key=value; expires=Thu, 13-Feb-2020 12:06:47 GMT; Max-Age=31536000; path=/;
domain=example.com; secure; HttpOnly; SameSite=Lax
// Actual:
// Set-Cookie: key=value; expires=Thu, 13-Feb-2020 12:06:47 GMT; Max-Age=31536000; path=/;
domain=example.com; secure; HttpOnly; SameSite=
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=77612&edit=1