Bug: Cookie with SameSite.DEFAULT_MODE sends an empty SameSite= attribute
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
- Create a
Cookiewithsame_site=SameSite.DEFAULT_MODE. - Return it in a
Response(cookies=[...])or callstr()on it. - The
Set-Cookievalue ends withSameSite=.
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
Thanks @anishmehta24, confirmed, SameSite= with nothing after it. Reviewing #8709. Goes into 3.40.0.
[!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!