From f89921ab30d89193e3078c12cefac44e546f066a Mon Sep 17 00:00:00 2001 From: xream Date: Fri, 12 Jun 2026 07:55:47 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20Surge=20=E6=94=AF=E6=8C=81=20Snell=20v6?= =?UTF-8?q?(v6=20=E4=B8=8D=E6=94=AF=E6=8C=81=20obfs,=20=E5=B0=86=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E8=BF=87=E6=BB=A4)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/package.json | 2 +- .../src/core/proxy-utils/producers/surge.js | 19 ++++++ backend/src/test/proxy-producers/text.spec.js | 65 ++++++++++++++----- 3 files changed, 67 insertions(+), 19 deletions(-) diff --git a/backend/package.json b/backend/package.json index 466050d1..16c19b35 100644 --- a/backend/package.json +++ b/backend/package.json @@ -1,6 +1,6 @@ { "name": "sub-store", - "version": "2.24.17", + "version": "2.24.19", "description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and Shadowrocket.", "main": "src/main.js", "packageManager": "pnpm@11.0.9", diff --git a/backend/src/core/proxy-utils/producers/surge.js b/backend/src/core/proxy-utils/producers/surge.js index 912ed56a..65ead3df 100644 --- a/backend/src/core/proxy-utils/producers/surge.js +++ b/backend/src/core/proxy-utils/producers/surge.js @@ -96,6 +96,18 @@ function warnMaxStreamsIfNeeded(proxy) { ); } +function hasSnellObfs(proxy) { + return ( + isPresent(proxy, 'obfs-opts.mode') || + isPresent(proxy, 'obfs-opts.host') || + isPresent(proxy, 'obfs-opts.path') + ); +} + +function isUnsupportedSnellV6Obfs(proxy) { + return Number(proxy.version) === 6 && hasSnellObfs(proxy); +} + export default function Surge_Producer() { const produce = (proxy, type, opts = {}) => { if ( @@ -923,6 +935,13 @@ function formatHeaderMap(headers, separator) { } function snell(proxy) { + if (isUnsupportedSnellV6Obfs(proxy)) { + $.error( + `Platform ${targetPlatform} does not support Snell version ${proxy.version} with obfs`, + ); + return ''; + } + const result = new Result(proxy); result.append(`${proxy.name}=${proxy.type},${proxy.server},${proxy.port}`); result.appendIfPresent(`,version=${proxy.version}`, 'version'); diff --git a/backend/src/test/proxy-producers/text.spec.js b/backend/src/test/proxy-producers/text.spec.js index 43322801..5461c6d4 100644 --- a/backend/src/test/proxy-producers/text.spec.js +++ b/backend/src/test/proxy-producers/text.spec.js @@ -807,6 +807,47 @@ describe('Proxy text producers', function () { ); }); + it('produces Surge Snell v6 and filters v6 obfs', function () { + const { result: output, errors } = captureErrors(() => + ProxyUtils.produce( + [ + { + type: 'snell', + name: 'Surge Snell v6', + server: 'snell.example.com', + port: 443, + psk: 'secret', + version: 6, + udp: true, + }, + { + type: 'snell', + name: 'Surge Snell v6 Obfs', + server: 'snell.example.com', + port: 443, + psk: 'secret', + version: 6, + udp: true, + 'obfs-opts': { + mode: 'tls', + host: 'obfs.example.com', + path: '/snell', + }, + }, + ], + 'Surge', + 'external', + ), + ); + + expect(output).to.equal( + 'Surge Snell v6=snell,snell.example.com,443,version=6,psk="secret",udp-relay=true', + ); + expect(errors).to.deep.equal([ + 'Platform Surge does not support Snell version 6 with obfs', + ]); + }); + it('omits Surge TLS-only params for plain HTTP, SOCKS5, and VMess nodes', function () { const cases = [ { @@ -2791,16 +2832,10 @@ describe('Proxy text producers', function () { expect( reparsed[0]['xhttp-opts']?.['download-settings']?.server, ).to.equal('download.example.com'); - expect(reparsed[0]['xhttp-opts']?.['session-table']).to.equal( - 'Base62', - ); - expect(reparsed[0]['xhttp-opts']?.['session-length']).to.equal( - '16-32', - ); + expect(reparsed[0]['xhttp-opts']?.['session-table']).to.equal('Base62'); + expect(reparsed[0]['xhttp-opts']?.['session-length']).to.equal('16-32'); expect( - reparsed[0]['xhttp-opts']?.['download-settings']?.[ - 'session-table' - ], + reparsed[0]['xhttp-opts']?.['download-settings']?.['session-table'], ).to.equal('abcXYZ012'); expect( reparsed[0]['xhttp-opts']?.['download-settings']?.[ @@ -4407,12 +4442,8 @@ describe('Proxy text producers', function () { expect( reparsed[0]['xhttp-opts']?.['sc-min-posts-interval-ms'], ).to.equal('0-300'); - expect(reparsed[0]['xhttp-opts']?.['session-table']).to.equal( - 'Base62', - ); - expect(reparsed[0]['xhttp-opts']?.['session-length']).to.equal( - '16-32', - ); + expect(reparsed[0]['xhttp-opts']?.['session-table']).to.equal('Base62'); + expect(reparsed[0]['xhttp-opts']?.['session-length']).to.equal('16-32'); expect( reparsed[0]['xhttp-opts']?.['download-settings']?.[ 'sc-max-each-post-bytes' @@ -4424,9 +4455,7 @@ describe('Proxy text producers', function () { ], ).to.equal('0-300'); expect( - reparsed[0]['xhttp-opts']?.['download-settings']?.[ - 'session-table' - ], + reparsed[0]['xhttp-opts']?.['download-settings']?.['session-table'], ).to.equal('abcXYZ012'); expect( reparsed[0]['xhttp-opts']?.['download-settings']?.[