Catalyst:
Gecko Bug 1617361 is a severe cookie-related bug where Gecko browsers randomly refuse to send the HTTP Cookie header (either extremely difficult to reproduce or (for the layman) extremely difficult to escape (just clear cookies)). It was later revealed that Gecko does not report an error where nonsecure cookies were not able to overwrite secure cookies. However after changing the session cookie name from session to session2 and setting all the security/domain settings to FALSE Gecko is still refusing to send the HTTP Cookie header. This bug is severe enough that it afflicts 90% of all people's Gecko browsers effectively preventing them from loading websites powered by my platform. As someone fundamentally against monopolies I need to address this on all fronts.
Which Bugs are Which?
- Gecko Bug 1617361 is when Gecko randomly chooses to not set the HTTP
Cookieheader. - Gecko Bug 1623284 (below) is about Gecko not bothering to mention that the session cookie was not acceptable because it's not secure and the current one is secure.
- This bug is about figuring out how my PHP code could generate the session cookie without the security/domain/whatever flags.
Question:
How would my PHP code below fail to set the session cookie as secure in any context of a request (on live (or "production") servers) and how would I rewrite the code to ensure that the session cookie is not only secure when it is set though always secure when it is reinitialized for subsequent page requests?
Error Message
The following is the error this post is directly about. This error message is only generated when in Firefox you go to about:networking#logging, set cookie:5 to "Current Load Modules" (comma delimiter) and log while the issue occurs hence the difficulty and frustration of not just one though multiple bugs. Here is the error message it generates:
W/cookie rejected because cookie can't save because older cookie is secure cookie but newer cookie is non-secure cookie
Details:
While there are two bugs relevant to this post the bug I'm trying to address is when my PHP code resumes the session but does not make the session cookie secure. In an attempt to address the issue for the original catalyst bug my server now uses setcookie('session2',session_id(),time()+3600,'/',$_SERVER['HTTP_HOST'], FALSE, FALSE); until both that bug and my own PHP code are all properly working.
- I am happy to update the question and provide any other relevant code.
- The domain in question is linked in my profile though as I mentioned I've set the session cookie to nonsecure for now.
- This bug seems to occur in both local/WAMP and live/LAMP environments.
Verification Requirements for Acceptable Answer
- I need to be able to reproduce the occurrence of the session cookie when it is refusing to be sent as secure (the domain in my profile is a good example of my platform's HTTP behavior).
- I need to understand what about my code, the environment and/or any bugs in PHP itself that are causing this issue.
- I need to be able to reliably know that session cookies being sent in all instances are secure, especially since Gecko browsers do not tell you about the error in the developer console (posted bug 1623284 for that).
- I do not use frameworks or libraries for any of my client/server code.
Here is the original PHP code that handled sessions:
<?php
if (substr($_SERVER['DOCUMENT_ROOT'],0,1) == '/' && isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on')
{
ini_set('session.cookie_secure', 1);
ini_set('session.gc_maxlifetime', 3600);
session_set_cookie_params(3600);
}
ini_set('session.cookie_httponly', 1);
ini_set('session.cookie_samesite','Strict');
ini_set('session.use_only_cookies', 1);
session_name('session');
session_start();
?>