From bd21d58fe7d6160fc1f42dc8359bfd09c1e5a248 Mon Sep 17 00:00:00 2001 From: xream Date: Mon, 10 Feb 2025 13:34:58 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20VMess/VLESS=20=E6=A0=A1=E9=AA=8C=20uuid?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/package.json | 2 +- backend/src/core/proxy-utils/index.js | 32 ++++++++++++++++++++++----- backend/src/utils/index.js | 10 +++++++++ 3 files changed, 38 insertions(+), 6 deletions(-) diff --git a/backend/package.json b/backend/package.json index 51f995568..98549726c 100644 --- a/backend/package.json +++ b/backend/package.json @@ -1,6 +1,6 @@ { "name": "sub-store", - "version": "2.16.33", + "version": "2.16.34", "description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and Shadowrocket.", "main": "src/main.js", "scripts": { diff --git a/backend/src/core/proxy-utils/index.js b/backend/src/core/proxy-utils/index.js index ec03e4ea0..b14ab6232 100644 --- a/backend/src/core/proxy-utils/index.js +++ b/backend/src/core/proxy-utils/index.js @@ -6,6 +6,7 @@ import { isIPv4, isIPv6, isValidPortNumber, + isValidUUID, isNotBlank, ipAddress, getRandomPort, @@ -76,7 +77,16 @@ function parse(raw) { $.error(`Failed to parse line: ${line}`); } } - return proxies; + return proxies.filter((proxy) => { + if (['vless', 'vmess'].includes(proxy.type)) { + const isProxyUUIDValid = isValidUUID(proxy.uuid); + if (!isProxyUUIDValid) { + $.error(`UUID is invalid: ${proxy.name} ${proxy.uuid}`); + } + return isProxyUUIDValid; + } + return true; + }); } async function processFn( @@ -215,10 +225,22 @@ function produce(proxies, targetPlatform, type, opts = {}) { ); // filter unsupported proxies - proxies = proxies.filter( - (proxy) => - !(proxy.supported && proxy.supported[targetPlatform] === false), - ); + proxies = proxies.filter((proxy) => { + // 检查代理是否支持目标平台 + if (proxy.supported && proxy.supported[targetPlatform] === false) { + return false; + } + + // 对于 vless 和 vmess 代理,需要额外验证 UUID + if (['vless', 'vmess'].includes(proxy.type)) { + const isProxyUUIDValid = isValidUUID(proxy.uuid); + if (!isProxyUUIDValid) + $.error(`UUID is invalid: ${proxy.name} ${proxy.uuid}`); + return isProxyUUIDValid; + } + + return true; + }); proxies = proxies.map((proxy) => { proxy._resolved = proxy.resolved; diff --git a/backend/src/utils/index.js b/backend/src/utils/index.js index 8330beaaa..daf6e769f 100644 --- a/backend/src/utils/index.js +++ b/backend/src/utils/index.js @@ -117,7 +117,17 @@ function numberToString(value) { : BigInt(value).toString(); } +function isValidUUID(uuid) { + return ( + typeof uuid === 'string' && + /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/.test( + uuid, + ) + ); +} + export { + isValidUUID, ipAddress, isIPv4, isIPv6,