fix: timing-safe key comparison and network-error state in liveview

Use hmac.compare_digest() to prevent timing-based key enumeration.
Distinguish network failures from invalid-key errors in the frontend.
This commit is contained in:
Pouzor
2026-03-28 15:30:09 +01:00
parent 210304394e
commit 5897be70c2
3 changed files with 8 additions and 5 deletions
+2 -1
View File
@@ -1,3 +1,4 @@
import hmac
from typing import Any
from fastapi import APIRouter, Depends, HTTPException, Query
@@ -26,7 +27,7 @@ async def liveview_canvas(
"""
if not settings.liveview_key:
raise HTTPException(status_code=403, detail="Live view is disabled")
if not key or key != settings.liveview_key:
if not key or not hmac.compare_digest(key, settings.liveview_key):
raise HTTPException(status_code=403, detail="Invalid live view key")
nodes = (await db.execute(select(Node))).scalars().all()