-
Notifications
You must be signed in to change notification settings - Fork 7.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix DATE_FORMAT_COOKIE definition #6783
Conversation
Can you add a test for this? |
I'm OK with that, but I would like to mention that when I wrote the code (back in 2004), the general definition was "l", and not "D" :-) |
I thought so, but I am happy that you agree with the change :) |
@derickr Is there anything missing? |
@derickr Just to double check, this is okay to merge (for master)? |
Is this to be merged into PHP 8.1? |
The most recent Cookie spec is: The date format used is specified here: This was later obsoleted by: There are 3 date formats listed there, 2 of which are considered obsolete. It is not clear to me which of these is meant to be represented by this constant (which I expect would be duplicated by other constants), but I don't think this change matches any of them? |
@GPHemsley True. This used to match one of the "obsolete" formats, and now it matches none of them, because it combines short weekday with |
This reverts commit ac34648. As pointed out on GH-6783, the new format doesn't match any of the specified formats. Previously the constant generated Thursday, 14-Jul-2005 22:30:41 BST which is obsolete. Now it generates Thu, 14-Jul-2005 22:30:41 BST which is not specified at all. The correct version would be: Thu, 14 Jul 2005 22:30:41 BST Reverting the change for now.
I've reverted the change for now in 9d8f97d. |
It looks like there's a fun little history here... The original RFC specifying cookies is RFC 2109, published February 1997. It does not define the "Expires" attribute directly, but makes reference to "Netscape's original proposal" having done so and reproduces the date format as RFC 2109 does not indicate where to find "Netscape's original proposal", but the curl link above indicates that it "is the original spec once found on netscape.com" and the Wayback Machine has this snapshot from June 1997. Both versions of the document indicate having been inspired by "RFC 822, RFC 850, RFC 1036, and RFC 1123" to cite a date format of RFC 822 (published August 1982) defines a date format that can be described as RFC 1123 (published October 1989) modifies that to use 4-digit years and thus Meanwhile, RFC 850 (published June 1983) specifies that a date format "must be acceptable both to the ARPANET and to the getdate routine". It cites RFC 1036 (published December 1987) updates that to say that a date format "must be acceptable both in RFC-822 and to the getdate(3) routine that is provided with the Usenet software" (like RFC 2965 (published October 2000) updates RFC 2109 and removes direct reference to the "Expires" attribute: This is the state of things as of July 2005, when e6c1ff2 introduces the DATE_COOKIE constant as an alias for DATE_FORMAT_RFC1123 ( In May 2006, fb92e33 changes DATE_FORMAT_RFC1123 to be In April 2011, RFC 6265 replaces RFC 2965 as the cookie spec and officially defines the "Expires" attribute for the first time. It does so, however, by directly referencing "<rfc1123-date, defined in [RFC2616], Section 3.3.1>": RFC 2616 (published June 1999) describes three date formats: "RFC 822, updated by RFC 1123" ( In November 2013, 23ab257 changes DATE_COOKIE to use DATE_FORMAT_COOKIE, which is newly-created but has a value ( This would nominally be where the cookie history stops, but, in June 2014, RFC 7231 replaces RFC 2616 and redefines its preferred date format in terms of RFC 5322, describing it as simply "IMF-fixdate" ( To round things out, RFC 5322 (published October 2008) specifies its full date format here: |
So again, working with dates is a major pain. If I understand https://datatracker.ietf.org/doc/html/rfc7231#section-7.1.1.1 correct, This would require a userland implementation to ensure a Maybe userland code then has to create a dedicated logic to ensure this behavior as the format will not enforce the proper timezone: Imho, the format is quite "misleading" as I would prefer Is this something which needs to be proposed to internals? Maybe worth having some kind of tooling around this? Is that even something PHP itself wants to address? Feedback is highly appreciated. |
I have checked 3 major websites - google.com, facebook.com, microsoft.com. They all use the |
One of the problems faced here is that most of the aforementioned date formats have multiple acceptable variations, so settling on a single value (as in a constant) is a decision being made outside the spec. And to further complicate things, I've discovered that RFC 822, RFC 1123, RFC 2822, and RFC 5322 allow 1-digit days ( Here are the constants compared with my interpretation of each spec: And @boesing, I agree with you that But in any case, this issue was originally specific to DATE_COOKIE, and the research indicates that, if the Netscape spec was what this constant was meant to capture, then the original change to |
In both http://curl.haxx.se/rfc/cookie_spec.html , https://docs.microsoft.com/de-de/windows/win32/wininet/http-cookies?redirectedfrom=MSDN and https://tools.ietf.org/html/rfc7234#section-5.3 the cookie datetime is specified as Mon, DD-Mon-YYYY HH:MM:SS GMT. However, the current definition returns Monday, DD-Mon-YYY HH:MM:SS GMT. Therefore, the "l" in "l, d-M-Y H:i:s T" must be changed to "D".