|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #77612 setcookie() sets incorrect SameSite header if all of its options filled
Submitted: 2019-02-13 12:19 UTC Modified: 2019-02-14 09:28 UTC
From: yura3d at tut dot by Assigned: nikic (profile)
Status: Closed Package: HTTP related
PHP Version: 7.3.2 OS: Debian 9.7/Kernel 4.9.0
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
17 + 24 = ?
Subscribe to this entry?

 [2019-02-13 12:19 UTC] yura3d at tut dot by
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' => '',
    'secure' => true,
    'httponly' => true,
    'samesite' => 'Lax'
// Expected:
// Set-Cookie: key=value; expires=Thu, 13-Feb-2020 12:06:47 GMT; Max-Age=31536000; path=/;; secure; HttpOnly; SameSite=Lax
// Actual:
// Set-Cookie: key=value; expires=Thu, 13-Feb-2020 12:06:47 GMT; Max-Age=31536000; path=/;; secure; HttpOnly; SameSite=


bug77512.patch (last revision 2019-02-13 12:55 UTC by yohgaki at ohgaki dot net)

Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2019-02-13 12:57 UTC]
-Status: Open +Status: Verified
 [2019-02-13 12:57 UTC]
It seems this feature hasn't tested well.
Just need more buffer. Patch attached.
 [2019-02-13 13:02 UTC]
Why does not it use smart_str? It's more robust and common in PHP.
 [2019-02-13 13:02 UTC]
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
 [2019-02-13 13:35 UTC]
Actually, you're right. Max-Age has variable length and that isn't taken into account.
 [2019-02-14 09:28 UTC]
-Assigned To: +Assigned To: nikic
 [2019-02-14 09:44 UTC]
Automatic comment on behalf of
Log: Fixed bug #77612
 [2019-02-14 09:44 UTC]
-Status: Verified +Status: Closed
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Thu Nov 30 22:01:27 2023 UTC