Skip to content

Accept single-digit time components in cookie expiry dates - #1458

Merged
He-Pin merged 1 commit into
apache:mainfrom
He-Pin:fix/cookie-expiry-time-width
Nov 17, 2026
Merged

He-Pin merged 1 commit into
apache:mainfrom
He-Pin:fix/cookie-expiry-time-width

Conversation

@He-Pin

@He-Pin He-Pin commented Nov 13, 2026 •

Copy link
Copy Markdown
Member

Motivation

RFC 6265 section 5.1.1 permits one or two digits in each cookie-date time component. HttpHeader.parse currently models Set-Cookie: sid=value; Expires=Sun, 06 Nov 1994 8:9:7 GMT without errors but gives it DateTime.MinValue, whereas the equivalent 08:09:07 is parsed correctly.

Modification

Use cookie-specific expiry-date alternatives for the existing IMF/rfc850-shaped and asctime-shaped forms. Accept one or two time digits while retaining the existing date construction and weekday validation. Keep the original HTTP-date branch first; shared HTTP-date and standalone Expires parsing and canonical rendering are unchanged.

This is a bounded receiving-interoperability fix, not a complete implementation of RFC 6265's cookie-date token algorithm or browser cookie storage. It does not change token order or weekday policy. Newly recognized shapes with invalid numeric/weekday fields now reach the existing validation instead of the unrecognized-date fallback; canonical invalid inputs retain their existing behavior.

Release note

Cookie Expires dates now accept one or two digits per time component, as RFC 6265 allows, e.g. Expires=Sun, 06 Nov 1994 8:9:7 GMT. Before, such a date was silently replaced with DateTime.MinValue. A Set-Cookie header whose single-digit date is invalid (e.g. 24:0:0) now fails date validation and becomes a RawHeader with errors, as the two-digit form already did, instead of being modeled with DateTime.MinValue. Date and Expires header parsing is unchanged.

Tests

  • Baseline: canonical date passed; single-digit date failed with Some(1800-01-01T00:00:00) instead of the expected timestamp.
  • Final complete HttpHeaderSpec, HeaderSpec, and Java HttpCookieSpec: 118 passed. Concrete HttpHeaderParserCRLFSpec and HttpHeaderParserLFSpec: 66 passed (184 distinct tests total, including 11 new tests).
  • Scala formatting, license-header checks, and http-core MiMa compatibility checks passed.
  • Added mixed-width/boundary, retained Path, canonical rendering, existing date shapes, shared Date/Expires isolation, and numeric/weekday validation coverage.

The Netty DateFormatter single-digit tests were an audit clue. This is an independent implementation against Pekko's existing parser, not a port of Netty's broader date parser.

Reference: https://www.rfc-editor.org/rfc/rfc6265.html#section-5.1.1

@pjfanning pjfanning added this to the 2.1.0 milestone Nov 15, 2026

@pjfanning pjfanning left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this looks correct. Trying HTTP-date first and only then the cookie-specific shapes keeps canonical dates on the existing path. Scoping it to expires-av leaves Date/Expires headers strict, and the tests show that. Two minor points:

  1. Duplicated rules. cookie-IMF-fixdate and cookie-asctime-date are copies of IMF-fixdate and asctime-date that differ only in using cookie-time-of-day. That's fine for now, but a comment on the originals pointing at the cookie variants (or vice versa) would help keep them in sync if the date shapes change again.
  2. Behaviour change for invalid single-digit dates. Previously a cookie like Expires=Sun, 06 Nov 1994 24:0:0 GMT fell through to the DateTime.MinValue fallback and the Set-Cookie was still modeled. Now it reaches createDateTime validation and the whole header becomes a RawHeader with errors. That's consistent with how the two-digit form already behaves, and the description mentions it, but it might be worth a line in the release notes, since some cookies that used to be modeled no longer will be.

@pjfanning pjfanning left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@He-Pin
He-Pin merged commit 521fee9 into apache:main Nov 17, 2026
6 checks passed
@He-Pin
He-Pin deleted the fix/cookie-expiry-time-width branch November 17, 2026 14:31
@pjfanning pjfanning added the release notes should be mentioned in release notes label Nov 18, 2026
pjfanning added a commit that referenced this pull request Nov 19, 2026
Motivation:
Several recently merged PRs left review points unaddressed: docs that
were asked to be dropped, comments and tests that were suggested, and
small API and internal tidy-ups.

Modification:
- Add a Scala FilenameEncoding alias and values to Multipart.FormData
  and use them in the Scala toEntity signature and tests (#1494).
- Render the form-data Content-Disposition header directly instead of
  rendering it twice and slicing off the prefix (#1494).
- Drop the docs paragraph about unpaired URI surrogates (#1426) and the
  cookie -0000 sentence in request-level.md (#1493).
- Fix the javadsl Multipart.FormData doc the same way #1483 fixed the
  scaladsl one.
- Comment the cookie date rule copies so they stay in sync (#1458).
- Test custom methods starting with Q next to the QUERY fast path
  (#1477).
- Use one root package import and a dilated timeout in
  HeaderCompressionSpec (#1438).
- Pass isTrailer to HttpMessageRendering.renderHeaders explicitly
  (#1463).
- Remove the unused forwarding overloads in Handshake.Client and
  EnabledPingState (#1436, #1462).
- Move the media type model checks from the routing spec to a new
  http-core MediaTypesSpec (#1437, #1454).
- Hash the WebSocket key without String.valueOf (#1439).

Result:
The review points are addressed. The only public API change is the
added Scala FilenameEncoding alias.

Tests:
- http-core/testOnly MultipartSpec MultipartsSpec MediaTypesSpec
  RequestParserCRLFSpec RequestParserLFSpec HeaderCompressionSpec
  WebSocketClientSpec HeaderSpec HttpHeaderSpec: 314 passed
- http2-tests/testOnly HttpMessageRenderingSpec Http2PingSchedulingSpec:
  38 passed
- http-tests/testOnly FileAndResourceDirectivesSpec: 63 passed
- http-core/mimaReportBinaryIssues: passed

References:
Refs #1426, #1436, #1437, #1438, #1439, #1454, #1458, #1462, #1463,
#1477, #1483, #1493, #1494
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release notes should be mentioned in release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants