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 个 reaction 已指派 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 小时
30 天内合并 PR
50

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

aws-powertools/powertools-lambda-python 的其他 Issue

查看 aws-powertools/powertools-lambda-python 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。