[GH-ISSUE #6782] [Bug]: VLESS/VMess + WebSocket + TLS inbound with the default ALPN (h2, http/1.1) can't be used: Xray negotiates h2 and the WebSocket dial fails #4518

Closed
opened 2026-10-31 20:40:12 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @jayhemnani9910 on GitHub (Oct 10, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/6782

Describe the bug

On the inbound form, switching Security to TLS fills ALPN with h2, http/1.1 for every transport (createTlsSettingsWithDefaultCert, frontend/src/pages/inbounds/form/useSecurityActions.ts:347 → TlsStreamSettingsSchema default, frontend/src/schemas/protocols/security/tls.ts:106). The panel copies that ALPN into the server's Xray config, the share link (alpn=h2%2Chttp%2F1.1) and the JSON subscription.

With WebSocket as the transport, this combination fails. The client offers h2, http/1.1, Xray on the server picks h2, and the client's WebSocket handshake then fails. The same inbound works once ALPN is just http/1.1. HTTPUpgrade + TLS with the same default ALPN connects fine, so the problem is limited to WebSocket.

An Xray-core maintainer describes the same behavior in XTLS/Xray-core#6128: with Xray as the server, h2, http/1.1 negotiates h2 and WS cannot work. So Xray treats it as a config problem. But the panel produces this config by default.

How to reproduce the problem

  1. Add an inbound: VLESS, transport WebSocket (path /ws), Security TLS with a certificate. Keep the default ALPN (h2, http/1.1).
  2. Add a client and import its link or JSON subscription into an Xray-core based client (I used Xray-core 26.9.30 as the client).
  3. Send any request through it.

The same thing happens with VMess + WS + TLS.

Expected behavior

A WebSocket + TLS inbound made with the panel defaults should connect.

Actual behavior

The connection fails. Client log:

transport/internet/websocket: failed to dial WebSocket > transport/internet/websocket: failed to dial to (wss://<host>:<port>/ws):  > websocket: protocol "h2" was given but is not supported;sharing tls.Config with net/http Transport can cause this error: malformed HTTP response "\x00\x00$\x04..."

What I tested, with the server inbound ALPN left at h2, http/1.1:

Client ALPN Client fingerprint Result
h2, http/1.1 (from the subscription) none fails
h2, http/1.1 chrome fails
http/1.1 none works
http/1.1 chrome works

HTTPUpgrade + TLS with ALPN h2, http/1.1: works.

Relevant logs

(see Actual behavior)

3x-ui version

3.9.0 (also checked on main at 442b7fb)

Xray-core version

26.9.30

How did you install 3x-ui?

Other: release tarball run locally

Operating system

Ubuntu 26.04 (x86_64)

Which parts of the panel are affected?

Xray config generation

Is the panel behind a reverse proxy or CDN?

No, direct access

Additional note

There is a precedent in #4076 (292eb992, "set ALPN to h3 when switching to Hysteria protocol"): the form could do the same for WebSocket and set ALPN to http/1.1 when the transport is WebSocket and Security is TLS. That would not fix existing inbounds, which already store h2, http/1.1. The other option is to drop h2 for WebSocket when the server config and the links are generated. Which way to go is your call.

Originally created by @jayhemnani9910 on GitHub (Oct 10, 2026). Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/6782 ### Describe the bug On the inbound form, switching Security to TLS fills ALPN with `h2, http/1.1` for every transport (`createTlsSettingsWithDefaultCert`, `frontend/src/pages/inbounds/form/useSecurityActions.ts:347` → `TlsStreamSettingsSchema` default, `frontend/src/schemas/protocols/security/tls.ts:106`). The panel copies that ALPN into the server's Xray config, the share link (`alpn=h2%2Chttp%2F1.1`) and the JSON subscription. With WebSocket as the transport, this combination fails. The client offers `h2, http/1.1`, Xray on the server picks `h2`, and the client's WebSocket handshake then fails. The same inbound works once ALPN is just `http/1.1`. HTTPUpgrade + TLS with the same default ALPN connects fine, so the problem is limited to WebSocket. An Xray-core maintainer describes the same behavior in XTLS/Xray-core#6128: with Xray as the server, `h2, http/1.1` negotiates h2 and WS cannot work. So Xray treats it as a config problem. But the panel produces this config by default. ### How to reproduce the problem 1. Add an inbound: VLESS, transport WebSocket (path `/ws`), Security TLS with a certificate. Keep the default ALPN (`h2`, `http/1.1`). 2. Add a client and import its link or JSON subscription into an Xray-core based client (I used Xray-core 26.9.30 as the client). 3. Send any request through it. The same thing happens with VMess + WS + TLS. ### Expected behavior A WebSocket + TLS inbound made with the panel defaults should connect. ### Actual behavior The connection fails. Client log: ``` transport/internet/websocket: failed to dial WebSocket > transport/internet/websocket: failed to dial to (wss://<host>:<port>/ws): > websocket: protocol "h2" was given but is not supported;sharing tls.Config with net/http Transport can cause this error: malformed HTTP response "\x00\x00$\x04..." ``` What I tested, with the server inbound ALPN left at `h2, http/1.1`: | Client ALPN | Client fingerprint | Result | |---|---|---| | h2, http/1.1 (from the subscription) | none | fails | | h2, http/1.1 | chrome | fails | | http/1.1 | none | works | | http/1.1 | chrome | works | HTTPUpgrade + TLS with ALPN `h2, http/1.1`: works. ### Relevant logs (see Actual behavior) ### 3x-ui version 3.9.0 (also checked on main at 442b7fb) ### Xray-core version 26.9.30 ### How did you install 3x-ui? Other: release tarball run locally ### Operating system Ubuntu 26.04 (x86_64) ### Which parts of the panel are affected? Xray config generation ### Is the panel behind a reverse proxy or CDN? No, direct access ### Additional note There is a precedent in #4076 (292eb992, "set ALPN to h3 when switching to Hysteria protocol"): the form could do the same for WebSocket and set ALPN to `http/1.1` when the transport is WebSocket and Security is TLS. That would not fix existing inbounds, which already store `h2, http/1.1`. The other option is to drop `h2` for WebSocket when the server config and the links are generated. Which way to go is your call.
bsakaguchi 2026-10-31 20:40:12 +07:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@github-actions[bot] commented on GitHub (Oct 10, 2026):

This is a real panel-side bug. When you switch Security to TLS, every inbound gets ALPN h2, http/1.1, whatever its transport. Nothing on the server-config, share-link or subscription path drops h2 for WebSocket, so a WS + TLS inbound made with the defaults sends Xray and clients the exact combination your log shows failing. It is still present on the default branch.

Workaround: in the inbound's TLS section, set ALPN to http/1.1 only, or clear it. Then re-import the link or refresh the subscription. The client keeps whatever ALPN it got from the old link until it does.

How the default reaches the client (everything below is checked in the source):

  1. frontend/src/schemas/protocols/security/tls.ts:106 sets the default, which applies to every transport:
    alpn: z.array(AlpnSchema).default(['h2', 'http/1.1']),
    
  2. onSecurityChange uses it with no check on the transport (frontend/src/pages/inbounds/form/useSecurityActions.ts:346-347):
    if (next === 'tls') {
      cleaned.tlsSettings = createTlsSettingsWithDefaultCert();
    
    The only exception is Hysteria, in createHysteriaTlsSettingsWithDefaultCert (frontend/src/lib/xray/inbound-tls-defaults.ts:31: tls.alpn = ['h3'];). There is nothing similar for ws.
  3. Server config: Inbound.GenXrayInboundConfig (internal/database/model/model.go:375-383) only strips XHTTP client fields and heals Hysteria. It passes tlsSettings.alpn to Xray unchanged.
  4. Links and subscriptions copy it as is: params["alpn"] = strings.Join(inst.ALPN, ",") (internal/sub/service.go:877), the per-protocol TLS param builders (internal/sub/service.go:1433-1441, 1834-1842, 1869-1877), and tlsData["alpn"] = tData["alpn"] in the JSON subscription (internal/sub/json_service.go:771).
  5. The golden fixtures already store the failing combination as the expected output: frontend/src/test/golden/fixtures/inbound-full/vless-ws-tls.json:68 and trojan-ws-tls.json:65 both contain "alpn": ["h2", "http/1.1"].

I did not check the Xray-core side, because Xray's websocket source is not in this repository. That covers Xray picking h2 and the WS dialer then rejecting it. The evidence for it is your log (websocket: protocol "h2" was given but is not supported) and the upstream issue you linked (XTLS/Xray-core#6128).

Verdict: Confirmed bug
Severity: High
Confidence: Medium
Root cause: TlsStreamSettingsSchema (frontend/src/schemas/protocols/security/tls.ts:106) defaults ALPN to ['h2','http/1.1'] for every transport, and onSecurityChange (frontend/src/pages/inbounds/form/useSecurityActions.ts:347) applies it to ws inbounds too. No later layer (Xray config generation in model.go:375, link/subscription builders in internal/sub/) removes h2 for WebSocket. The default dates back to b639a1bb ("alpn set by default", 2023-04-14, then web/assets/js/model/xray.js) and was carried into the Zod schema by 3f787ae1 (#4599).
Already fixed: No. Still present on the default branch (442b7fb1) and in v3.9.0.
Duplicate of: None. #5473 is about ALPN missing from subscriptions, a different cause.
Evidence: tls.ts:106, useSecurityActions.ts:346-347, inbound-tls-defaults.ts:31 (Hysteria-only override), model.go:375-383, service.go:877, json_service.go:771, golden fixtures vless-ws-tls.json:68 and trojan-ws-tls.json:65.
Not determined: Whether Xray-core's WS listener, rather than the client's TLS fingerprint, is what picks h2. This rests on your log and XTLS/Xray-core#6128 and is not verified here. A WS + TLS test against the current Xray with server ALPN h2,http/1.1 would settle it. I also did not check whether Trojan + WS behaves the same, though its fixture stores the same ALPN.

Suggested fix: Changing the form default only (as #4076 did for Hysteria) would leave existing WS inbounds broken, as you note. A more complete fix also removes h2 from a ws inbound's ALPN where GenXrayInboundConfig builds the server config and where internal/sub builds links and subscriptions, plus the matching link builders in frontend/src/lib/xray/ and docs/lib/xray/. A DB migration that rewrites stored ALPN would be an alternative, but it changes users' saved data, so the maintainer has to decide between the two.

@MHSanaei: confirmed High-severity default-configuration bug, see the root cause above.

This reply was generated automatically; a maintainer may follow up.

<!-- gh-comment-id:6095118764 --> @github-actions[bot] commented on GitHub (Oct 10, 2026): This is a real panel-side bug. When you switch Security to TLS, every inbound gets ALPN `h2, http/1.1`, whatever its transport. Nothing on the server-config, share-link or subscription path drops `h2` for WebSocket, so a WS + TLS inbound made with the defaults sends Xray and clients the exact combination your log shows failing. It is still present on the default branch. **Workaround:** in the inbound's TLS section, set **ALPN** to `http/1.1` only, or clear it. Then re-import the link or refresh the subscription. The client keeps whatever ALPN it got from the old link until it does. **How the default reaches the client** (everything below is checked in the source): 1. `frontend/src/schemas/protocols/security/tls.ts:106` sets the default, which applies to every transport: ```ts alpn: z.array(AlpnSchema).default(['h2', 'http/1.1']), ``` 2. `onSecurityChange` uses it with no check on the transport (`frontend/src/pages/inbounds/form/useSecurityActions.ts:346-347`): ```ts if (next === 'tls') { cleaned.tlsSettings = createTlsSettingsWithDefaultCert(); ``` The only exception is Hysteria, in `createHysteriaTlsSettingsWithDefaultCert` (`frontend/src/lib/xray/inbound-tls-defaults.ts:31`: `tls.alpn = ['h3'];`). There is nothing similar for `ws`. 3. Server config: `Inbound.GenXrayInboundConfig` (`internal/database/model/model.go:375-383`) only strips XHTTP client fields and heals Hysteria. It passes `tlsSettings.alpn` to Xray unchanged. 4. Links and subscriptions copy it as is: `params["alpn"] = strings.Join(inst.ALPN, ",")` (`internal/sub/service.go:877`), the per-protocol TLS param builders (`internal/sub/service.go:1433-1441`, `1834-1842`, `1869-1877`), and `tlsData["alpn"] = tData["alpn"]` in the JSON subscription (`internal/sub/json_service.go:771`). 5. The golden fixtures already store the failing combination as the expected output: `frontend/src/test/golden/fixtures/inbound-full/vless-ws-tls.json:68` and `trojan-ws-tls.json:65` both contain `"alpn": ["h2", "http/1.1"]`. I did not check the Xray-core side, because Xray's websocket source is not in this repository. That covers Xray picking `h2` and the WS dialer then rejecting it. The evidence for it is your log (`websocket: protocol "h2" was given but is not supported`) and the upstream issue you linked (XTLS/Xray-core#6128). Verdict: Confirmed bug Severity: High Confidence: Medium Root cause: `TlsStreamSettingsSchema` (`frontend/src/schemas/protocols/security/tls.ts:106`) defaults ALPN to `['h2','http/1.1']` for every transport, and `onSecurityChange` (`frontend/src/pages/inbounds/form/useSecurityActions.ts:347`) applies it to `ws` inbounds too. No later layer (Xray config generation in `model.go:375`, link/subscription builders in `internal/sub/`) removes `h2` for WebSocket. The default dates back to b639a1bb ("alpn set by default", 2023-04-14, then `web/assets/js/model/xray.js`) and was carried into the Zod schema by 3f787ae1 (#4599). Already fixed: No. Still present on the default branch (442b7fb1) and in v3.9.0. Duplicate of: None. #5473 is about ALPN missing from subscriptions, a different cause. Evidence: `tls.ts:106`, `useSecurityActions.ts:346-347`, `inbound-tls-defaults.ts:31` (Hysteria-only override), `model.go:375-383`, `service.go:877`, `json_service.go:771`, golden fixtures `vless-ws-tls.json:68` and `trojan-ws-tls.json:65`. Not determined: Whether Xray-core's WS listener, rather than the client's TLS fingerprint, is what picks `h2`. This rests on your log and XTLS/Xray-core#6128 and is not verified here. A WS + TLS test against the current Xray with server ALPN `h2,http/1.1` would settle it. I also did not check whether Trojan + WS behaves the same, though its fixture stores the same ALPN. Suggested fix: Changing the form default only (as #4076 did for Hysteria) would leave existing WS inbounds broken, as you note. A more complete fix also removes `h2` from a `ws` inbound's ALPN where `GenXrayInboundConfig` builds the server config and where `internal/sub` builds links and subscriptions, plus the matching link builders in `frontend/src/lib/xray/` and `docs/lib/xray/`. A DB migration that rewrites stored ALPN would be an alternative, but it changes users' saved data, so the maintainer has to decide between the two. @MHSanaei: confirmed High-severity default-configuration bug, see the root cause above. *This reply was generated automatically; a maintainer may follow up.* <!-- claude-issue:analyst -->
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
MHSanaei/3x-ui#4518
No description provided.