920920bc67
Security - SSRF: async DNS resolver; allow_redirects=False on all outbound clients; matrix homeserver_url validated on create/update/test; update_provider and email_bot merge incoming config and reject ***-masked secrets. - Auth: bcrypt offloaded to asyncio.to_thread; JWT now carries iss/aud + leeway and rejects missing claims; setup TOCTOU closed inside a transaction; rate limits extended (default 600/min, 10/min on password change, 30/min on needs-setup); constant-time login to prevent username enumeration. - Config: rejects known dev secret keys; validates CORS origin schemes, port range, token lifetimes. - Webhook handlers stream-read body with a 1 MiB cap; Discord 429 retries bounded (3 attempts, Retry-After capped at 60 s). - CSP + HSTS added to SecurityHeadersMiddleware. Async / runtime - SQLite engine: WAL, synchronous=NORMAL, foreign_keys=ON, busy_timeout, pool_pre_ping, dispose on shutdown. - Lifespan shutdown now stops scheduler before closing HTTP session and disposing the engine. - Shared aiohttp session locked against concurrent first-caller races; core NotificationDispatcher accepts and reuses it. - Storage and scheduled backup writes wrapped in asyncio.to_thread. - NUT client writes bounded by asyncio.wait_for. - Telegram poller switched from 3 s short-poll to 30 s interval + 25 s long-poll (~10x fewer API calls). Database - New performance-indexes migration covers every FK/owner column and hot-path composite (notification_tracker(provider_id, enabled); event_log(user_id, created_at DESC); webhook_payload_log(provider_id, created_at DESC); action_execution(action_id, started_at DESC)). - New schema_version table for future upgrade gating. - __system__ placeholder user (id=0) seeded so user_id=0 system defaults satisfy the newly enforced FK; filtered out of /auth/needs-setup, /api/users, and setup. - list_notification_trackers rewritten to batched loads (was 1+N+N*M). - Retention job extended to event_log, webhook_payload_log, and action_execution; retention days exposed as a setting. Scheduler - AsyncIOScheduler job_defaults: coalesce, misfire_grace_time=300, max_instances=1. Ops - uvicorn runs with proxy_headers, forwarded_allow_ips, timeout_graceful_shutdown; access log suppressed in non-debug. - FastAPI version string now reads from importlib.metadata. - New /api/ready endpoint separate from /api/health. - docker-compose drops the ALLOW_PRIVATE_URLS=1 default, adds mem/cpu/pid limits, read_only + tmpfs, cap_drop:ALL, no-new-privileges; healthcheck targets /api/ready. - CI now runs on push/PR with backend pytest, frontend svelte-check + build, and a non-push image build; release workflow gated on tests, publishes immutable sha-<commit> image tag, adds Trivy scan. Tests - New packages/server/tests/ with 29 passing tests: config validation, JWT round-trip + aud/alg=none rejection, SSRF scheme and private-range enforcement (sync + async), Discord bounded retry, and a lifespan-level /api/health + /api/ready smoke check. - Renamed the misnamed services/test_dispatch.py to manual_dispatch.py so pytest never auto-collects production code. Frontend - /login now redirects already-authenticated users to /, shows a distinct 'backend unreachable' banner (en/ru) when /auth/needs-setup fails.
43 lines
1.3 KiB
Bash
43 lines
1.3 KiB
Bash
#!/usr/bin/env bash
|
|
# Restart the backend dev server.
|
|
# Usage: bash scripts/restart-backend.sh
|
|
|
|
cd "$(dirname "$0")/.."
|
|
|
|
# Kill existing backend
|
|
PID=$(netstat -ano 2>/dev/null | grep ':8420.*LISTENING' | awk '{print $5}' | head -1)
|
|
if [ -n "$PID" ]; then
|
|
taskkill //F //PID "$PID" 2>/dev/null || true
|
|
sleep 1
|
|
fi
|
|
|
|
# Resolve python — prefer py launcher on Windows (python3 may be the Store stub)
|
|
if command -v py &>/dev/null; then
|
|
PYTHON=$(py -3 -c "import sys; print(sys.executable)" 2>/dev/null)
|
|
elif command -v python3 &>/dev/null && python3 --version &>/dev/null; then
|
|
PYTHON=python3
|
|
elif command -v python &>/dev/null && python --version &>/dev/null; then
|
|
PYTHON=python
|
|
else
|
|
echo "Python not found"; exit 1
|
|
fi
|
|
|
|
# Start backend
|
|
export NOTIFY_BRIDGE_DATA_DIR=./test-data
|
|
export NOTIFY_BRIDGE_SECRET_KEY=dev-only-pwIOUsKmfn4CYWQ9hCRs5lmI3GgrVlXSu2nqFzGW
|
|
# Dev targets (homelab Immich / Gitea / etc.) live on RFC1918 ranges; the SSRF
|
|
# guard rejects private addresses by default, which would make trackers fail.
|
|
export NOTIFY_BRIDGE_ALLOW_PRIVATE_URLS=1
|
|
nohup "$PYTHON" -m uvicorn notify_bridge_server.main:app \
|
|
--host 0.0.0.0 --port 8420 > .backend.log 2>&1 &
|
|
|
|
sleep 3
|
|
if curl -sf http://localhost:8420/api/health; then
|
|
echo ""
|
|
echo "Backend started (PID $!)"
|
|
else
|
|
echo "Backend failed to start. Log:"
|
|
tail -20 .backend.log
|
|
exit 1
|
|
fi
|