Skip to content

Commit

Permalink
feat: VMess/VLESS 校验 uuid
Browse files Browse the repository at this point in the history
  • Loading branch information
xream committed Feb 10, 2025
1 parent 2ea46dc commit bd21d58
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 6 deletions.
2 changes: 1 addition & 1 deletion backend/package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
32 changes: 27 additions & 5 deletions backend/src/core/proxy-utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
isIPv4,
isIPv6,
isValidPortNumber,
isValidUUID,
isNotBlank,
ipAddress,
getRandomPort,
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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;
Expand Down
10 changes: 10 additions & 0 deletions backend/src/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit bd21d58

Please sign in to comment.