validate cookie Max-Age as -?digits before int()#12947
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #12947 +/- ##
========================================
Coverage 98.95% 98.96%
========================================
Files 131 131
Lines 47998 48103 +105
Branches 2494 2497 +3
========================================
+ Hits 47498 47603 +105
Misses 376 376
Partials 124 124
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. |
Merging this PR will not alter performance
Comparing Footnotes
|
|
the codecov run flagged test_morsel_with_attributes: a Morsel built in Python can carry an int in max-age (the test sets it directly), and the old int() tolerated that while my regex didn't, so it blew up with a TypeError. pushed a small fix that normalises to str before the rfc check. a programmatic int can't carry the sign/underscore oddities we're guarding against anyway, so the strictness on header-parsed values is unchanged. cookiejar suite is green locally. |
What do these changes do?
CookieJar.update_cookiesreads aSet-CookieMax-Agewith a bareint(). Python'sint()is more permissive than :rfc:6265#section-5.2.2, which says aMax-Ageis"-"? DIGIT+and any other value must be ignored. SoMax-Age=+1000,Max-Age=1_000and whitespace-padded values are honoured and persist the cookie with the given lifetime, whereas a browser drops the attribute and keeps it as a session cookie. The jar already clears a clearly non-numeric value (Max-Age=string), so this just completes that existing intent by validating against-?[0-9]+before parsing.Are there changes in behavior for the user?
A
Set-CookiewhoseMax-Ageis not-?DIGIT+now leaves the cookie as a session cookie instead of giving it an expiry. Well-formed values, including negative ones, are unchanged.Is it a substantial burden for the maintainers to support this?
No, it is a small contained check next to the existing parse.
Related issue number
N/A
Checklist
CONTRIBUTORS.txtCHANGES/folder