Self-hosted homelab infrastructure visualizer — interactive network diagram with live status monitoring
TypeScript diagramhomelabhomelab-infrastructure-observabilitynetworkproxmox-veself-hostedzigbeezwavezwave-js
security: fix C3, C1 and H1
Pouzordbfc8a2a328b
diff --git a/.gitignore b/.gitignoreindex 3856de0..4b69641 100644--- a/.gitignore+++ b/.gitignore@@ -41,6 +41,9 @@ build/htmlcov/.coverage+# App config — contains credentials, never commit+backend/config.yml+# SQLite*.db*.db-shmdiff --git a/backend/.env.example b/backend/.env.examplenew file mode 100644index 0000000..14c8692--- /dev/null+++ b/backend/.env.example@@ -0,0 +1,4 @@+SECRET_KEY=<generate with: python3 -c "import secrets; print(secrets.token_urlsafe(32))">+SQLITE_PATH=./data/homelab.db+CONFIG_PATH=./config.yml+CORS_ORIGINS=["http://localhost:5173","http://localhost:3000"]diff --git a/backend/app/api/routes/status.py b/backend/app/api/routes/status.pyindex d2f4894..106af8c 100644--- a/backend/app/api/routes/status.py+++ b/backend/app/api/routes/status.py@@ -2,6 +2,8 @@ import jsonfrom fastapi import APIRouter, WebSocket, WebSocketDisconnect+from app.core.security import decode_token+router = APIRouter()# Active WebSocket connections@@ -9,7 +11,10 @@ _connections: list[WebSocket] = []@router.websocket("/ws/status")-async def ws_status(websocket: WebSocket) -> None:+async def ws_status(websocket: WebSocket, token: str | None = None) -> None:+ if not token or not decode_token(token):+ await websocket.close(code=1008) # Policy Violation+ returnawait websocket.accept()_connections.append(websocket)try:diff --git a/backend/app/core/config.py b/backend/app/core/config.pyindex 96f40bc..1c8f4b3 100644--- a/backend/app/core/config.py+++ b/backend/app/core/config.py@@ -4,7 +4,7 @@ from pydantic_settings import BaseSettings, SettingsConfigDictclass Settings(BaseSettings):model_config = SettingsConfigDict(env_file=".env", env_file_encoding="utf-8")- secret_key: str = "change_me_in_production"+ secret_key: str # Required — set SECRET_KEY in .envsqlite_path: str = "./data/homelab.db"config_path: str = "./config.yml"cors_origins: list[str] = ["http://localhost:5173", "http://localhost:3000"]diff --git a/backend/config.yml b/backend/config.ymldeleted file mode 100644index c902bc2..0000000--- a/backend/config.yml+++ /dev/null@@ -1,9 +0,0 @@-auth:- password_hash: $2b$12$o/LWyvmBc978CNpSsHxcveXN0WqjAGW/gBR0.U.HURWbaYD3GCDqS- username: admin-scanner:- interval: null- ranges:- - 192.168.1.0/24-status_checker:- interval_seconds: 60diff --git a/backend/config.yml.example b/backend/config.yml.examplenew file mode 100644index 0000000..25594a5--- /dev/null+++ b/backend/config.yml.example@@ -0,0 +1,9 @@+auth:+ username: admin+ password_hash: "" # Generate with: python -c "from passlib.context import CryptContext; print(CryptContext(schemes=['bcrypt']).hash('yourpassword'))"+scanner:+ interval: null+ ranges:+ - 192.168.1.0/24+status_checker:+ interval_seconds: 60diff --git a/frontend/src/hooks/useStatusPolling.ts b/frontend/src/hooks/useStatusPolling.tsindex c7405b3..a39103b 100644--- a/frontend/src/hooks/useStatusPolling.ts+++ b/frontend/src/hooks/useStatusPolling.ts@@ -22,7 +22,7 @@ export function useStatusPolling() {const protocol = window.location.protocol === 'https:' ? 'wss' : 'ws'const host = window.location.hostname- const url = `${protocol}://${host}:8000/api/v1/status/ws/status`+ const url = `${protocol}://${host}:8000/api/v1/status/ws/status?token=${encodeURIComponent(token)}`const ws = new WebSocket(url)wsRef.current = ws