Skip to content

Hysteria server: Fix Unix masquerade socket path - #6705

Merged
RPRX merged 1 commit into
XTLS:mainfrom
XXcipherX:fix/hysteria-unix-masquerade-path
Sep 7, 2026
Merged

RPRX merged 1 commit into
XTLS:mainfrom
XXcipherX:fix/hysteria-unix-masquerade-path

Conversation

@XXcipherX

@XXcipherX XXcipherX commented Aug 31, 2026 •

Copy link
Copy Markdown
Contributor

Problem

The current Xray code handles Unix-socket targets in the following order:

case "", "unix":
    u = &url.URL{Scheme: "http", Host: "localhost"}
    path := u.Path

    dialer := &net.Dialer{Timeout: 30 * time.Second}
    transport = transport.Clone()
    transport.Proxy = nil
    transport.DialContext = func(ctx context.Context, network, addr string) (net.Conn, error) {
        return dialer.DialContext(ctx, "unix", path)
    }

The original parsed URL is overwritten before its path is saved:

u = &url.URL{Scheme: "http", Host: "localhost"}

The replacement URL has an empty Path, so the next assignment always produces:

path == ""

Consequently, the custom transport effectively attempts:

dialer.DialContext(ctx, "unix", "")

On Linux, this fails with an error similar to:

dial unix: missing address

The Hysteria masquerade handler then returns 502 Bad Gateway, while Xray logs:

HTTP reverse proxy error

This affects all supported Unix-socket target formats, not just one particular URL form, because the parsed socket path is discarded in every case.

Upstream behavior

In the upstream Hysteria implementation, the socket path is saved before constructing the synthetic HTTP target:

socketPath := parsedURL.Path

Only after that does it return the target used by httputil.ReverseProxy:

return &url.URL{
    Scheme: "http",
    Host:   "localhost",
}, transport, nil

The custom transport therefore captures the original socket path:

transport.DialContext = func(ctx context.Context, _, _ string) (net.Conn, error) {
    return dialer.DialContext(ctx, "unix", socketPath)
}

The incorrect ordering was introduced while adapting this logic in #6565 it is not caused by the upstream Hysteria implementation.

Fix

Save u.Path before replacing u with the synthetic http://localhost target:

case "", "unix":
    path := u.Path
    u = &url.URL{Scheme: "http", Host: "localhost"}

This preserves the original Unix socket address while leaving HTTP and HTTPS masquerade behavior unchanged.

@LjhAUMEM

LjhAUMEM commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

这里确实同步错了,感谢修复

改的代码行数少的话也不用写这么多描述,看代码就可以知道意图

@RPRX RPRX changed the title Hysteria: Fix Unix masquerade socket path Hysteria server: Fix Unix masquerade socket path Sep 7, 2026
@RPRX
RPRX merged commit de2caf3 into XTLS:main Sep 7, 2026
40 checks passed
TaiLerV pushed a commit to TaiLerV/Xray-core-up that referenced this pull request Oct 7, 2026
Hysteria app/v2.12.2 added Unix sockets as masquerade proxy targets,
which the upstream sync (XTLS#6565, XTLS#6705) brought over without the URL
checks of Hysteria's newUnixMasqueradeProxyTarget. Any URL without a
scheme counted as a socket path, so "example.com/site" or a relative path
started the server, and a unix: URL silently dropped its host, userinfo,
query and fragment. The server then answered every unauthenticated probe
with 502 Bad Gateway instead of the masqueraded site.

Accept, as Hysteria does, unix:///path and absolute paths without a
scheme; reject the rest when the listener starts. A second test sends an
unauthenticated HTTP/3 request, as a prober would, and checks that it
reaches the site behind the socket with its Host and path intact.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
TaiLerV pushed a commit to TaiLerV/Xray-core-up that referenced this pull request Oct 7, 2026
The Hysteria features were already at 2.12.2 through upstream XTLS#6565 and
XTLS#6705 although the fork list still said 2.12.1. Record 2.13.0, Chrome 154
parroting, the Hysteria-compatible masquerade socket URLs and ECH key
generation, and the QUIC and TLS sniffing that now reassembles split
ClientHellos without modifying the sniffed datagrams.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants