Skip to content

Commit 30ebaa4

Browse files
fix(event_handler): leave SameSite out of cookies in DEFAULT_MODE (#8709)
Co-authored-by: Leandro Damascena <lcdama@amazon.pt>
1 parent 9945fcb commit 30ebaa4

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

‎aws_lambda_powertools/shared/cookies.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@ def __str__(self) -> str:
112112
if self.secure:
113113
payload.write("; Secure")
114114

115-
if self.same_site:
115+
# DEFAULT_MODE leaves the attribute out, so the browser applies its own default
116+
if self.same_site and self.same_site.value:
116117
payload.write(f"; SameSite={self.same_site.value}")
117118

118119
if self.custom_attributes:

‎tests/unit/test_cookie_class.py‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,16 @@ def test_cookie_with_same_site():
115115
assert str(cookie) == "powertools=test; Path=/; Secure; SameSite=Strict"
116116

117117

118+
def test_cookie_with_same_site_default_mode():
119+
# GIVEN a cookie with the default same_site mode
120+
cookie = Cookie(name="powertools", value="test", path="/", same_site=SameSite.DEFAULT_MODE)
121+
122+
# WHEN getting the cookie's attributes
123+
# THEN the SameSite attribute should be left out instead of sent without a value
124+
assert cookie.same_site == SameSite.DEFAULT_MODE
125+
assert str(cookie) == "powertools=test; Path=/; Secure"
126+
127+
118128
def test_cookie_with_custom_attribute():
119129
# GIVEN a cookie with custom_attributes
120130
cookie = Cookie(name="powertools", value="test", path="/", custom_attributes=["extra1=value1", "extra2=value2"])

0 commit comments

Comments
 (0)