Spaces:
Running
Running
AuthorBot commited on
Commit ·
b9169bd
1
Parent(s): 8471fa1
Fix: Make TOTP optional when not configured — prevents locking out existing SuperAdmins
Browse files- app/dependencies.py +8 -9
app/dependencies.py
CHANGED
|
@@ -192,18 +192,17 @@ async def get_current_superadmin(
|
|
| 192 |
current_user=Depends(get_current_user),
|
| 193 |
x_totp_code: str = Header(default="", alias="X-TOTP-Code"),
|
| 194 |
):
|
| 195 |
-
"""Ensure the authenticated user is a SuperAdmin with valid TOTP."""
|
| 196 |
if current_user.role != "superadmin":
|
| 197 |
raise HTTPException(status_code=403, detail="SuperAdmin access required")
|
| 198 |
|
| 199 |
-
# R-007: TOTP verification
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
raise HTTPException(status_code=403, detail="Invalid TOTP code")
|
| 207 |
|
| 208 |
return current_user
|
| 209 |
|
|
|
|
| 192 |
current_user=Depends(get_current_user),
|
| 193 |
x_totp_code: str = Header(default="", alias="X-TOTP-Code"),
|
| 194 |
):
|
| 195 |
+
"""Ensure the authenticated user is a SuperAdmin with valid TOTP (if configured)."""
|
| 196 |
if current_user.role != "superadmin":
|
| 197 |
raise HTTPException(status_code=403, detail="SuperAdmin access required")
|
| 198 |
|
| 199 |
+
# R-007: TOTP verification — only enforced when SuperAdmin has TOTP configured
|
| 200 |
+
if current_user.totp_secret:
|
| 201 |
+
from app.core.access.totp import verify_totp
|
| 202 |
+
if not x_totp_code:
|
| 203 |
+
raise HTTPException(status_code=403, detail="TOTP code required")
|
| 204 |
+
if not verify_totp(current_user.totp_secret, x_totp_code):
|
| 205 |
+
raise HTTPException(status_code=403, detail="Invalid TOTP code")
|
|
|
|
| 206 |
|
| 207 |
return current_user
|
| 208 |
|