From ca05b65638c9b2341c2bf70408cf4029ed5fac0e Mon Sep 17 00:00:00 2001 From: Miku Date: Sat, 2 Aug 2025 02:07:29 +0800 Subject: [PATCH] fix(stash): fix Flow network and SNI issues --- app/Protocols/Stash.php | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/app/Protocols/Stash.php b/app/Protocols/Stash.php index c27ea26..740fa90 100644 --- a/app/Protocols/Stash.php +++ b/app/Protocols/Stash.php @@ -18,7 +18,7 @@ class Stash extends AbstractProtocol Server::TYPE_HYSTERIA, Server::TYPE_TROJAN, Server::TYPE_TUIC, - // Server::TYPE_ANYTLS, + // Server::TYPE_ANYTLS, Server::TYPE_SOCKS, Server::TYPE_HTTP, ]; @@ -253,6 +253,9 @@ class Stash extends AbstractProtocol case 'tcp': $array['network'] = data_get($protocol_settings, 'network_settings.header.type', 'http'); $array['http-opts']['path'] = data_get($protocol_settings, 'network_settings.header.request.path', ['/']); + if ($host = data_get($protocol_settings, 'network_settings.header.request.headers.Host')) { + $array['http-opts']['headers']['Host'] = $host; + } break; case 'ws': $array['network'] = 'ws'; @@ -295,16 +298,24 @@ class Stash extends AbstractProtocol break; case 2: $array['tls'] = true; + if ($serverName = data_get($protocol_settings, 'reality_settings.server_name')) { + $array['servername'] = $serverName; + $array['sni'] = $serverName; + } + $array['flow'] = data_get($protocol_settings, 'flow'); $array['reality-opts'] = [ 'public-key' => data_get($protocol_settings, 'reality_settings.public_key'), 'short-id' => data_get($protocol_settings, 'reality_settings.short_id') ]; + break; } switch (data_get($protocol_settings, 'network')) { case 'tcp': - $array['network'] = data_get($protocol_settings, 'network_settings.header.type'); - $array['http-opts']['path'] = data_get($protocol_settings, 'network_settings.header.request.path', ['/']); + if ($headerType = data_get($protocol_settings, 'network_settings.header.type', 'tcp') != 'tcp') { + $array['network'] = $headerType; + $array['http-opts']['path'] = data_get($protocol_settings, 'network_settings.header.request.path', ['/']); + } break; case 'ws': $array['network'] = 'ws'; @@ -317,11 +328,11 @@ class Stash extends AbstractProtocol $array['network'] = 'grpc'; $array['grpc-opts']['grpc-service-name'] = data_get($protocol_settings, 'network_settings.serviceName'); break; - // case 'h2': - // $array['network'] = 'h2'; - // $array['h2-opts']['host'] = data_get($protocol_settings, 'network_settings.host'); - // $array['h2-opts']['path'] = data_get($protocol_settings, 'network_settings.path'); - // break; + // case 'h2': + // $array['network'] = 'h2'; + // $array['h2-opts']['host'] = data_get($protocol_settings, 'network_settings.host'); + // $array['h2-opts']['path'] = data_get($protocol_settings, 'network_settings.path'); + // break; } return $array; @@ -384,7 +395,6 @@ class Stash extends AbstractProtocol break; } return $array; - } public static function buildTuic($password, $server)