Skip to content

Commit bd21d58

Browse files
committed
feat: VMess/VLESS 校验 uuid
1 parent 2ea46dc commit bd21d58

File tree

3 files changed

+38
-6
lines changed

3 files changed

+38
-6
lines changed

backend/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "sub-store",
3-
"version": "2.16.33",
3+
"version": "2.16.34",
44
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and Shadowrocket.",
55
"main": "src/main.js",
66
"scripts": {

backend/src/core/proxy-utils/index.js

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
isIPv4,
77
isIPv6,
88
isValidPortNumber,
9+
isValidUUID,
910
isNotBlank,
1011
ipAddress,
1112
getRandomPort,
@@ -76,7 +77,16 @@ function parse(raw) {
7677
$.error(`Failed to parse line: ${line}`);
7778
}
7879
}
79-
return proxies;
80+
return proxies.filter((proxy) => {
81+
if (['vless', 'vmess'].includes(proxy.type)) {
82+
const isProxyUUIDValid = isValidUUID(proxy.uuid);
83+
if (!isProxyUUIDValid) {
84+
$.error(`UUID is invalid: ${proxy.name} ${proxy.uuid}`);
85+
}
86+
return isProxyUUIDValid;
87+
}
88+
return true;
89+
});
8090
}
8191

8292
async function processFn(
@@ -215,10 +225,22 @@ function produce(proxies, targetPlatform, type, opts = {}) {
215225
);
216226

217227
// filter unsupported proxies
218-
proxies = proxies.filter(
219-
(proxy) =>
220-
!(proxy.supported && proxy.supported[targetPlatform] === false),
221-
);
228+
proxies = proxies.filter((proxy) => {
229+
// 检查代理是否支持目标平台
230+
if (proxy.supported && proxy.supported[targetPlatform] === false) {
231+
return false;
232+
}
233+
234+
// 对于 vless 和 vmess 代理,需要额外验证 UUID
235+
if (['vless', 'vmess'].includes(proxy.type)) {
236+
const isProxyUUIDValid = isValidUUID(proxy.uuid);
237+
if (!isProxyUUIDValid)
238+
$.error(`UUID is invalid: ${proxy.name} ${proxy.uuid}`);
239+
return isProxyUUIDValid;
240+
}
241+
242+
return true;
243+
});
222244

223245
proxies = proxies.map((proxy) => {
224246
proxy._resolved = proxy.resolved;

backend/src/utils/index.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,17 @@ function numberToString(value) {
117117
: BigInt(value).toString();
118118
}
119119

120+
function isValidUUID(uuid) {
121+
return (
122+
typeof uuid === 'string' &&
123+
/^[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(
124+
uuid,
125+
)
126+
);
127+
}
128+
120129
export {
130+
isValidUUID,
121131
ipAddress,
122132
isIPv4,
123133
isIPv6,

0 commit comments

Comments
 (0)