Bug: Set-Cookie values passed as a header are comma-joined into one invalid header on HTTP API and Function URL responses

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

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

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

2026年11月28日 から。

評価

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

調査の方向性

HttpApiHeadersSerializer.serialize から始めます。これは現在、値がリストのヘッダーをカンマで結合しています。提供された APIGatewayHttpResolver のスニペットと apiGatewayProxyV2Event_GET.json を使用して、その動作を再現してください。シリアライザーのテストを追加または更新し、大文字と小文字を区別しない Set-Cookie ヘッダーをカバーし、他のヘッダーは変更されずに、値がレスポンスの cookies フィールドへ移動されることを確認してください。また、同等の LambdaFunctionUrlResolver のパスも確認し、関連する機能テストスイートを実行してください。

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

説明

Expected Behaviour

When a route returns Response(headers={"Set-Cookie": [...]}) with APIGatewayHttpResolver or LambdaFunctionUrlResolver, each value should reach the client as its own Set-Cookie header, the same as passing them through cookies=. Payload format 2.0 has no multi-value headers, so the values belong in the response cookies field.

Current Behaviour

HttpApiHeadersSerializer joins every list header with ", ", including Set-Cookie. The client gets one header such as session=abc; Expires=Wed, 21 Oct 2026 07:28:00 GMT, theme=dark, which browsers read as a single cookie, so the second cookie is lost and the first gets a broken Expires. Set-Cookie cannot be comma-joined (RFC 6265 section 3); the REST/ALB multi-value serializer already sends them separately.

Code snippet
from aws_lambda_powertools.event_handler import APIGatewayHttpResolver, Response
from aws_lambda_powertools.shared.cookies import Cookie
from tests.functional.utils import load_event

app = APIGatewayHttpResolver()

@app.get("/my/path")
def handler():
    return Response(
        200,
        "text/plain",
        "ok",
        headers={"Set-Cookie": ["session=abc; Expires=Wed, 21 Oct 2026 07:28:00 GMT", "theme=dark"]},
        cookies=[Cookie("lang", "en")],
    )

result = app.resolve(load_event("apiGatewayProxyV2Event_GET.json"), None)
print(result["headers"])
print(result["cookies"])
Possible Solution

In HttpApiHeadersSerializer.serialize, treat a Set-Cookie header (any casing) as cookies: append its values to the cookies list instead of joining them into headers. Other headers are unchanged.

Steps to Reproduce
  1. On develop (0bbc252), run the snippet above.
  2. headers["Set-Cookie"] is 'session=abc; Expires=Wed, 21 Oct 2026 07:28:00 GMT, theme=dark' and cookies only has lang=en; Secure.
Did you run the reproduction yourself?

Yes, I ran it and saw the failure

Powertools for AWS Lambda (Python) version

3.41.0 (develop @ 0bbc252)

AWS Lambda function runtime

3.13

Packaging format used

PyPi

Debugging logs
{'Set-Cookie': 'session=abc; Expires=Wed, 21 Oct 2026 07:28:00 GMT, theme=dark', 'Content-Type': 'text/plain'}
['lang=en; Secure']
主要言語
Python
スター
3.3k
フォーク
511
平均マージ
2日 23時間
マージ済み PR(30日)
50

環境構築

はじめの一歩

  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 を短くまとめたダイジェスト。