Skip to content

Commit 6381c51

Browse files
committed
fix: 优化订阅生成逻辑,随机替换主机名通配符以增强安全性
1 parent 3a12deb commit 6381c51

1 file changed

Lines changed: 20 additions & 8 deletions

File tree

_worker.js

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,8 @@ export default {
260260
console.warn(`[订阅内容] 不规范的IP格式已忽略: ${原始地址}`);
261261
return null;
262262
}
263-
264-
return `${协议类型}://${config_JSON.UUID}@${节点地址}:${节点端口}?security=tls&type=${config_JSON.传输协议}&host=${config_JSON.HOST}&sni=${config_JSON.HOST}&path=${encodeURIComponent((随机路径() + 节点路径).replace('/?', '?')) + TLS分片参数}&encryption=none${config_JSON.跳过证书验证 ? '&allowInsecure=1' : ''}#${encodeURIComponent(节点备注)}`;
263+
const 节点HOST = 随机替换通配符(config_JSON.HOST);
264+
return `${协议类型}://${config_JSON.UUID}@${节点地址}:${节点端口}?security=tls&type=${config_JSON.传输协议}&host=${节点HOST}&sni=${节点HOST}&path=${encodeURIComponent((随机路径() + 节点路径).replace('/?', '?')) + TLS分片参数}&encryption=none${config_JSON.跳过证书验证 ? '&allowInsecure=1' : ''}#${encodeURIComponent(节点备注)}`;
265265
}).filter(item => item !== null).join('\n');
266266
订阅内容 = btoa(其他节点LINK + 订阅内容);
267267
} else { // 优选订阅生成器
@@ -289,9 +289,9 @@ export default {
289289
}
290290
}
291291
if (订阅类型 === 'mixed') {
292-
订阅内容 = atob(订阅内容).replace(/example.com/g, config_JSON.HOST).replace(/00000000-0000-4000-0000-000000000000/g, config_JSON.UUID);
292+
订阅内容 = atob(订阅内容).replace(/example.com/g, 随机替换通配符(config_JSON.HOST)).replace(/00000000-0000-4000-0000-000000000000/g, config_JSON.UUID);
293293
if (!ua.includes('mozilla')) 订阅内容 = btoa(订阅内容);
294-
} else 订阅内容 = 订阅内容.replace(/example.com/g, config_JSON.HOST).replace(/00000000-0000-4000-0000-000000000000/g, config_JSON.UUID);
294+
} else 订阅内容 = 订阅内容.replace(/example.com/g, 随机替换通配符(config_JSON.HOST)).replace(/00000000-0000-4000-0000-000000000000/g, config_JSON.UUID);
295295
if (订阅类型 === 'singbox') {
296296
订阅内容 = JSON.stringify(JSON.parse(订阅内容), null, 2);
297297
responseHeaders["content-type"] = 'application/json; charset=utf-8';
@@ -819,12 +819,24 @@ async function MD5MD5(文本) {
819819

820820
function 随机路径() {
821821
const 常用路径目录 = ["#","about","account","acg","act","activity","ad","admin","ads","ajax","album","albums","anime","api","app","apps","archive","archives","article","articles","ask","auth","avatar","bbs","bd","blog","blogs","book","books","bt","buy","cart","category","categories","cb","channel","channels","chat","china","city","class","classify","clip","clips","club","cn","code","collect","collection","comic","comics","community","company","config","contact","content","course","courses","cp","data","detail","details","dh","directory","discount","discuss","dl","dload","doc","docs","document","documents","doujin","download","downloads","drama","edu","en","ep","episode","episodes","event","events","f","faq","favorite","favourites","favs","feedback","file","files","film","films","forum","forums","friend","friends","game","games","gif","go","go.html","go.php","group","groups","help","home","hot","htm","html","image","images","img","index","info","intro","item","items","ja","jp","jump","jump.html","jump.php","jumping","knowledge","lang","lesson","lessons","lib","library","link","links","list","live","lives","login","logout","m","mag","magnet","mall","manhua","map","member","members","message","messages","mobile","movie","movies","music","my","new","news","note","novel","novels","online","order","out","out.html","out.php","outbound","p","page","pages","pay","payment","pdf","photo","photos","pic","pics","picture","pictures","play","player","playlist","post","posts","product","products","program","programs","project","qa","question","rank","ranking","read","readme","redirect","redirect.html","redirect.php","reg","register","res","resource","retrieve","sale","search","season","seasons","section","seller","series","service","services","setting","settings","share","shop","show","shows","site","soft","sort","source","special","star","stars","static","stock","store","stream","streaming","streams","student","study","tag","tags","task","teacher","team","tech","temp","test","thread","tool","tools","topic","topics","torrent","trade","travel","tv","txt","type","u","upload","uploads","url","urls","user","users","v","version","video","videos","view","vip","vod","watch","web","wenku","wiki","work","www","zh","zh-cn","zh-tw","zip"];
822-
const 随机数 = Math.floor(Math.random() * 4 + 1);
822+
const 随机数 = Math.floor(Math.random() * 3 + 1);
823823
const 随机路径 = 常用路径目录.sort(() => 0.5 - Math.random()).slice(0, 随机数).join('/');
824824
return `/${随机路径}`;
825825
}
826826

827-
async function 读取config_JSON(env, host, userID, 重置配置 = false) {
827+
function 随机替换通配符(h) {
828+
if (!h?.includes('*')) return h;
829+
const 字符集 = 'abcdefghijklmnopqrstuvwxyz0123456789';
830+
return h.replace(/\*/g, () => {
831+
let s = '';
832+
for (let i = 0; i < Math.floor(Math.random() * 14) + 3; i++)
833+
s += 字符集[Math.floor(Math.random() * 36)];
834+
return s;
835+
});
836+
}
837+
838+
async function 读取config_JSON(env, hostname, userID, 重置配置 = false) {
839+
const host = 随机替换通配符(hostname);
828840
const 初始化开始时间 = performance.now();
829841
const 默认配置JSON = {
830842
TIME: new Date().toISOString(),
@@ -845,7 +857,7 @@ async function 读取config_JSON(env, host, userID, 重置配置 = false) {
845857
SUB: null,
846858
SUBNAME: "edge" + "tunnel",
847859
SUBUpdateTime: 6, // 订阅更新时间(小时)
848-
TOKEN: await MD5MD5(host + userID),
860+
TOKEN: await MD5MD5(hostname + userID),
849861
},
850862
订阅转换配置: {
851863
SUBAPI: "https://SUBAPI.cmliussss.net",
@@ -898,7 +910,7 @@ async function 读取config_JSON(env, host, userID, 重置配置 = false) {
898910
config_JSON.PATH = config_JSON.反代.SOCKS5.启用 ? ('/' + config_JSON.反代.SOCKS5.启用 + (config_JSON.反代.SOCKS5.全局 ? '://' : '=') + config_JSON.反代.SOCKS5.账号) : (config_JSON.反代.PROXYIP === 'auto' ? '/' : `/proxyip=${config_JSON.反代.PROXYIP}`);
899911
const TLS分片参数 = config_JSON.TLS分片 == 'Shadowrocket' ? `&fragment=${encodeURIComponent('1,40-60,30-50,tlshello')}` : config_JSON.TLS分片 == 'Happ' ? `&fragment=${encodeURIComponent('3,1,tlshello')}` : '';
900912
config_JSON.LINK = `${config_JSON.协议类型}://${userID}@${host}:443?security=tls&type=${config_JSON.传输协议}&host=${host}&sni=${host}&path=${encodeURIComponent(config_JSON.启用0RTT ? config_JSON.PATH + '?ed=2560' : config_JSON.PATH) + TLS分片参数}&encryption=none${config_JSON.跳过证书验证 ? '&allowInsecure=1' : ''}#${encodeURIComponent(config_JSON.优选订阅生成.SUBNAME)}`;
901-
config_JSON.优选订阅生成.TOKEN = await MD5MD5(host + userID);
913+
config_JSON.优选订阅生成.TOKEN = await MD5MD5(hostname + userID);
902914

903915
const 初始化TG_JSON = { BotToken: null, ChatID: null };
904916
config_JSON.TG = { 启用: config_JSON.TG.启用 ? config_JSON.TG.启用 : false, ...初始化TG_JSON };

0 commit comments

Comments
 (0)