diff --git a/backend/package.json b/backend/package.json index b96b25d6..8e218d6d 100644 --- a/backend/package.json +++ b/backend/package.json @@ -1,6 +1,6 @@ { "name": "sub-store", - "version": "2.22.10", + "version": "2.22.11", "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 7f45a777..ab7faeca 100644 --- a/backend/src/core/proxy-utils/parsers/index.js +++ b/backend/src/core/proxy-utils/parsers/index.js @@ -46,6 +46,23 @@ function splitURIFragment(raw) { }; } +function decodeShadowsocksUserInfo(rawUserInfoStr) { + const separatorIndex = rawUserInfoStr.indexOf(':'); + if (separatorIndex !== -1) { + return [ + decodeURIComponent(rawUserInfoStr.slice(0, separatorIndex)), + decodeURIComponent(rawUserInfoStr.slice(separatorIndex + 1)), + ].join(':'); + } + + const decodedUserInfoStr = decodeURIComponent(rawUserInfoStr); + if (decodedUserInfoStr.includes(':')) { + return decodedUserInfoStr; + } + + return Base64.decode(decodedUserInfoStr); +} + function parseWireGuardURIAddressValue(value) { if (value == null) return null; const raw = `${value}`.trim(); @@ -182,13 +199,7 @@ function URI_SS() { // handle IPV4 and IPV6 let serverAndPortArray = content.match(/@([^/?]*)(\/|\?|$)/); - let rawUserInfoStr = decodeURIComponent(content.split('@')[0]); // 其实应该分隔之后, 用户名和密码再 decodeURIComponent. 但是问题不大 - let userInfoStr; - if (rawUserInfoStr?.startsWith('2022-blake3-')) { - userInfoStr = rawUserInfoStr; - } else { - userInfoStr = Base64.decode(rawUserInfoStr); - } + let userInfoStr = decodeShadowsocksUserInfo(content.split('@')[0]); let query = ''; if (!serverAndPortArray) { diff --git a/backend/src/test/proxy-parsers/uri.spec.js b/backend/src/test/proxy-parsers/uri.spec.js index 289c9104..e20494be 100644 --- a/backend/src/test/proxy-parsers/uri.spec.js +++ b/backend/src/test/proxy-parsers/uri.spec.js @@ -102,6 +102,60 @@ describe('Proxy URI parser coverage', function () { }); }); + it('parses SIP002 Base64URL shadowsocks userinfo', function () { + const proxy = parseOne( + `ss://${Base64.encodeURI( + 'aes-128-gcm:aa>', + )}@ss.example.com:8388#SS%20Base64URL`, + ); + + expectSubset(proxy, { + type: 'ss', + name: 'SS Base64URL', + server: 'ss.example.com', + port: 8388, + cipher: 'aes-128-gcm', + password: 'aa>', + }); + }); + + it('parses SIP002 plain shadowsocks userinfo with percent-encoded credentials', function () { + const password = 'sec:ret@/plus+'; + const proxy = parseOne( + `ss://aes-128-gcm:${encodeURIComponent( + password, + )}@ss.example.com:8388#SS%20Plain`, + ); + + expectSubset(proxy, { + type: 'ss', + name: 'SS Plain', + server: 'ss.example.com', + port: 8388, + cipher: 'aes-128-gcm', + password, + }); + }); + + it('parses SIP002 AEAD-2022 plain userinfo without Base64URL decoding', function () { + const password = + 'YctPZ6U7xPPcU+gp3u+0tx/tRizJN9K8y+uKlW2qjlI='; + const proxy = parseOne( + `ss://2022-blake3-aes-256-gcm:${encodeURIComponent( + password, + )}@192.168.100.1:8888#SS%202022`, + ); + + expectSubset(proxy, { + type: 'ss', + name: 'SS 2022', + server: '192.168.100.1', + port: 8888, + cipher: '2022-blake3-aes-256-gcm', + password, + }); + }); + it('parses legacy shadowsocks URIs with v2ray-plugin options', function () { const legacy = Base64.encode( 'chacha20-ietf-poly1305:legacy-pass@legacy.example.com:443',