towerops/docs
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
..
features docs: update nix guide for TimescaleDB, add org settings and device monitoring docs 2026-02-14 11:28:57 -06:00
librenms-audit docs: add comprehensive priority vendors analysis for LibreNMS parity 2026-02-12 08:49:32 -06:00
plans fix: comprehensive security audit fixes (#108) 2026-03-22 10:10:27 -05:00
references fix: input validation, SSRF, API hardening, and cookie security 2026-03-14 14:48:59 -05:00
templates fix: input validation, SSRF, API hardening, and cookie security 2026-03-14 14:48:59 -05:00
ARCHITECTURE.md fix: input validation, SSRF, API hardening, and cookie security 2026-03-14 14:48:59 -05:00
COMPETITIVE_ANALYSIS.md fix: input validation, SSRF, API hardening, and cookie security 2026-03-14 14:48:59 -05:00
CONVENTIONS.md fix: input validation, SSRF, API hardening, and cookie security 2026-03-14 14:48:59 -05:00
librenms-feature-parity.md docs: add comprehensive LibreNMS feature parity summary 2026-02-12 12:01:55 -06:00
librenms-parity-audit-complete.md docs: add comprehensive LibreNMS parity audit report 2026-02-12 11:56:12 -06:00
lldp-topology-discovery-analysis.md docs: add LLDP topology discovery analysis from lldp2map research 2026-03-05 10:39:09 -06:00
NIX-VERIFICATION.md feat: Add comprehensive Nix flakes integration 2026-02-07 12:26:54 -06:00
nix.md docs: update nix guide for TimescaleDB, add org settings and device monitoring docs 2026-02-14 11:28:57 -06:00
README-nix-section.md feat: Add comprehensive Nix flakes integration 2026-02-07 12:26:54 -06:00
SECURITY_AUDIT_2026_03_14.md fix: input validation, SSRF, API hardening, and cookie security 2026-03-14 14:48:59 -05:00
SECURITY_AUDIT_API.md fix: input validation, SSRF, API hardening, and cookie security 2026-03-14 14:48:59 -05:00
SECURITY_AUDIT_INPUT_VALIDATION.md fix: input validation, SSRF, API hardening, and cookie security 2026-03-14 14:48:59 -05:00
TEST_COVERAGE.md fix: input validation, SSRF, API hardening, and cookie security 2026-03-14 14:48:59 -05:00