fix(cookies): parse ISO 8601 expires with milliseconds and fail loudly on invalid dates - #339
Open
jingjing2222 wants to merge 1 commit into
Open
fix(cookies): parse ISO 8601 expires with milliseconds and fail loudly on invalid dates#339jingjing2222 wants to merge 1 commit into
jingjing2222 wants to merge 1 commit into
Conversation
…y on invalid dates
jingjing2222
requested review from
gronxb,
heecheolman,
intmain,
l2hyunwoo,
leegeunhyeok and
raon0211
as code owners
August 3, 2026 09:25
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
🦋 Changeset detectedLatest commit: 27c3ad3 The changes in this PR will be included in the next version bump. This PR includes changesets to release 28 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
@granite-js/deployment-manager
@granite-js/forge-cli
@granite-js/pulumi-aws
babel-preset-granite
@granite-js/blur-view
@granite-js/brownfield-module
@granite-js/cli
@granite-js/cookies
create-granite-app
@granite-js/screen
@granite-js/image
@granite-js/jest
@granite-js/lottie
@granite-js/mpack
@granite-js/native
@granite-js/naver-map
@granite-js/plugin-core
@granite-js/plugin-env
@granite-js/plugin-hermes
@granite-js/plugin-micro-frontend
@granite-js/plugin-router
@granite-js/plugin-rozenite
@granite-js/plugin-sentry
@granite-js/react-native
@granite-js/style-utils
@granite-js/utils
@granite-js/video
@granite-js/vitest
commit: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Fixes
expiresdate parsing in the@granite-js/cookiesnative modules on both platforms:parseExpiresDateused a defaultISO8601DateFormatter, which cannot parse ISO 8601 strings containing fractional seconds. Since JavaScript'sDate.prototype.toISOString()always emits milliseconds (e.g.2024-01-01T00:00:00.000Z), the most common way to produce anexpiresvalue from JS never parsed. Now anISO8601DateFormatterwith.withFractionalSecondsis tried first, falling back to the non-fractional variant.yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ, whose zone letters cannot reliably match the literalZsuffix oftoISOString()output. Added literal-'Z'UTC patterns (with and without milliseconds) tried first, keeping the existing offset/RFC 1123/timestamp fallbacks.expiresattribute and store the cookie as a session cookie — the caller gottrueback and had no way to know the expiration was lost.setnow rejects an unparseableexpireswith a descriptive error listing the supported formats.Why
The cookie
expiresfield is documented as "ISO string or timestamp", but passing the canonical JS ISO string silently produced a session cookie. Session cookies live only in memory, so when iOS kills the WebKit network process of a backgrounded app, the cookie disappears — surfacing downstream as apps losing state they believed was persisted for weeks. The silent fallback made this effectively undebuggable from the JS side, sinceCookieManager.setresolved successfully.How it was verified
Ran replicas of the exact parsing logic (old vs. new) as standalone scripts:
swifton macOS, same FoundationISO8601DateFormatter), also constructing the resultingHTTPCookieto checkisSessionOnly:2024-01-01T00:00:00.000Z(toISOString)isSessionOnly=false)2024-01-01T00:00:00ZMon, 01 Jan 2024 00:00:00 GMT(RFC 1123)Android (
javawith the samejava.text.SimpleDateFormatsemantics): the new literal-'Z'patterns parsetoISOString()output (with and without milliseconds) to the correct epoch; RFC 1123 and millisecond-timestamp behavior is unchanged.swiftc -parsepasses on the modified Swift file;yarn workspace @granite-js/cookies build(brick-codegen + tsdown) succeeds with no generated-file drift.Notes for reviewers
expires(instead of silently storing a session cookie) is a behavior change for callers that were passing unparseable dates — but those callers were already not getting what they asked for; they were just never told.parseExpiresDateintentionally keeps lenientSimpleDateFormatparsing: strict mode would reject RFC 1123 dates whose weekday doesn't match the date, which the previous implementation accepted.