From 0caeaf6e5cdf7c130f7644d8346b74f18b4af227 Mon Sep 17 00:00:00 2001 From: Novice Date: Tue, 28 Oct 2025 17:30:01 +0800 Subject: [PATCH] chore: improve mcp server url validation (#27558) --- web/app/components/tools/mcp/modal.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/web/app/components/tools/mcp/modal.tsx b/web/app/components/tools/mcp/modal.tsx index 987a517ef5..ad528e9fb9 100644 --- a/web/app/components/tools/mcp/modal.tsx +++ b/web/app/components/tools/mcp/modal.tsx @@ -141,8 +141,8 @@ const MCPModal = ({ const isValidUrl = (string: string) => { try { - const urlPattern = /^(https?:\/\/)((([a-z\d]([a-z\d-]*[a-z\d])*)\.)+[a-z]{2,}|((\d{1,3}\.){3}\d{1,3})|localhost)(:\d+)?(\/[-a-z\d%_.~+]*)*(\?[;&a-z\d%_.~+=-]*)?/i - return urlPattern.test(string) + const url = new URL(string) + return url.protocol === 'http:' || url.protocol === 'https:' } catch { return false