1. A security dependency that never runs
Symptom
The endpoint has an auth dependency listed and is completely open.
The pattern
@app.get("/admin/users")
async def list_users(current_user=Depends(get_current_user)):
# get_current_user returns None for anonymous callers instead of raising
return await db.fetch_all("SELECT * FROM users")Why it bites
The dependency resolves successfully with a `None` user and the handler never checks it. FastAPI enforces nothing about the value — a dependency that returns rather than raises is documentation, not a gate.
The fix
async def require_admin(user=Depends(get_current_user)):
if user is None:
raise HTTPException(401, "Not authenticated")
if not user.is_admin:
raise HTTPException(403, "Forbidden")
return user
@app.get("/admin/users", dependencies=[Depends(require_admin)])
async def list_users():
...