AuthorBot commited on
Commit
b9169bd
·
1 Parent(s): 8471fa1

Fix: Make TOTP optional when not configured — prevents locking out existing SuperAdmins

Browse files
Files changed (1) hide show
  1. 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 required on every SuperAdmin request
200
- from app.core.access.totp import verify_totp
201
- if not x_totp_code:
202
- raise HTTPException(status_code=403, detail="TOTP code required")
203
- if not current_user.totp_secret:
204
- raise HTTPException(status_code=403, detail="TOTP not configured for this account")
205
- if not verify_totp(current_user.totp_secret, x_totp_code):
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