Critical Fixes: - Remove /health/time endpoint exposing system time information * Prevents attackers from detecting time sync issues for TOTP attacks * Removed route and controller function, updated tests - Add email confirmation check to account data export * GDPR export now requires confirmed email address * Prevents unconfirmed accounts from accessing data export - Add path traversal validation for MIB archive uploads * Extract to temp directory, validate all paths, then copy if safe * Prevents malicious tar/zip files from writing outside target directory * Added validate_extracted_paths/1 helper function High Priority Fixes: - Add comprehensive input validation for mobile auth * Length limits: device_name (255), device_os (100), app_version (50), push_token (512) * Prevents database corruption and storage exhaustion - Add heartbeat rate limiting to agent channel * Limit database updates to once per 30 seconds (max ~2/min per agent) * Prevents malicious agents from exhausting database connections - Sanitize 500 error responses * Return generic error messages to clients * Log full details server-side with request_id for support * Prevents leaking stack traces and module names - Add message size limits to agent channel * 10MB maximum for all protobuf messages (result, heartbeat, error) * Prevents DoS attacks via oversized payloads Medium Priority Fixes: - Add GraphQL query depth limits (max_depth: 10) * Prevents DoS from deeply nested queries * Complements existing complexity limits Code Quality: - Refactor agent channel handlers to reduce nesting depth * Extract message processing into separate private functions * Fixes Credo warnings about excessive nesting * Improves code readability and maintainability Files changed: - lib/towerops_web/controllers/health_controller.ex - lib/towerops_web/controllers/api/account_data_controller.ex - lib/towerops_web/controllers/api/v1/mib_controller.ex - lib/towerops/mobile_sessions/mobile_session.ex - lib/towerops_web/channels/agent_channel.ex - lib/towerops_web/controllers/error_json.ex - lib/towerops_web/router.ex - CHANGELOG.txt - priv/static/changelog.txt - test/towerops_web/controllers/health_controller_test.exs - test/towerops_web/controllers/error_json_test.exs All 7,424 tests passing.
34 lines
1 KiB
Elixir
34 lines
1 KiB
Elixir
defmodule ToweropsWeb.ErrorJSON do
|
|
@moduledoc """
|
|
This module is invoked by your endpoint in case of errors on JSON requests.
|
|
|
|
See config/config.exs.
|
|
"""
|
|
|
|
require Logger
|
|
|
|
# Render 500 errors with generic message and request ID for support
|
|
# Never expose internal error details, stack traces, or module names to clients
|
|
def render("500.json", assigns) do
|
|
# Log full error details server-side for debugging
|
|
Logger.error("Internal server error",
|
|
assigns: inspect(assigns),
|
|
request_id: Logger.metadata()[:request_id]
|
|
)
|
|
|
|
# Return generic error to client with request ID for support tracking
|
|
%{
|
|
errors: %{
|
|
detail: "An unexpected error occurred. Please contact support if this persists.",
|
|
request_id: Logger.metadata()[:request_id]
|
|
}
|
|
}
|
|
end
|
|
|
|
# By default, Phoenix returns the status message from
|
|
# the template name. For example, "404.json" becomes
|
|
# "Not Found".
|
|
def render(template, _assigns) do
|
|
%{errors: %{detail: Phoenix.Controller.status_message_from_template(template)}}
|
|
end
|
|
end
|