diff --git a/backend/package.json b/backend/package.json index 078ec140..1120047a 100644 --- a/backend/package.json +++ b/backend/package.json @@ -1,6 +1,6 @@ { "name": "sub-store", - "version": "2.21.92", + "version": "2.21.93", "description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and Shadowrocket.", "main": "src/main.js", "scripts": { diff --git a/backend/src/core/proxy-utils/parsers/index.js b/backend/src/core/proxy-utils/parsers/index.js index d7d1ce9e..0de270d2 100644 --- a/backend/src/core/proxy-utils/parsers/index.js +++ b/backend/src/core/proxy-utils/parsers/index.js @@ -707,9 +707,7 @@ function URI_VLESS() { hMaxReusableSecs: 'h-max-reusable-secs', }; - for (const [sourceKey, targetKey] of Object.entries( - xmuxFieldMap, - )) { + for (const [sourceKey, targetKey] of Object.entries(xmuxFieldMap)) { const value = xmux[sourceKey]; if (typeof value === 'string' && value !== '') { reuseSettings[targetKey] = value; @@ -849,6 +847,9 @@ function URI_VLESS() { `VLESS ${server}:${port}`; proxy.tls = params.security && params.security !== 'none'; + if (params.pbk) { + params.security = 'reality'; + } if (isShadowrocket && /TRUE|1/i.test(params.tls)) { proxy.tls = true; params.security = params.security ?? 'reality'; diff --git a/backend/src/test/proxy-parsers/v2ray-and-platforms.spec.js b/backend/src/test/proxy-parsers/v2ray-and-platforms.spec.js index d14c2208..82bb4e80 100644 --- a/backend/src/test/proxy-parsers/v2ray-and-platforms.spec.js +++ b/backend/src/test/proxy-parsers/v2ray-and-platforms.spec.js @@ -356,6 +356,54 @@ describe('VMess and VLESS parser coverage', function () { }); }); + it('keeps reality opts when share links carry pbk without security=reality', function () { + const proxy = parseOne( + `vless://${UUID}@vless-grpc.example.com:443?type=grpc&security=tls&serviceName=grpc-service&pbk=pubkey&sid=08#VLESS%20PBK`, + ); + + expectSubset(proxy, { + type: 'vless', + name: 'VLESS PBK', + server: 'vless-grpc.example.com', + port: 443, + uuid: UUID, + tls: true, + network: 'grpc', + 'grpc-opts': { + 'grpc-service-name': 'grpc-service', + '_grpc-type': 'gun', + }, + 'reality-opts': { + 'public-key': 'pubkey', + 'short-id': '08', + }, + }); + }); + + it('keeps pbk-derived reality opts without tls defaults when security is none', function () { + const proxy = parseOne( + `vless://${UUID}@vless-grpc.example.com:443?type=grpc&security=none&serviceName=grpc-service&pbk=pubkey&sid=08#VLESS%20PBK%20No%20TLS`, + ); + + expectSubset(proxy, { + type: 'vless', + name: 'VLESS PBK No TLS', + server: 'vless-grpc.example.com', + port: 443, + uuid: UUID, + tls: false, + network: 'grpc', + 'grpc-opts': { + 'grpc-service-name': 'grpc-service', + '_grpc-type': 'gun', + }, + 'reality-opts': { + 'public-key': 'pubkey', + 'short-id': '08', + }, + }); + }); + it('parses tcp http-header VLESS shares', function () { const proxy = parseOne( `vless://${UUID}@vless-http.example.com:80?type=tcp&headerType=http&host=http.example.com&path=%2Fedge&method=GET#VLESS%20HTTP`, @@ -484,7 +532,9 @@ describe('VMess and VLESS parser coverage', function () { }, }); const proxy = parseOne( - `vless://${UUID}@vless-xhttp.example.com:443?type=xhttp&security=tls&host=cdn.example.com&path=%2Fxhttp&mode=stream-up&extra=${encodeURIComponent(extra)}#VLESS%20XHTTP`, + `vless://${UUID}@vless-xhttp.example.com:443?type=xhttp&security=tls&host=cdn.example.com&path=%2Fxhttp&mode=stream-up&extra=${encodeURIComponent( + extra, + )}#VLESS%20XHTTP`, ); expectSubset(proxy, { @@ -542,7 +592,9 @@ describe('VMess and VLESS parser coverage', function () { }, }); const proxy = parseOne( - `vless://${UUID}@vless-xhttp.example.com:443?type=xhttp&security=tls&host=cdn.example.com&path=%2Fxhttp&mode=stream-up&extra=${encodeURIComponent(extra)}#VLESS%20XHTTP%20Download`, + `vless://${UUID}@vless-xhttp.example.com:443?type=xhttp&security=tls&host=cdn.example.com&path=%2Fxhttp&mode=stream-up&extra=${encodeURIComponent( + extra, + )}#VLESS%20XHTTP%20Download`, ); expectSubset(proxy, { @@ -592,7 +644,9 @@ describe('VMess and VLESS parser coverage', function () { }, }); const proxy = parseOne( - `vless://${UUID}@vless-xhttp.example.com:443?type=xhttp&security=tls&host=cdn.example.com&path=%2Fxhttp&extra=${encodeURIComponent(extra)}#VLESS%20XHTTP%20Download%20No%20Mode`, + `vless://${UUID}@vless-xhttp.example.com:443?type=xhttp&security=tls&host=cdn.example.com&path=%2Fxhttp&extra=${encodeURIComponent( + extra, + )}#VLESS%20XHTTP%20Download%20No%20Mode`, ); expectSubset(proxy, { @@ -634,7 +688,9 @@ describe('VMess and VLESS parser coverage', function () { }, }); const proxy = parseOne( - `vless://${UUID}@vless-xhttp.example.com:443?type=xhttp&security=tls&host=cdn.example.com&path=%2Fxhttp&mode=stream-up&extra=${encodeURIComponent(extra)}#VLESS%20XHTTP%20Range`, + `vless://${UUID}@vless-xhttp.example.com:443?type=xhttp&security=tls&host=cdn.example.com&path=%2Fxhttp&mode=stream-up&extra=${encodeURIComponent( + extra, + )}#VLESS%20XHTTP%20Range`, ); expectSubset(proxy, { @@ -680,7 +736,9 @@ describe('VMess and VLESS parser coverage', function () { }, }); const proxy = parseOne( - `vless://${UUID}@vless-xhttp.example.com:443?type=xhttp&security=tls&host=cdn.example.com&path=%2Fxhttp&mode=stream-up&extra=${encodeURIComponent(extra)}#VLESS%20XHTTP%20String`, + `vless://${UUID}@vless-xhttp.example.com:443?type=xhttp&security=tls&host=cdn.example.com&path=%2Fxhttp&mode=stream-up&extra=${encodeURIComponent( + extra, + )}#VLESS%20XHTTP%20String`, ); expectSubset(proxy, { @@ -729,7 +787,9 @@ describe('VMess and VLESS parser coverage', function () { }, }); const proxy = parseOne( - `vless://${UUID}@vless-xhttp.example.com:443?type=xhttp&security=tls&host=cdn.example.com&path=%2Fxhttp&mode=stream-up&extra=${encodeURIComponent(extra)}#VLESS%20XHTTP%20Invalid`, + `vless://${UUID}@vless-xhttp.example.com:443?type=xhttp&security=tls&host=cdn.example.com&path=%2Fxhttp&mode=stream-up&extra=${encodeURIComponent( + extra, + )}#VLESS%20XHTTP%20Invalid`, ); expectSubset(proxy, { diff --git a/backend/src/test/proxy-producers/text.spec.js b/backend/src/test/proxy-producers/text.spec.js index a3073a9b..c1880f33 100644 --- a/backend/src/test/proxy-producers/text.spec.js +++ b/backend/src/test/proxy-producers/text.spec.js @@ -850,7 +850,9 @@ describe('Proxy text producers', function () { }); expect(output).to.equal( - `vless://${UUID}@vless-xhttp.example.com:443?security=tls&type=xhttp&path=%2Fxhttp&host=cdn.example.com&sni=sni.example.com&mode=stream-up&extra=${encodeURIComponent(extra)}#URI%20XHTTP`, + `vless://${UUID}@vless-xhttp.example.com:443?security=tls&type=xhttp&path=%2Fxhttp&host=cdn.example.com&sni=sni.example.com&mode=stream-up&extra=${encodeURIComponent( + extra, + )}#URI%20XHTTP`, ); }); @@ -888,7 +890,9 @@ describe('Proxy text producers', function () { }); expect(output).to.equal( - `vless://${UUID}@vless-xhttp.example.com:443?security=tls&type=xhttp&path=%2Fxhttp&host=cdn.example.com&sni=sni.example.com&mode=stream-up&extra=${encodeURIComponent(extra)}#URI%20XHTTP%20Raw%20Extra`, + `vless://${UUID}@vless-xhttp.example.com:443?security=tls&type=xhttp&path=%2Fxhttp&host=cdn.example.com&sni=sni.example.com&mode=stream-up&extra=${encodeURIComponent( + extra, + )}#URI%20XHTTP%20Raw%20Extra`, ); }); @@ -960,7 +964,9 @@ describe('Proxy text producers', function () { }); expect(output).to.equal( - `vless://${UUID}@vless-xhttp.example.com:443?security=tls&type=xhttp&path=%2Fxhttp&host=cdn.example.com&sni=sni.example.com&mode=stream-up&extra=${encodeURIComponent(extra)}#URI%20XHTTP%20Download`, + `vless://${UUID}@vless-xhttp.example.com:443?security=tls&type=xhttp&path=%2Fxhttp&host=cdn.example.com&sni=sni.example.com&mode=stream-up&extra=${encodeURIComponent( + extra, + )}#URI%20XHTTP%20Download`, ); });