From 3d47081be1c654a11e79a322cd2196c806b0e8bf Mon Sep 17 00:00:00 2001 From: "Builder.io" Date: Tue, 14 Oct 2025 01:49:04 +0000 Subject: [PATCH] Harden skip-agent network logic and remove HelloSkip strings cgen-e2cdb0fca2e44d0a907845424feb493a --- client/lib/skip-agent.ts | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/client/lib/skip-agent.ts b/client/lib/skip-agent.ts index fd5b074b..656969c9 100644 --- a/client/lib/skip-agent.ts +++ b/client/lib/skip-agent.ts @@ -223,8 +223,25 @@ const isSkipAgentReachable = async (): Promise => { const timeout = window.setTimeout(() => controller.abort(), 4000); try { + const agentSrc = getAgentSrc(); + if (!agentSrc) { + window.clearTimeout(timeout); + return false; + } + + let origin: string; + try { + origin = new URL(agentSrc).origin; + } catch (e) { + window.clearTimeout(timeout); + if (shouldEnableSkipAgent) { + console.warn("Invalid agent src; skipping status check", agentSrc); + } + return false; + } + const response = await fetch( - `${SKIP_AGENT_ORIGIN}/api/agent/status?agentId=${encodeURIComponent(SKIP_AGENT_ID)}`, + `${origin}/api/agent/status?agentId=${encodeURIComponent(getAgentId())}`, { method: "GET", mode: "cors", @@ -239,7 +256,7 @@ const isSkipAgentReachable = async (): Promise => { window.clearTimeout(timeout); if (!response.ok) { - throw new Error(`Skip agent status request failed with ${response.status}`); + throw new Error(`Agent status request failed with ${response.status}`); } const payload = (await response.json().catch(() => null)) as @@ -247,7 +264,7 @@ const isSkipAgentReachable = async (): Promise => { | null; if (payload && payload.active === false) { - throw new Error("Skip agent is inactive"); + throw new Error("Agent reported inactive"); } return true; @@ -255,7 +272,7 @@ const isSkipAgentReachable = async (): Promise => { window.clearTimeout(timeout); if (shouldEnableSkipAgent) { console.warn( - "Skip Agent status endpoint unreachable; skipping embed to prevent runtime errors:", + "Agent status endpoint unreachable; skipping embed to prevent runtime errors:", error, ); }