fix: reject unsafe-integer maxAge in stringifySetCookie#286
Open
spokodev wants to merge 1 commit into
Open
Conversation
Number.isInteger accepts values >= 1e21, which String() renders in exponential notation (e.g. 1e+21), producing an invalid Max-Age that violates the RFC 6265 grammar (max-age-value = 1*DIGIT). Use Number.isSafeInteger so the emitted value is always a plain integer.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #286 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 1 1
Lines 160 193 +33
Branches 69 83 +14
=========================================
+ Hits 160 193 +33 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
stringifySetCookieguardsmaxAgewithNumber.isInteger, but that accepts integers>= 1e21, whichString()renders in exponential notation. The result is aMax-Agethat breaks the RFC 6265 §5.2.2 grammar (max-age-value = 1*DIGIT):The guard exists precisely to guarantee a valid header (it already rejects
Infinity/NaN/non-integers), so letting these values through defeats its purpose. It also corrupts a parse -> serialize round-trip:Max-Age=<22 digits>is a valid header a server may send,parseSetCookiereads it as1e21, and re-serializing yields the broken output above.Switching to
Number.isSafeIntegerkeeps the emitted value a plain integer (safe integers are<= 2^53, well below the exponential threshold) and still accepts every realistic Max-Age. All existing cases (0,-1,1000, and theInfinity/3.14/non-number throw cases) are unaffected.Adds a regression test.