From e954c7930a4838e0030c3058e7ef5f435c13968b Mon Sep 17 00:00:00 2001 From: Graham McIntie Date: Sat, 14 Feb 2026 17:15:17 -0600 Subject: [PATCH] Fix Gaiia webhook timestamp: Gaiia sends millis, not seconds The timestamp check was comparing millisecond timestamps against System.system_time(:second), causing every webhook to be rejected as 'expired'. Now normalizes timestamps >10 digits to seconds. --- .../controllers/api/v1/gaiia_webhook_controller.ex | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/towerops_web/controllers/api/v1/gaiia_webhook_controller.ex b/lib/towerops_web/controllers/api/v1/gaiia_webhook_controller.ex index 083b600f..1c90cd7c 100644 --- a/lib/towerops_web/controllers/api/v1/gaiia_webhook_controller.ex +++ b/lib/towerops_web/controllers/api/v1/gaiia_webhook_controller.ex @@ -149,7 +149,9 @@ defmodule ToweropsWeb.Api.V1.GaiiaWebhookController do defp check_timestamp(timestamp_str) do case Integer.parse(timestamp_str) do {ts, ""} -> - age = abs(System.system_time(:second) - ts) + # Gaiia sends timestamps in milliseconds — normalize to seconds + ts_seconds = if ts > 9_999_999_999, do: div(ts, 1000), else: ts + age = abs(System.system_time(:second) - ts_seconds) if age <= @max_age_seconds, do: :ok, else: {:error, :expired} _ ->