Use case-insensitive role check (user.role | lower == 'admin') so the
password field shows correctly even if the role was stored with mixed
case (e.g. 'Admin' via the Streamlit interface).
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Password field in edit user modal is now hidden for managers.
Backend already blocks non-admins from updating users.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Adds a DELETE USER button to the edit user modal with a confirmation
dialog. Includes a self-deletion guard on both the frontend and backend.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Password complexity: enforce 12+ chars, uppercase, lowercase, number, and
special character on /setup-password and admin password-reset flow; show
requirements hint on login page
- Data retention: cleanup_old_logs(days=90) purges activity_log and
interactions rows older than 90 days; runs at every startup in lifespan
- PII hashing: add _hash_quote() SHA-256 helper (16-char prefix) for
correlation without storing raw customer text in audit records; activity_log
already stores no raw quotes — helper available for future log calls
- import hashlib added to main.py
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Structured JSON logging (core/logging_config.py):
- Replace ad-hoc print() statements with logger.info/warning/error
- Each log line is one JSON object: timestamp (ISO8601 UTC), level, logger,
message, module, exception traceback, plus user-supplied 'extra' fields
- Quiets uvicorn.access and huggingface_hub noise to WARNING
- Configurable via LOG_LEVEL env var
/health endpoint (public, no auth):
- 200 + {"status":"healthy"} → DB ok, predictor loaded
- 200 + {"status":"degraded", ...} → DB ok, predictor still warming
- 503 + {"status":"unhealthy","reason"} → DB unreachable, restart needed
- Compatible with HF Spaces / Railway / uptime monitors
Fail-fast model loading:
- After download attempt, verify distilbert_stage1 exists on disk
- If missing, raise RuntimeError to prevent app from starting in a broken
state where every /api/predict returns 500 at runtime
- Operators can override with ALLOW_DEGRADED_STARTUP=1 (offline dev, etc.)
- Critical-level log includ…
Rate limiting (slowapi):
- /login: 10 attempts/minute per IP
- /setup-password: 3 attempts/10min per IP
- /admin/export/users: 5 exports/hour
- /browse/export.csv: 10 exports/hour
- Uses X-Forwarded-For for HF Spaces proxy compatibility
- Logs failed login attempts with IP for forensics
Admin-only restrictions (close manager privilege escalation):
- /admin/users/update: managers can no longer reset passwords or modify users
(per requirement: managers can only ADD users, not edit them)
- /admin/export/users: only admins can exfiltrate user emails/login times
- Edit button hidden in admin UI for managers
Audit trail:
- Failed logins logged with IP
- All CSV exports logged (users + browse responses)
- Password change actions explicitly flagged in activity log
Input validation (Pydantic Field constraints):
- PredictRequest: quote 5000c, group 50c, service 200c
- CorrectionRequest: all fields capped (200c types, 5000c quote)
- BrowseEditRequest: response/solution 10000c, follow-up 2000…
Fix admin page encoding issues and use company logo as favicon
- Replace company logo as favicon (browser tab icon) using logo-transparent.png
- Fix admin tab title from corrupted 'Admin â€" Explorer' to 'Admin - Explorer'
- Fix Export CSV button: replace garbled char with proper down arrow (↓)
- Replace garbled trash emoji in corrections delete button with 'Delete' text
Cache-bust favicon version to v=3 to force browser refresh.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Fix critical Jinja2 syntax error in admin.html corrections delete
Smart/curly quotes (U+2018, U+2019) were accidentally introduced
during the role hierarchy refactor edit, breaking Jinja2 parsing
and causing Internal Server Error on /admin page load.
Replaced with proper ASCII single quotes.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Fix: Replace Jinja2 'in' operator with explicit or checks for template compatibility
Changed 'user.role in [list]' to 'user.role == 'admin' or user.role == 'manager''
to avoid potential Jinja2 compatibility issues.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Fix: Use HTTPException instead of invalid RedirectResponse status code
RedirectResponse only accepts redirect status codes (301, 302, 303, 307, 308),
not 403. Changed admin_corrections_delete to use HTTPException for authorization errors.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Rework role hierarchy: admin/manager/staff with granular permissions
Role structure:
- Admin (3): Full access to all pages and operations
- Manager (2): Access all pages + admin panel, but can only add users (not delete)
- Staff (1): Access consultants/analytics/browse (read-only), can save corrections
Changes:
- Rename employee→manager, viewer→staff in role definitions
- Update PAGE_ACCESS to reflect new permissions
- Add admin-only authorization checks on all delete endpoints
- /admin/corrections/delete
- /browse/delete, /browse/edit
- /analytics/delete
- Update admin.html with new role select options (staff/manager/admin)
- Hide delete buttons from non-admin users in corrections table
- Allow managers to access admin navigation link in base.html and home.html
- Add .role-manager CSS styling (blue/purple)
- Update database default role from employee to staff
- Remove obsolete .role-employee CSS selector
Backward compatibility: Existing 'employee' and 'viewer' users need migration:
UPDATE users SET role = 'manager' WHERE role = 'employee';
…
Replace X-Frame-Options: DENY with CSP frame-ancestors to allow
HF Spaces to embed the app while still blocking other origins.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Apply security hardening across FastAPI and Webapp
- Remove hardcoded admin email fallback; require ADMIN_EMAIL env var
- Reduce session lifetime from 3650 days to 30 days
- Set secure=True on session cookies (opt-out via ENVIRONMENT=local)
- Add HTTP security headers middleware (X-Frame-Options, X-Content-Type-Options, HSTS, etc.)
- Require authentication on /api/services and /api/type-cluster-map
- Sanitize 500 error messages to avoid leaking exception details
- Validate role enum on user add/update (whitelist: admin/employee/viewer)
- Add 5000-char limit on prediction quotes; raise password minimum to 8 chars
- Call cleanup_expired_sessions() on startup to prune stale tokens
- Guard admin seed row against empty ADMIN_EMAIL in both databases
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>