Commit graph osint-dashboard/tests/test_auth.py
Author SHA1 Message Date
Sirius DevOps
ca1c73e1a6 news: per-article proximate geolocation + GET /api/news/blips
Every graded article now carries best-effort geo on article_scores:
- parse_map_scores extracts Location/Lat/Lon/Confidence per block
  (clamp_coords-validated; Unknown -> no geo; never invent a place)
- place-name-only blocks resolve via a vendored offline GeoNames
  gazetteer (cities15000 + admin1 + country->capital), confidence approx
- nullable location_name/lat/lon/location_confidence columns (alembic
  014, single head; idempotent ensure_tables mirror) + partial bbox index
- GET /api/news/blips: frozen contract, dedup by article id (latest geo
  wins), finite coords only, created_at DESC, bbox/since/limit, default
  1000 max 5000, public read like /api/news/map
- critical/high map pins, ticker, grading thresholds, dedupe unchanged

Tests: 50 new summarizer geo tests (161 total), 18 new blips API
contract tests; alembic upgrade heads proven on fresh DBs both start
orders; forced batch on test DB yielded 10 non-critical blips with geo.

Card: t_bc15eb53
2026-11-19 22:50:59 -05:00
Hermes Backend
72757e7c51 feat(auth): ADMIN_COOKIE_SECURE forces the session cookie Secure
Behind the cluster's HTTP origin listener Envoy normalizes
X-Forwarded-Proto to http, so _is_https() never fires and the session
cookie was issued without Secure. Add an explicit deploy-time flag:
set_session_cookie() now marks the cookie Secure when the env var is
1/true/yes (case-insensitive, stripped) or the header inference says
https. clear_session_cookie() is unchanged, SameSite stays Lax.

Tests cover flag-over-http, header-without-flag, and the local-dev path;
docs/auth.md and .env.example document the variable.
2026-11-13 21:15:05 -05:00
Sirius DevOps
c0a2454fdd feat(auth): public read-only HUD, admin-only API keys and mutations
Adds single-admin authentication to the dashboard. Anonymous visitors get a
read-only site (map + news); the one admin unlocks everything else.

- app/auth.py: deny-by-default ASGI middleware on /api/* with an explicit
  public read allowlist; /login page; /api/auth/{login,logout,me}; PBKDF2
  password hashing; HMAC-signed HttpOnly SameSite=Lax session cookie (7d,
  Secure behind X-Forwarded-Proto: https); 5-fail/15-min per-IP login limit;
  Origin/Referer host check on state-changing admin requests.
- Fails closed: missing ADMIN_PASSWORD_HASH or ADMIN_SESSION_SECRET -> admin
  routes 403 'admin auth not configured', public site unaffected.
- app/main.py: mounts the middleware + router (6 lines, no per-route decorators).
- app/static/index.html: hides Ingest/API Keys/Settings, the summarizer panel
  and geofence write controls until /api/auth/me says admin; adds a discreet
  SIGN IN link to /login. CSS gates fail closed without JS.
- tests/test_auth.py: 42 tests (anonymous 401s, login/logout, tampered and
  expired cookies, fail-closed, rate limit, CSRF, HUD markup).
- Existing API tests now send an admin session cookie for admin routes.

Public allowlist extends the spec's list with the remaining read-only GETs the
HUD calls (/api/stats, /api/conflicts, /api/place, /api/satellites,
/api/infrastructure, /api/map/gpsjam, /api/map/times, /api/fire-incidents,
/api/fire-perimeters, /api/weather-alerts, /api/storms, /api/geofences/{id}/at)
so an anonymous HUD is not half-broken.
2026-11-13 20:56:07 -05:00