From 99b19c410d1a839267c9fb52f505623e2db717dc Mon Sep 17 00:00:00 2001 From: xream Date: Mon, 21 Aug 2023 22:16:07 +0800 Subject: [PATCH] fix: vmess/vless http-opts.path/http-opts.headers.Host must be an array in some clients --- backend/package.json | 2 +- .../src/core/proxy-utils/producers/clash.js | 20 +++++++++++++++++++ .../src/core/proxy-utils/producers/loon.js | 12 +++++++---- backend/src/core/proxy-utils/producers/qx.js | 6 ++++-- .../src/core/proxy-utils/producers/stash.js | 20 +++++++++++++++++++ 5 files changed, 53 insertions(+), 7 deletions(-) diff --git a/backend/package.json b/backend/package.json index 20db01522..4beee97de 100644 --- a/backend/package.json +++ b/backend/package.json @@ -1,6 +1,6 @@ { "name": "sub-store", - "version": "2.14.14", + "version": "2.14.15", "description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and ShadowRocket.", "main": "src/main.js", "scripts": { diff --git a/backend/src/core/proxy-utils/producers/clash.js b/backend/src/core/proxy-utils/producers/clash.js index 109c75306..8b6519e34 100644 --- a/backend/src/core/proxy-utils/producers/clash.js +++ b/backend/src/core/proxy-utils/producers/clash.js @@ -55,6 +55,26 @@ export default function Clash_Producer() { } } + if ( + ['vmess', 'vless'].includes(proxy.type) && + proxy.network === 'http' + ) { + let httpPath = proxy['http-opts']?.path; + if ( + isPresent(proxy, 'http-opts.path') && + !Array.isArray(httpPath) + ) { + proxy['http-opts'].path = [httpPath]; + } + let httpHost = proxy['http-opts']?.headers?.Host; + if ( + isPresent(proxy, 'http-opts.headers.Host') && + !Array.isArray(httpHost) + ) { + proxy['http-opts'].headers.Host = [httpHost]; + } + } + delete proxy['tls-fingerprint']; return ' - ' + JSON.stringify(proxy) + '\n'; }) diff --git a/backend/src/core/proxy-utils/producers/loon.js b/backend/src/core/proxy-utils/producers/loon.js index 57d0e3c83..48fa02994 100644 --- a/backend/src/core/proxy-utils/producers/loon.js +++ b/backend/src/core/proxy-utils/producers/loon.js @@ -144,12 +144,14 @@ function vmess(proxy) { ); } else if (proxy.network === 'http') { result.append(`,transport=http`); + let httpPath = proxy['http-opts']?.path; + let httpHost = proxy['http-opts']?.headers?.Host; result.appendIfPresent( - `,path=${proxy['http-opts'].path}`, + `,path=${Array.isArray(httpPath) ? httpPath[0] : httpPath}`, 'http-opts.path', ); result.appendIfPresent( - `,host=${proxy['http-opts'].headers.Host}`, + `,host=${Array.isArray(httpHost) ? httpHost[0] : httpHost}`, 'http-opts.headers.Host', ); } else { @@ -206,12 +208,14 @@ function vless(proxy) { ); } else if (proxy.network === 'http') { result.append(`,transport=http`); + let httpPath = proxy['http-opts']?.path; + let httpHost = proxy['http-opts']?.headers?.Host; result.appendIfPresent( - `,path=${proxy['http-opts'].path}`, + `,path=${Array.isArray(httpPath) ? httpPath[0] : httpPath}`, 'http-opts.path', ); result.appendIfPresent( - `,host=${proxy['http-opts'].headers.Host}`, + `,host=${Array.isArray(httpHost) ? httpHost[0] : httpHost}`, 'http-opts.headers.Host', ); } else { diff --git a/backend/src/core/proxy-utils/producers/qx.js b/backend/src/core/proxy-utils/producers/qx.js index 55cbc63f9..b25514738 100644 --- a/backend/src/core/proxy-utils/producers/qx.js +++ b/backend/src/core/proxy-utils/producers/qx.js @@ -206,12 +206,14 @@ function vmess(proxy) { } else { throw new Error(`network ${proxy.network} is unsupported`); } + let httpPath = proxy[`${proxy.network}-opts`]?.path; + let httpHost = proxy[`${proxy.network}-opts`]?.headers?.Host; appendIfPresent( - `,obfs-uri=${proxy[`${proxy.network}-opts`].path}`, + `,obfs-uri=${Array.isArray(httpPath) ? httpPath[0] : httpPath}`, `${proxy.network}-opts.path`, ); appendIfPresent( - `,obfs-host=${proxy[`${proxy.network}-opts`].headers.Host}`, + `,obfs-host=${Array.isArray(httpHost) ? httpHost[0] : httpHost}`, `${proxy.network}-opts.headers.Host`, ); } else { diff --git a/backend/src/core/proxy-utils/producers/stash.js b/backend/src/core/proxy-utils/producers/stash.js index 30c355555..0174bff58 100644 --- a/backend/src/core/proxy-utils/producers/stash.js +++ b/backend/src/core/proxy-utils/producers/stash.js @@ -58,6 +58,26 @@ export default function Stash_Producer() { } } + if ( + ['vmess', 'vless'].includes(proxy.type) && + proxy.network === 'http' + ) { + let httpPath = proxy['http-opts']?.path; + if ( + isPresent(proxy, 'http-opts.path') && + !Array.isArray(httpPath) + ) { + proxy['http-opts'].path = [httpPath]; + } + let httpHost = proxy['http-opts']?.headers?.Host; + if ( + isPresent(proxy, 'http-opts.headers.Host') && + !Array.isArray(httpHost) + ) { + proxy['http-opts'].headers.Host = [httpHost]; + } + } + delete proxy['tls-fingerprint']; return ' - ' + JSON.stringify(proxy) + '\n'; })