Skip to content

Commit 070974e

Browse files
committed
fix: validate MFA claim before allowing TOTP device removal
- Fixes an issue where `removeDevice` API allowed removing TOTP devices without the user completing MFA.
1 parent 1273c46 commit 070974e

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

supertokens_python/recipe/totp/api/remove_device.py

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

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

tests/test-server/test_functions_mapper.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,10 @@ async def get_mfa_requirements_for_auth(
142142
required_secondary_factors_for_tenant: Any,
143143
user_context: Dict[str, Any],
144144
) -> MFARequirementList:
145+
# Test specifies an override, return the required data
146+
if 'getMFARequirementsForAuth:async()=>["totp"]' in eval_str:
147+
return ["totp"]
148+
145149
return ["otp-phone"] if user_context.get("requireFactor") else []
146150

147151
original_implementation.get_mfa_requirements_for_auth = (

0 commit comments

Comments
 (0)