Repository navigation
fix(event_handler): send cookie Expires in GMT with English day and month names - #8876
Conversation
|
Thanks a lot for your first contribution! Please check out our contributing guidelines and don't hesitate to ask whatever you need. |
…onth names A timezone-aware expires was formatted as its local wall-clock time with a GMT suffix, so the cookie expired early or late by the UTC offset. strftime's %a and %b also followed the process LC_TIME locale, producing names browsers cannot parse. Convert aware datetimes to UTC and format with email.utils.format_datetime. Naive datetimes keep being read as UTC and a date keeps meaning midnight GMT. An instant outside years 1 to 9999 is clamped instead of raising OverflowError.
805ef99 to
30615f4
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #8876 +/- ##
========================================
Coverage 97.14% 97.14%
========================================
Files 327 327
Lines 16828 16839 +11
Branches 1539 1540 +1
========================================
+ Hits 16348 16359 +11
Misses 337 337
Partials 143 143 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
leandrodamascena
left a comment
There was a problem hiding this comment.
Thanks @cleissonom, and thanks @LemonCondor for the quick answer today. Converting to UTC first and letting format_datetime write the English names fixes both problems in the thread with one call, and the clamp at the year boundaries is a nice touch. I checked it against a real de_DE locale on my side: develop writes Fr, 30 Okt, this branch writes Fri, 30 Oct. Goes out in 3.42.0, no need to rebase, you'll be in the release notes.
7c4709b
into
aws-powertools:develop
|
Awesome work, congrats on your first merged pull request and thank you for helping improve everyone's experience! |
|
Awesome work, congrats on your first merged pull request and thank you for helping improve everyone's experience! |



Issue number:
closes #8671
Summary
Changes
Cookieformats expiry dates withstrftimeand a fixedGMTsuffix. For a non-UTC datetime, that changes the intended expiry time by its UTC offset. The day and month names also depend onLC_TIME, so a non-English locale can produce an invalid cookie date._format_datenow converts the value to UTC and usesemail.utils.format_datetime(..., usegmt=True). This fixes both problems discussed in #8671. The import stays inside the function so its cost is deferred until an expiry value is formatted.Naive datetimes still mean UTC, and
datevalues still mean midnight GMT. UTC conversions outside years 1 to 9999 are clamped to the nearest representable boundary to avoid introducingOverflowError. The constructor docstring explains the timezone handling.User experience
datetime(2026, 1, 1, 12, tzinfo=timezone(timedelta(hours=2)))Expires=Thu, 01 Jan 2026 12:00:00 GMTExpires=Thu, 01 Jan 2026 10:00:00 GMTdatetime(2026, 10, 30, 7, 28)withLC_TIME=de_DE.UTF-8Expires=Fr., 30 Okt. 2026 07:28:00 GMTExpires=Fri, 30 Oct 2026 07:28:00 GMTThe cookie payload shape is unchanged. The date text changes without a deprecation warning under ADR 0006: the previous output contradicted the RFC 6265 cookie date format, and the maintainer confirmed both fixes in the issue.
Verification
I used an AI coding assistant.
I ran
uv run --locked pytest tests/unit/test_cookie_class.py tests/functional/event_handler/required_dependencies/test_api_gateway.py -q -k cookieon this commit, withcookies.pytaken fromdevelop(4 failed, 16 passed) and with the change (20 passed), and read both outputs.The added tests cover timezone conversion, locale-independent formatting,
datevalues, range boundaries, and cookie output throughAPIGatewayRestResolverandAPIGatewayHttpResolver. The locale unit test uses adatetimesubclass to emulate Germanstrftimeoutput, following #8707, so it does not depend on installed locales.Other recorded checks on macOS arm64, with locked dependencies and base
a2eb4d59:OverflowErrorif conversion is added without the clamp.test_channel_path_normalizationskip.make pron Python 3.14.6: 4,241 passed, 73 skipped and 0 failed; 10 performance tests passed. Mypy and bandit pass,cookies.pyremains at xenon rank A, and generated skill references are unchanged.date, microsecond and boundary outputs. Non-UTC values, including year rollover,Europe/BerlinandAmerica/Sao_Paulo, get the corrected GMT time. Realde_DE,fr_FRandja_JPlocale checks produce English names.These checks were local. The change has not been run against a real API Gateway, ALB or Function URL, and no AWS resources were used.
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.