Skip to content

Commit 187d6ff

Browse files
namsnathivoberger
andauthored
fix: reverts cookie timezones to GMT (#587)
Co-authored-by: Ivo <[email protected]>
1 parent 6529f65 commit 187d6ff

File tree

7 files changed

+37
-18
lines changed

7 files changed

+37
-18
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88

99
## [unreleased]
10+
11+
## [0.29.2] - 2025-05-19
12+
- Fixes cookies being set without expiry in Django
13+
- Reverts timezone change from 0.28.0 and uses GMT
14+
15+
### Infrastructure
1016
- Sets up workflow to run backend-sdk-testing
1117
- Updates test-servers to work with updated tests
1218
- Adds workflow to test supertokens-website
@@ -35,6 +41,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3541
- Migrates unit tests from CircleCI to Github Actions
3642
- Adds lint/format checks to Github Actions
3743

44+
## [0.28.2] - 2025-05-19
45+
- Fixes cookies being set without expiry in Django
46+
- Reverts timezone change from 0.28.0 and uses GMT
3847

3948
## [0.28.1] - 2025-02-26
4049
- Pins `httpx` and `respx` to current major versions (<1.0.0)

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282

8383
setup(
8484
name="supertokens_python",
85-
version="0.29.1",
85+
version="0.29.2",
8686
author="SuperTokens",
8787
license="Apache 2.0",
8888
author_email="[email protected]",

supertokens_python/constants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from __future__ import annotations
1616

1717
SUPPORTED_CDI_VERSIONS = ["5.2"]
18-
VERSION = "0.29.1"
18+
VERSION = "0.29.2"
1919
TELEMETRY = "/telemetry"
2020
USER_COUNT = "/users/count"
2121
USER_DELETE = "/user/remove"

supertokens_python/framework/django/django_response.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ def set_cookie(
5151
key=key,
5252
value=value,
5353
expires=datetime.fromtimestamp(ceil(expires / 1000)).strftime(
54-
"%a, %d %b %Y %H:%M:%S UTC"
54+
# NOTE: This should always be GMT. HTTP only supports GMT in cookies.
55+
# If this is not respected, the cookie is always treated as a session cookie.
56+
"%a, %d %b %Y %H:%M:%S GMT"
5557
),
5658
path=path,
5759
domain=domain,

tests/Django/test_django.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ async def test_login_handle(self):
279279

280280
try:
281281
datetime.strptime(
282-
cookies["sAccessToken"]["expires"], "%a, %d %b %Y %H:%M:%S UTC"
282+
cookies["sAccessToken"]["expires"], "%a, %d %b %Y %H:%M:%S GMT"
283283
)
284284
except ValueError:
285285
assert False, "cookies expiry time doesn't have the correct format"

tests/test_session.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -644,13 +644,15 @@ async def test_token_cookie_expires(
644644
for c in response.cookies.jar:
645645
if c.name == "sAccessToken": # 100 years (set by the SDK)
646646
# some time must have elasped since the cookie was set. So less than current time
647-
assert datetime.fromtimestamp(c.expires or 0, tz=timezone.utc) - timedelta(
648-
days=365.25 * 100
649-
) < datetime.now(tz=timezone.utc)
647+
assert datetime.fromtimestamp(
648+
c.expires or 0, tz=timezone(timedelta(0), "GMT")
649+
) - timedelta(days=365.25 * 100) < datetime.now(
650+
tz=timezone(timedelta(0), "GMT")
651+
)
650652
if c.name == "sRefreshToken": # 100 days (set by the core)
651-
assert datetime.fromtimestamp(c.expires or 0, tz=timezone.utc) - timedelta(
652-
days=100
653-
) < datetime.now(tz=timezone.utc)
653+
assert datetime.fromtimestamp(
654+
c.expires or 0, tz=timezone(timedelta(0), "GMT")
655+
) - timedelta(days=100) < datetime.now(tz=timezone(timedelta(0), "GMT"))
654656

655657
assert response.headers["anti-csrf"] != ""
656658
assert response.headers["front-token"] != ""
@@ -672,13 +674,15 @@ async def test_token_cookie_expires(
672674
for c in response.cookies.jar:
673675
if c.name == "sAccessToken": # 100 years (set by the SDK)
674676
# some time must have elasped since the cookie was set. So less than current time
675-
assert datetime.fromtimestamp(c.expires or 0, tz=timezone.utc) - timedelta(
676-
days=365.25 * 100
677-
) < datetime.now(tz=timezone.utc)
677+
assert datetime.fromtimestamp(
678+
c.expires or 0, tz=timezone(timedelta(0), "GMT")
679+
) - timedelta(days=365.25 * 100) < datetime.now(
680+
tz=timezone(timedelta(0), "GMT")
681+
)
678682
if c.name == "sRefreshToken": # 100 days (set by the core)
679-
assert datetime.fromtimestamp(c.expires or 0, tz=timezone.utc) - timedelta(
680-
days=100
681-
) < datetime.now(tz=timezone.utc)
683+
assert datetime.fromtimestamp(
684+
c.expires or 0, tz=timezone(timedelta(0), "GMT")
685+
) - timedelta(days=100) < datetime.now(tz=timezone(timedelta(0), "GMT"))
682686

683687
assert response.headers["anti-csrf"] != ""
684688
assert response.headers["front-token"] != ""

tests/utils.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
# Import AsyncMock
1818
import sys
1919
from contextlib import contextmanager
20-
from datetime import datetime
20+
from datetime import datetime, timezone
2121
from functools import lru_cache
2222
from http.cookies import SimpleCookie
2323
from os import environ
@@ -215,7 +215,11 @@ def assert_info_clears_tokens(info: Dict[str, Any], token_transfer_method: str):
215215

216216

217217
def get_unix_timestamp(expiry: str):
218-
return int(datetime.strptime(expiry, "%a, %d %b %Y %H:%M:%S UTC").timestamp())
218+
return int(
219+
datetime.strptime(expiry, "%a, %d %b %Y %H:%M:%S GMT")
220+
.replace(tzinfo=timezone.utc)
221+
.timestamp()
222+
)
219223

220224

221225
def verify_within_5_second_diff(n1: int, n2: int):

0 commit comments

Comments
 (0)