diff --git a/web/app/components/plugins/plugin-detail-panel/subscription-list/create/common-modal.tsx b/web/app/components/plugins/plugin-detail-panel/subscription-list/create/common-modal.tsx index dd5309559f..00c0160056 100644 --- a/web/app/components/plugins/plugin-detail-panel/subscription-list/create/common-modal.tsx +++ b/web/app/components/plugins/plugin-detail-panel/subscription-list/create/common-modal.tsx @@ -18,6 +18,7 @@ import { useVerifyTriggerSubscriptionBuilder, } from '@/service/use-triggers' import { parsePluginErrorMessage } from '@/utils/error-parser' +import { isPrivateOrLocalAddress } from '@/utils/urlValidation' import { RiLoader2Line } from '@remixicon/react' import { debounce } from 'lodash-es' import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react' @@ -66,43 +67,6 @@ const normalizeFormType = (type: FormTypeEnum | string): FormTypeEnum => { } } -// Check if URL is a private/local network address -const isPrivateOrLocalAddress = (url: string): boolean => { - try { - const urlObj = new URL(url) - const hostname = urlObj.hostname.toLowerCase() - - // Check for localhost - if (hostname === 'localhost' || hostname === '127.0.0.1' || hostname === '::1') - return true - - // Check for private IP ranges - const ipv4Regex = /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/ - const ipv4Match = hostname.match(ipv4Regex) - if (ipv4Match) { - const [, a, b] = ipv4Match.map(Number) - // 10.0.0.0/8 - if (a === 10) - return true - // 172.16.0.0/12 - if (a === 172 && b >= 16 && b <= 31) - return true - // 192.168.0.0/16 - if (a === 192 && b === 168) - return true - // 169.254.0.0/16 (link-local) - if (a === 169 && b === 254) - return true - } - - // Check for .local domains - return hostname.endsWith('.local') - } - catch { - return false - } -} - const StatusStep = ({ isActive, text }: { isActive: boolean, text: string }) => { return