From b4acd02007f385fe6d95721fbf2d8241772a7aea Mon Sep 17 00:00:00 2001 From: linked-danis Date: Thu, 12 Mar 2026 14:09:23 +0100 Subject: [PATCH] fix: validate URL in fetchLlmsTxt Prevent crash on invalid URLs. Changes: - Wrap URL constructor in try/catch - Return null for invalid URLs instead of throwing (cherry picked from commit 8b0acf314d0d8c84d6bf896438136e09caf8ba42) --- packages/core/src/utils/index.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/core/src/utils/index.ts b/packages/core/src/utils/index.ts index b740be1..150cfd5 100644 --- a/packages/core/src/utils/index.ts +++ b/packages/core/src/utils/index.ts @@ -61,7 +61,12 @@ const llmsTxtCache = new Map() /** Fetch /llms.txt for a URL's origin. Cached per origin, `null` = tried and not found. */ export async function fetchLlmsTxt(url: string): Promise { - const origin = new URL(url).origin + let origin: string + try { + origin = new URL(url).origin + } catch { + return null // Invalid URL + } if (llmsTxtCache.has(origin)) return llmsTxtCache.get(origin)! const endpoint = `${origin}/llms.txt`