[PR #5861] [MERGED] fix(inbound): reject finalmask + REALITY combo (crashes Xray-core) #6011

Closed
opened 2026-11-02 04:05:45 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/5861
Author: @mrnickson-hue
Created: 7/8/2026
Status: ✅ Merged
Merged: 7/8/2026
Merged by: @MHSanaei

Base: main ← Head: fix/reject-finalmask-reality-combo


📝 Commits (2)

  • 13f1d6c fix(inbound): reject finalmask configured together with REALITY security
  • 6f962ba fix(inbound): heal legacy rows and narrow the finalmask+REALITY guard

📊 Changes

3 files changed (+219 additions, -0 deletions)

View changed files

📝 internal/web/service/inbound.go (+50 -0)
➕ internal/web/service/inbound_finalmask_reality_test.go (+157 -0)
📝 internal/web/service/xray.go (+12 -0)

📄 Description

Summary

Configuring finalmask on an inbound with security: reality currently crashes the entire Xray-core process on the first connection — not just that connection. Reproduced live on a clean build from source (v26.6.27):

panic: interface conversion: *fragment.fragmentConn is not reality.CloseWriteConn: missing method CloseWrite

github.com/xtls/reality.Server(...)
	tls.go:186

Root cause: finalmask wraps the listener/connection before REALITY's handshake ever sees it (TcpmaskManager.WrapListener → WrapConnServer runs at Accept() time, ahead of reality.Server()). reality.Server() then does an unchecked type assertion assuming the connection is always a raw *net.TCPConn. With finalmask in front, it's a *fragment.fragmentConn instead, and the assertion panics.

Filed upstream with full repro + trace: https://github.com/XTLS/Xray-core/issues/6453

RPRX (Xray-core/REALITY author) responded and closed it — the plan upstream is to document this combination as unsupported rather than make the failure mode graceful. Since the crash itself won't be fixed at the engine level, the panel needs to stop this configuration from being saved in the first place.

Change

AddInbound / UpdateInbound now reject streamSettings with security: reality and a non-empty finalmask.tcp/finalmask.udp with a clear error, instead of letting it reach Xray and crash the process.

Test plan

  • go build ./internal/web/service/...
  • New test TestValidateFinalMaskRealityCombo — 6 cases (empty streamSettings, reality without finalmask, reality with empty finalmask arrays, reality+tcp fragment, reality+udp mask, non-reality security+finalmask)
  • Full go test ./internal/web/service/ — all passing, no regressions

Related: #5857 (originally reported as an xHTTP-specific connection failure; root cause turned out to be this panic, not xHTTP-specific — reproduces on plain tcp transport too)


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/MHSanaei/3x-ui/pull/5861 **Author:** [@mrnickson-hue](https://github.com/mrnickson-hue) **Created:** 7/8/2026 **Status:** ✅ Merged **Merged:** 7/8/2026 **Merged by:** [@MHSanaei](https://github.com/MHSanaei) **Base:** `main` ← **Head:** `fix/reject-finalmask-reality-combo` --- ### 📝 Commits (2) - [`13f1d6c`](https://github.com/MHSanaei/3x-ui/commit/13f1d6c23fbcad4906c35afe51600a585a34df39) fix(inbound): reject finalmask configured together with REALITY security - [`6f962ba`](https://github.com/MHSanaei/3x-ui/commit/6f962ba3e3d68b71a9fa793bde8e833474f22f64) fix(inbound): heal legacy rows and narrow the finalmask+REALITY guard ### 📊 Changes **3 files changed** (+219 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `internal/web/service/inbound.go` (+50 -0) ➕ `internal/web/service/inbound_finalmask_reality_test.go` (+157 -0) 📝 `internal/web/service/xray.go` (+12 -0) </details> ### 📄 Description ## Summary Configuring `finalmask` on an inbound with `security: reality` currently crashes the entire Xray-core process on the first connection — not just that connection. Reproduced live on a clean build from source (v26.6.27): ``` panic: interface conversion: *fragment.fragmentConn is not reality.CloseWriteConn: missing method CloseWrite github.com/xtls/reality.Server(...) tls.go:186 ``` Root cause: `finalmask` wraps the listener/connection before REALITY's handshake ever sees it (`TcpmaskManager.WrapListener` → `WrapConnServer` runs at `Accept()` time, ahead of `reality.Server()`). `reality.Server()` then does an unchecked type assertion assuming the connection is always a raw `*net.TCPConn`. With finalmask in front, it's a `*fragment.fragmentConn` instead, and the assertion panics. Filed upstream with full repro + trace: https://github.com/XTLS/Xray-core/issues/6453 RPRX (Xray-core/REALITY author) responded and closed it — the plan upstream is to document this combination as unsupported rather than make the failure mode graceful. Since the crash itself won't be fixed at the engine level, the panel needs to stop this configuration from being saved in the first place. ## Change `AddInbound` / `UpdateInbound` now reject `streamSettings` with `security: reality` and a non-empty `finalmask.tcp`/`finalmask.udp` with a clear error, instead of letting it reach Xray and crash the process. ## Test plan - [x] `go build ./internal/web/service/...` - [x] New test `TestValidateFinalMaskRealityCombo` — 6 cases (empty streamSettings, reality without finalmask, reality with empty finalmask arrays, reality+tcp fragment, reality+udp mask, non-reality security+finalmask) - [x] Full `go test ./internal/web/service/` — all passing, no regressions Related: #5857 (originally reported as an xHTTP-specific connection failure; root cause turned out to be this panic, not xHTTP-specific — reproduces on plain `tcp` transport too) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 04:05:45 +07:00
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#6011
No description provided.