Repository navigation
fix(cookies): do not serialize a finite maxAge outside the long long range - #6244
Open
waw666waw666 wants to merge 1 commit into
Open
waw666waw666 wants to merge 1 commit into
waw666waw666 wants to merge 1 commit into
Conversation
…range Signed-off-by: waw666waw666 <184799977+waw666waw666@users.noreply.github.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #6244 +/- ##
==========================================
+ Coverage 91.72% 91.73% +0.01%
==========================================
Files 113 113
Lines 44835 44861 +26
==========================================
+ Hits 41124 41155 +31
+ Misses 3711 3706 -5 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This branch has not been deployed
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.
This relates to...
Relates to #5832 and #6123, which fixed the same class of problem for the
expiresfield of the same Cookie dictionary. No open issue coversmaxAge; this was found by auditing the remaining numeric field after those fixes.Rationale
The
maxAgemember of the Cookie dictionary is converted with the WebIDLlong longconverter, which wraps finite numbers modulo 2^64. A finitemaxAgeoutside the long long range therefore serializes as an unrelated value:2 ** 64 + 2 ** 32becomesMax-Age=4294967296, and2 ** 63wraps to a negative value that only throws by accident. As withexpiresin #6123, an out-of-range finite value must not become a different, valid-looking value through integer wraparound.Changes
Bug Fixes
setCookie: a finitemaxAgeoutside the range of the WebIDLlong longconversion (value < -(2 ** 63) || value >= 2 ** 63) is now dropped in the Cookie dictionary converter, before the conversion can wrap it, so noMax-Ageattribute is serialized. This mirrors the guard fix(cookies): ignore finite numeric expires that wrap in unsigned long long #6124 added for numericexpires. In-range behavior is unchanged, including fractional truncation by the WebIDL conversion and the existingInvalid cookie max-ageerror for negative values. Non-finite values are intentionally out of scope, matching the scoping of setCookie turns finite out-of-range expires values into a Unix-epoch expiry #6123: they are still coerced to 0 by the WebIDL converter.Breaking Changes and Deprecations
N/A. The only behavior change is for inputs that previously produced an arbitrary wrapped
Max-Agevalue.Status
Tests
New cases in
test/cookie/cookies.js(in theCookie Settest, next to the existing out-of-rangeexpirescases):2 ** 63,2 ** 64,2 ** 64 + 2 ** 32,Number.MAX_VALUE,-Number.MAX_VALUEand-(2 ** 64)serialize without aMax-Ageattribute, and2 ** 62still serializes as-is.npm run test:cookies: 93 pass / 0 fail with this change; on the base commit the new assertions fail (92 pass / 1 fail, theCookie Settest) and everything else is unchanged.npx eslint lib/web/cookies/index.js test/cookie/cookies.js: clean.