fix(hub): require JWT on netstats endpoints (ref #758)

Add user=Depends(require_jwt) to netstats_summary and netstats_series,
matching the sibling pattern used throughout the same router.
Drop redundant int() casts on already-typed window/step params.
This commit is contained in:
CyberMind-FR 2026-06-27 11:29:00 +02:00
parent d91f6a8b67
commit fd9f535e63

View File

@ -758,19 +758,19 @@ async def network_summary(user=Depends(require_jwt)):
@router.get("/netstats/summary")
async def netstats_summary() -> dict:
async def netstats_summary(user=Depends(require_jwt)) -> dict:
"""#758 — latest network-stats snapshot (categories, interfaces, drops).
Read-only; served from the collector's JSON snapshot (cheap)."""
return netstats.read_snapshot()
@router.get("/netstats/series")
async def netstats_series(window: int = 86400, step: int = 300) -> dict:
async def netstats_series(window: int = 86400, step: int = 300, user=Depends(require_jwt)) -> dict:
"""#758 — reset-aware drops/throughput time-series for the dashboard charts.
Read-only over the collector's SQLite DB."""
import sqlite3 as _sql
w = max(300, min(int(window), 7 * 86400))
s = max(30, min(int(step), 3600))
w = max(300, min(window, 7 * 86400))
s = max(30, min(step, 3600))
if not netstats.DB_PATH.exists():
return {"window_s": w, "step_s": s, "drops": {}, "in_bps": {}, "out_bps": {}}
conn = _sql.connect(f"file:{netstats.DB_PATH}?mode=ro", uri=True)