Skip to content

Commit 08a3d29

Browse files
authored
fix: check for MFA claim in removeDevice (supertokens#581)
- Ensures that verified TOTP devices can only be removed after MFA requirements are completed - Removes override for global claim validators
1 parent 11f56cd commit 08a3d29

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99
## [unreleased]
1010

1111
## [0.29.1] - 2025-04-11
12-
- Fixes an issue where `removeDevice` API allowed removing TOTP devices without the user completing MFA.
12+
- Fixes an issue where `removeDevice` API allowed removing verified TOTP devices without the user completing MFA.
1313
- Fixes issue with ThirdParty provider info on dashboard
1414

1515
## [0.29.0] - 2025-03-03

supertokens_python/recipe/totp/api/implementation.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,12 @@
1717
from supertokens_python.recipe.multifactorauth.asyncio import (
1818
assert_allowed_to_setup_factor_else_throw_invalid_claim_error,
1919
)
20+
from supertokens_python.recipe.multifactorauth.multi_factor_auth_claim import (
21+
MultiFactorAuthClaim,
22+
)
2023
from supertokens_python.recipe.multifactorauth.recipe import MultiFactorAuthRecipe
2124
from supertokens_python.recipe.session import SessionContainer
22-
from supertokens_python.recipe.session.exceptions import UnauthorisedError
25+
from supertokens_python.recipe.session.exceptions import UnauthorisedError # noqa: E402
2326
from supertokens_python.types import GeneralErrorResponse
2427

2528
from ..interfaces import APIInterface, APIOptions
@@ -90,6 +93,23 @@ async def remove_device_post(
9093
) -> Union[RemoveDeviceOkResult, GeneralErrorResponse]:
9194
user_id = session.get_user_id()
9295

96+
device_list = await options.recipe_implementation.list_devices(
97+
user_id=user_id, user_context=user_context
98+
)
99+
100+
# MFA should be completed when trying to remove a verified TOTP device
101+
if any(
102+
[
103+
device.name == device_name and device.verified
104+
for device in device_list.devices
105+
]
106+
):
107+
await session.assert_claims(
108+
[
109+
MultiFactorAuthClaim.validators.has_completed_mfa_requirements_for_auth()
110+
]
111+
)
112+
93113
return await options.recipe_implementation.remove_device(
94114
user_id=user_id,
95115
device_name=device_name,

supertokens_python/recipe/totp/api/remove_device.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,7 @@ async def handle_remove_device_api(
3535

3636
session = await get_session(
3737
api_options.request,
38-
override_global_claim_validators=lambda global_claim_validators, __, ___: [
39-
gcv for gcv in global_claim_validators if gcv.id == "st-mfa"
40-
],
38+
override_global_claim_validators=lambda _, __, ___: [],
4139
session_required=True,
4240
user_context=user_context,
4341
)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy