powertools-lambda-python icon indicating copy to clipboard operation
powertools-lambda-python copied to clipboard

Bug: Cookie with SameSite.DEFAULT_MODE sends an empty SameSite= attribute

Open anishmehta24 opened this issue 1 month ago • 3 comments

Expected Behaviour

Cookie(..., same_site=SameSite.DEFAULT_MODE) leaves the SameSite attribute out of the Set-Cookie header, so the browser applies its default (the same as Go's http.SameSiteDefaultMode, which these names follow).

Current Behaviour

Cookie.__str__ checks if self.same_site:, which is true for every enum member, and DEFAULT_MODE has the value "", so the header gets an attribute with no value: SameSite=. That is not a valid SameSite value.

Code snippet

from aws_lambda_powertools.shared.cookies import Cookie, SameSite

str(Cookie(name="session", value="abc", same_site=SameSite.DEFAULT_MODE))
# 'session=abc; Secure; SameSite='

Steps to Reproduce

  1. Create a Cookie with same_site=SameSite.DEFAULT_MODE.
  2. Return it in a Response(cookies=[...]) or call str() on it.
  3. The Set-Cookie value ends with SameSite=.

Possible Solution

Only write the attribute when the enum value is not empty. I can open a PR.

Powertools for AWS Lambda (Python) version

latest (develop, 3.38.0)

AWS Lambda function runtime

3.12

Packaging format used

PyPi

Debugging logs

No response

anishmehta24 avatar Oct 30 '26 16:10 anishmehta24

Thanks @anishmehta24, confirmed, SameSite= with nothing after it. Reviewing #8709. Goes into 3.40.0.

leandrodamascena avatar Oct 30 '26 17:10 leandrodamascena

[!warning] This issue is now closed. Please be mindful that future comments are hard for our team to see. If you need more assistance, please either reopen the issue, or open a new issue referencing this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.

This is now released under 3.40.0 version!

github-actions[bot] avatar Nov 10 '26 11:11 github-actions[bot]