Skip to content

Parse Expires with the RFC 6265 cookie-date algorithm - #296

Open
bardrop wants to merge 1 commit into
jshttp:masterfrom
bardrop-oss:fix-expires-cookie-date
Open

bardrop wants to merge 1 commit into
jshttp:masterfrom
bardrop-oss:fix-expires-cookie-date

Conversation

@bardrop

@bardrop bardrop commented Nov 15, 2026

Copy link
Copy Markdown

Fixes #295.

parseSetCookie parsed Expires with new Date(val). That is engine-defined for non-ISO strings, reads a date without a zone in the local time zone, and turns strings like 1 or 2015 into dates.

This replaces it with the cookie-date algorithm from RFC 6265 section 5.1.1:

  • split the value on the delimiter set, then take the first hh:mm:ss time, 1-2 digit day, month name prefix, and 2-4 digit year
  • years 70-99 become 19xx, 0-69 become 20xx
  • ignore the attribute if a part is missing, the year is before 1601, the time is out of range, or the date does not exist (30 Feb)
  • build the date with Date.UTC, so the result is the same in every time zone and engine

Behavior change: ISO strings like 2015-10-21T07:28:00Z are no longer accepted as Expires, same as in browsers. The usual Wed, 21 Oct 2015 07:28:00 GMT and 21-Oct-15 forms parse as before (the top-sites snapshots are unchanged).

Size: this adds about 280 bytes (brotli), so I raised the size-limit from 1.4 KB to 1.6 KB (now 1.54 KB). Happy to trim it further if you have a target in mind.

Tests: new cases for the RFC 1123, RFC 850, asctime and two-digit-year forms, values that must be ignored, and a zone-less date read with TZ=America/New_York. 11 of them fail on master. npm test passes (63771 tests, size check included).

`parseSetCookie` read Expires with `new Date(str)`. For anything but
ISO strings that parse is engine-defined, a date without a zone is
read in the local time zone, and strings such as "1" or "2015" became
dates. Use the algorithm from RFC 6265 sec 5.1.1 instead: always UTC,
two-digit years, and the attribute is ignored unless the day, month,
year and time are all present and valid.
@bardrop

bardrop commented Nov 23, 2026

Copy link
Copy Markdown
Author

Friendly ping on this fix for #295. No conflicts, and I can trim it if you would rather keep a smaller parser.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

parseSetCookie reads Expires with Date parsing: depends on the time zone and accepts non-dates

1 participant