Skip to content

Commit 534d345

Browse files
Merge pull request #511 from supertokens/fix/always_clear_in_401_refreshes
test: move the session object and claims to the BE sdk server
2 parents 7accf0e + 433fd62 commit 534d345

File tree

5 files changed

+34
-15
lines changed

5 files changed

+34
-15
lines changed

CHANGELOG.md

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

99
## [unreleased]
1010

11+
## [0.23.1] - 2024-07-09
12+
13+
### Changes
14+
15+
- `refresh_post` and `refresh_session` now clears all user tokens upon CSRF failures and if no tokens are found. See the latest comment on https://github.com/supertokens/supertokens-node/issues/141 for more details.
16+
1117
## [0.23.0] - 2024-06-24
1218

1319
### Breaking change

setup.py

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

8484
setup(
8585
name="supertokens_python",
86-
version="0.23.0",
86+
version="0.23.1",
8787
author="SuperTokens",
8888
license="Apache 2.0",
8989
author_email="[email protected]",

supertokens_python/constants.py

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

1616
SUPPORTED_CDI_VERSIONS = ["3.0"]
17-
VERSION = "0.23.0"
17+
VERSION = "0.23.1"
1818
TELEMETRY = "/telemetry"
1919
USER_COUNT = "/users/count"
2020
USER_DELETE = "/user/remove"

supertokens_python/recipe/session/session_request_functions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ async def refresh_session_in_request(
439439

440440
return raise_unauthorised_exception(
441441
"Refresh token not found. Are you sending the refresh token in the request?",
442-
clear_tokens=False,
442+
clear_tokens=True,
443443
response_mutators=response_mutators,
444444
)
445445

@@ -460,7 +460,7 @@ async def refresh_session_in_request(
460460
# see https://github.com/supertokens/supertokens-node/issues/141
461461
raise_unauthorised_exception(
462462
"anti-csrf check failed. Please pass 'rid: \"session\"' header in the request.",
463-
clear_tokens=False,
463+
clear_tokens=True,
464464
)
465465
disable_anti_csrf = True
466466

tests/sessions/test_auth_mode.py

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -475,15 +475,15 @@ async def test_should_update_acccess_token_payload(
475475
@mark.parametrize(
476476
"transfer_method, auth_header, auth_cookie, output, set_tokens, cleared_tokens",
477477
[
478-
("any", False, False, "unauthorised", None, None),
479-
("header", False, False, "unauthorised", None, None),
480-
("cookie", False, False, "unauthorised", None, None),
478+
("any", False, False, "unauthorised", None, "both"),
479+
("header", False, False, "unauthorised", None, "both"),
480+
("cookie", False, False, "unauthorised", None, "both"),
481481
("any", False, True, "validatecookie", "cookies", None),
482-
("header", False, True, "unauthorised", None, None),
482+
("header", False, True, "unauthorised", None, "both"),
483483
("cookie", False, True, "validatecookie", "cookies", None),
484484
("any", True, False, "validateheader", "headers", None),
485485
("header", True, False, "validateheader", "headers", None),
486-
("cookie", True, False, "unauthorised", None, None),
486+
("cookie", True, False, "unauthorised", None, "both"),
487487
("any", True, True, "validateheader", "headers", "cookies"),
488488
("header", True, True, "validateheader", "headers", "cookies"),
489489
("cookie", True, True, "validatecookie", "cookies", "headers"),
@@ -544,6 +544,18 @@ async def test_refresh_session_parametrized(
544544
refresh_result["sRefreshToken"]["expires"]
545545
== "Thu, 01 Jan 1970 00:00:00 GMT"
546546
)
547+
elif cleared_tokens == "both":
548+
assert refresh_result["accessTokenFromHeader"] == ""
549+
assert refresh_result["refreshTokenFromHeader"] == ""
550+
assert refresh_result["accessToken"] == ""
551+
assert (
552+
refresh_result["sAccessToken"]["expires"] == "Thu, 01 Jan 1970 00:00:00 GMT"
553+
)
554+
assert refresh_result["refreshToken"] == ""
555+
assert (
556+
refresh_result["sRefreshToken"]["expires"]
557+
== "Thu, 01 Jan 1970 00:00:00 GMT"
558+
)
547559

548560
if set_tokens == "headers":
549561
assert refresh_result["accessTokenFromHeader"] != ""
@@ -565,12 +577,13 @@ async def test_refresh_session_parametrized(
565577
else:
566578
assert False, "Invalid set_tokens value"
567579

568-
if set_tokens != "cookies" and cleared_tokens != "cookies":
569-
assert refresh_result["accessToken"] is None
570-
assert refresh_result["refreshToken"] is None
571-
elif set_tokens != "headers" and cleared_tokens != "headers":
572-
assert refresh_result["accessTokenFromHeader"] is None
573-
assert refresh_result["refreshTokenFromHeader"] is None
580+
if cleared_tokens != "both":
581+
if set_tokens != "cookies" and cleared_tokens != "cookies":
582+
assert refresh_result["accessToken"] is None
583+
assert refresh_result["refreshToken"] is None
584+
elif set_tokens != "headers" and cleared_tokens != "headers":
585+
assert refresh_result["accessTokenFromHeader"] is None
586+
assert refresh_result["refreshTokenFromHeader"] is None
574587

575588

576589
async def refresh_session(

0 commit comments

Comments
 (0)