Bug: Cookie Expires labels a non-UTC aware datetime as GMT without converting it

オープン 初心者向け
#8,671 コメント 3 件 リアクション 0 件 担当者 1 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@LemonCondor がすでに取り組んでいます。

2026年10月29日 から。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
86/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
aws, python
領域
backend

調査の方向性

aws_lambda_powertools/shared/cookies.py の Cookie._format_date と、tests/unit/test_cookie_class.py で言及されている回帰テストから始めてください。そのテストを実行し、現在、フォーマット済みヘッダーでタイムゾーンオフセットが保持されることを確認してください。タイムゾーン付き datetime が UTC で出力され、naive datetime は現在の動作を維持し、回帰テストが成功すれば完了です。

索引モデルが issue の本文から書いたものです。

説明

bug event_handlers
Expected Behaviour

A Cookie whose expires is a timezone-aware datetime should send that instant in GMT, as RFC 6265 requires for Expires. datetime(2026, 1, 1, 12, tzinfo=timezone(timedelta(hours=2))) is 10:00 UTC, so the header should read Expires=Thu, 01 Jan 2026 10:00:00 GMT.

Current Behaviour

Cookie._format_date formats the datetime with strftime and a hard-coded GMT suffix, without converting it to UTC first. The local wall-clock time is labelled GMT, so the cookie expires earlier or later by the UTC offset: Expires=Thu, 01 Jan 2026 12:00:00 GMT.

Code snippet
from datetime import datetime, timedelta, timezone
from aws_lambda_powertools.shared.cookies import Cookie

cookie = Cookie("a", "b", expires=datetime(2026, 1, 1, 12, tzinfo=timezone(timedelta(hours=2))))
print(str(cookie))  # a=b; Secure; Expires=Thu, 01 Jan 2026 12:00:00 GMT
Possible Solution

Convert an aware datetime to UTC before formatting (expires.astimezone(timezone.utc)); naive datetimes keep today's behaviour. I have this fix with a regression test in tests/unit/test_cookie_class.py (fails on develop, passes with the change) and can open a PR once this is triaged.

Steps to Reproduce

Run the snippet above on develop (5785377).

Powertools for AWS Lambda (Python) version

latest (3.37.0, develop)

AWS Lambda function runtime

3.13

Packaging format used

PyPi

Debugging logs
N/A
主要言語
Python
スター
3.3k
フォーク
511
平均マージ
3日 8時間
マージ済み PR(30日)
92

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

aws-powertools/powertools-lambda-python のほかの issue

aws-powertools/powertools-lambda-python の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。