Skip to content

fix: reverts cookie timezones to GMT #588

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0


## [unreleased]
- Upgrades `pip` and `setuptools` in CI publish job
- Also upgrades `poetry` and it's dependency - `clikit`

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

## [0.28.1] - 2025-02-26
- Pins `httpx` and `respx` to current major versions (<1.0.0)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@

setup(
name="supertokens_python",
version="0.28.1",
version="0.28.2",
author="SuperTokens",
license="Apache 2.0",
author_email="[email protected]",
Expand Down
2 changes: 1 addition & 1 deletion supertokens_python/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from __future__ import annotations

SUPPORTED_CDI_VERSIONS = ["5.2"]
VERSION = "0.28.1"
VERSION = "0.28.2"
TELEMETRY = "/telemetry"
USER_COUNT = "/users/count"
USER_DELETE = "/user/remove"
Expand Down
4 changes: 3 additions & 1 deletion supertokens_python/framework/django/django_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ def set_cookie(
key=key,
value=value,
expires=datetime.fromtimestamp(ceil(expires / 1000)).strftime(
"%a, %d %b %Y %H:%M:%S UTC"
# NOTE: This should always be GMT. HTTP only supports GMT in cookies.
# If this is not respected, the cookie is always treated as a session cookie.
"%a, %d %b %Y %H:%M:%S GMT"
),
path=path,
domain=domain,
Expand Down
2 changes: 1 addition & 1 deletion tests/Django/test_django.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ async def test_login_handle(self):

try:
datetime.strptime(
cookies["sAccessToken"]["expires"], "%a, %d %b %Y %H:%M:%S UTC"
cookies["sAccessToken"]["expires"], "%a, %d %b %Y %H:%M:%S GMT"
)
except ValueError:
assert False, "cookies expiry time doesn't have the correct format"
Expand Down
28 changes: 16 additions & 12 deletions tests/test_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -663,13 +663,15 @@ async def test_token_cookie_expires(
for c in response.cookies.jar:
if c.name == "sAccessToken": # 100 years (set by the SDK)
# some time must have elasped since the cookie was set. So less than current time
assert datetime.fromtimestamp(c.expires or 0, tz=timezone.utc) - timedelta(
days=365.25 * 100
) < datetime.now(tz=timezone.utc)
assert datetime.fromtimestamp(
c.expires or 0, tz=timezone(timedelta(0), "GMT")
) - timedelta(days=365.25 * 100) < datetime.now(
tz=timezone(timedelta(0), "GMT")
)
if c.name == "sRefreshToken": # 100 days (set by the core)
assert datetime.fromtimestamp(c.expires or 0, tz=timezone.utc) - timedelta(
days=100
) < datetime.now(tz=timezone.utc)
assert datetime.fromtimestamp(
c.expires or 0, tz=timezone(timedelta(0), "GMT")
) - timedelta(days=100) < datetime.now(tz=timezone(timedelta(0), "GMT"))

assert response.headers["anti-csrf"] != ""
assert response.headers["front-token"] != ""
Expand All @@ -691,13 +693,15 @@ async def test_token_cookie_expires(
for c in response.cookies.jar:
if c.name == "sAccessToken": # 100 years (set by the SDK)
# some time must have elasped since the cookie was set. So less than current time
assert datetime.fromtimestamp(c.expires or 0, tz=timezone.utc) - timedelta(
days=365.25 * 100
) < datetime.now(tz=timezone.utc)
assert datetime.fromtimestamp(
c.expires or 0, tz=timezone(timedelta(0), "GMT")
) - timedelta(days=365.25 * 100) < datetime.now(
tz=timezone(timedelta(0), "GMT")
)
if c.name == "sRefreshToken": # 100 days (set by the core)
assert datetime.fromtimestamp(c.expires or 0, tz=timezone.utc) - timedelta(
days=100
) < datetime.now(tz=timezone.utc)
assert datetime.fromtimestamp(
c.expires or 0, tz=timezone(timedelta(0), "GMT")
) - timedelta(days=100) < datetime.now(tz=timezone(timedelta(0), "GMT"))

assert response.headers["anti-csrf"] != ""
assert response.headers["front-token"] != ""
Expand Down
8 changes: 6 additions & 2 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

# Import AsyncMock
import sys
from datetime import datetime
from datetime import datetime, timezone
from http.cookies import SimpleCookie
from os import environ, kill, remove, scandir
from pathlib import Path
Expand Down Expand Up @@ -320,7 +320,11 @@ def assert_info_clears_tokens(info: Dict[str, Any], token_transfer_method: str):


def get_unix_timestamp(expiry: str):
return int(datetime.strptime(expiry, "%a, %d %b %Y %H:%M:%S UTC").timestamp())
return int(
datetime.strptime(expiry, "%a, %d %b %Y %H:%M:%S GMT")
.replace(tzinfo=timezone.utc)
.timestamp()
)


def verify_within_5_second_diff(n1: int, n2: int):
Expand Down
Loading