feat: VMess/VLESS 校验 uuid

This commit is contained in:
xream 2025-02-10 13:34:58 +08:00
parent 2ea46dcbf1
commit bd21d58fe7
No known key found for this signature in database
GPG Key ID: 1D2C5225471789F9
3 changed files with 38 additions and 6 deletions

View File

@ -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": {

View File

@ -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;

View File

@ -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,