towerops/lib/towerops_web/live
Graham McIntire 6ef6b3d61d fix: comprehensive security audit fixes (#108)
This commit addresses multiple CRITICAL, HIGH, and MEDIUM severity security vulnerabilities identified in the security audit:

CRITICAL FIXES:
- Fix weak RNG for recovery codes - replaced Enum.random() with :crypto.strong_rand_bytes/1 for cryptographically secure token generation
- Fix subscription limit race conditions - moved free org and device quota checks inside transactions with FOR UPDATE locks to prevent concurrent bypass
- Fix default organization race condition - moved is_default check inside transaction to prevent multiple defaults per user

HIGH SEVERITY FIXES:
- Fix agent token deletion race condition - moved PubSub broadcast inside transaction to ensure agents only receive notification after successful deletion

MEDIUM SEVERITY FIXES:
- Fix LIKE wildcard injection in search - applied sanitize_like() to all user-facing search queries in devices.ex, sites.ex, and gaiia.ex to prevent enumeration attacks
- Fix Jason.decode! DoS - replaced with safe Jason.decode/1 with error handling in device_live/index.ex
- Fix SSRF vulnerability - added URL validation in HTTP executor to block requests to private/internal IP ranges (127.0.0.0/8, 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16, 169.254.0.0/16)
- Fix error information leakage - replaced inspect() in API responses with generic error messages, logging details server-side only
- Fix atom table pollution - HTTP method normalization now uses whitelist mapping instead of String.to_atom()

SECURITY IMPROVEMENTS:
- All quota checks now use pessimistic locking (SELECT FOR UPDATE) to prevent TOCTOU race conditions
- Private IP validation prevents cloud metadata service access (169.254.169.254)
- DNS resolution performed before HTTP requests to detect IP spoofing
- Error details logged server-side but not exposed to clients

Files changed:
- lib/towerops/accounts/user_recovery_code.ex
- lib/towerops/organizations.ex
- lib/towerops/devices.ex
- lib/towerops/sites.ex
- lib/towerops/gaiia.ex
- lib/towerops/agents.ex
- lib/towerops/monitoring/executors/http_executor.ex
- lib/towerops_web/live/device_live/index.ex
- lib/towerops_web/controllers/api/v1/mib_controller.ex
- lib/towerops_web/controllers/api/v1/agent_release_webhook_controller.ex
- lib/towerops_web/controllers/api/v1/geoip_controller.ex

Reviewed-on: graham/towerops-web#108
2026-03-22 10:10:27 -05:00
..
account_live Fix dark mode inconsistencies across all pages 2026-02-16 10:31:52 -06:00
admin rename "Admin Dashboard" to "Dashboard" 2026-03-10 13:36:03 -05:00
agent_live test: improve test coverage and code quality 2026-03-15 14:49:55 -05:00
alert_live Integrate Gleam into the build pipeline and rewrite three pure-function modules (#98) 2026-03-21 07:30:36 -05:00
check_live add auto ICMP ping check for all devices (#68) 2026-03-17 17:55:23 -05:00
components logging fix and some other codex fixes 2026-03-10 15:04:28 -05:00
device_live fix: comprehensive security audit fixes (#108) 2026-03-22 10:10:27 -05:00
escalation_policy_live fix: input validation, SSRF, API hardening, and cookie security 2026-03-14 14:48:59 -05:00
graph_live Integrate Gleam into the build pipeline and rewrite three pure-function modules (#98) 2026-03-21 07:30:36 -05:00
help_live Add GeoIP import HTTP tests 2026-03-10 16:02:49 -05:00
helpers refactor: centralize LiveView access control checks 2026-02-04 17:51:05 -06:00
insights_live improve Gaiia integration UX 2026-03-12 13:04:17 -05:00
maintenance_live Add page descriptions + rename Schedules to On-Call 2026-03-13 15:30:39 -05:00
map_live i18n: wrap all user-facing strings in gettext() 2026-02-14 17:44:01 -06:00
mikrotik_backup_live i18n: wrap all user-facing strings in gettext() 2026-02-14 17:44:01 -06:00
org fix: make sidebar sticky with header and resolve all credo issues (#32) 2026-03-15 18:19:09 -05:00
org_live fix: org switching now correctly updates session 2026-03-04 17:04:49 -06:00
schedule_live fix: input validation, SSRF, API hardening, and cookie security 2026-03-14 14:48:59 -05:00
site_live remove-add-device-from-sites (#37) 2026-03-15 18:46:16 -05:00
trace_live Add page descriptions + rename Schedules to On-Call 2026-03-13 15:30:39 -05:00
user_settings_live feat: add 12/24-hour time format setting with consistent timezone display 2026-02-13 15:16:29 -06:00
activity_feed_live.ex fix: comprehensive bug fixes from reliability audit 2026-03-05 08:53:30 -06:00
activity_feed_live.html.heex tweaks (#85) 2026-03-19 13:51:02 -05:00
capacity_live.ex feat: add capacity insight worker, UI, and reporting views 2026-03-07 14:42:40 -06:00
capacity_live.html.heex feat: add capacity insight worker, UI, and reporting views 2026-03-07 14:42:40 -06:00
changelog_live.ex fix: add navigation and footer to changelog page 2026-03-09 15:59:13 -05:00
config_timeline_live.ex ux: improve navigation, tooltips, and discoverability across pages 2026-03-12 13:40:10 -05:00
dashboard_live.ex fix/subscriber-count-pluralization (#84) 2026-03-19 12:14:50 -05:00
dashboard_live.html.heex fix/subscriber-count-pluralization (#84) 2026-03-19 12:14:50 -05:00
mobile_qr_live.ex fix-mobile-qr-layout (#44) 2026-03-16 14:24:51 -05:00
network_map_live.ex feat: WISP-tuned network map enhancements (TOW-16) 2026-03-15 14:06:06 -05:00
network_map_live.html.heex TOW-44: Hide RF Links UI elements from network map (#45) 2026-03-16 15:12:09 -05:00
onboarding_live.ex Prevent Oban polling/monitoring job stacking per device 2026-02-16 16:37:48 -06:00
onboarding_live.html.heex Prevent Oban polling/monitoring job stacking per device 2026-02-16 16:37:48 -06:00
reports_live.ex fix: make sidebar sticky with header and resolve all credo issues (#32) 2026-03-15 18:19:09 -05:00
reports_live.html.heex fix: make sidebar sticky with header and resolve all credo issues (#32) 2026-03-15 18:19:09 -05:00
rf_link_health_live.ex fix: make sidebar sticky with header and resolve all credo issues (#32) 2026-03-15 18:19:09 -05:00
rf_link_health_live.html.heex fix: make sidebar sticky with header and resolve all credo issues (#32) 2026-03-15 18:19:09 -05:00
status_page_live.ex fix: make sidebar sticky with header and resolve all credo issues (#32) 2026-03-15 18:19:09 -05:00
status_page_live.html.heex fix: make sidebar sticky with header and resolve all credo issues (#32) 2026-03-15 18:19:09 -05:00
user_registration_live.ex fix: status emoji accumulating in page title and add missing page titles 2026-03-11 09:54:18 -05:00
user_reset_password_live.ex fix: status emoji accumulating in page title and add missing page titles 2026-03-11 09:54:18 -05:00
user_settings_live.ex gdpr (#86) 2026-03-19 14:28:31 -05:00
user_settings_live.html.heex Fix DB pool exhaustion and settings page crashes (#88) 2026-03-19 15:16:34 -05:00