mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-11-19 11:34:59 +03:00
fix(inbounds): flag conflicts with the reserved Xray API port (#5304)
The internal API inbound (tag "api", default port 62789 on 127.0.0.1) lives in the Xray config template, not the inbounds table, so checkPortConflict never caught a local user inbound reusing it — Xray then bound the port twice and served requests unpredictably. Now reject a local TCP inbound whose listen overlaps loopback on the reserved API port, read from the template (fallback 62789). Nodes are unaffected since they run their own Xray.
This commit is contained in:
@@ -669,3 +669,65 @@ func TestIsAutoGeneratedTag(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// the internal Xray API inbound (tag "api", loopback TCP) isn't a DB row, so
|
||||
// checkPortConflict must still reject a local user inbound that reuses its
|
||||
// reserved port — otherwise Xray binds the port twice (#5304).
|
||||
func TestCheckPortConflict_ReservedAPIPortBlockedLocal(t *testing.T) {
|
||||
setupConflictDB(t)
|
||||
|
||||
svc := &InboundService{}
|
||||
candidate := &model.Inbound{
|
||||
Tag: "user-62789",
|
||||
Listen: "0.0.0.0",
|
||||
Port: defaultXrayAPIPort,
|
||||
Protocol: model.VLESS,
|
||||
StreamSettings: `{"network":"tcp"}`,
|
||||
}
|
||||
got, err := svc.checkPortConflict(candidate, 0)
|
||||
if err != nil {
|
||||
t.Fatalf("checkPortConflict: %v", err)
|
||||
}
|
||||
if got == nil {
|
||||
t.Fatalf("local inbound on the reserved API port %d must conflict", defaultXrayAPIPort)
|
||||
}
|
||||
if msg := got.String(); !strings.Contains(msg, "api") {
|
||||
t.Fatalf("conflict message should name the api inbound; got %q", msg)
|
||||
}
|
||||
}
|
||||
|
||||
// nodes run their own Xray with their own API port, so a node inbound on the
|
||||
// central panel's reserved API port must be allowed.
|
||||
func TestCheckPortConflict_ReservedAPIPortAllowedOnNode(t *testing.T) {
|
||||
setupConflictDB(t)
|
||||
|
||||
svc := &InboundService{}
|
||||
candidate := &model.Inbound{
|
||||
Tag: "node-62789",
|
||||
Listen: "0.0.0.0",
|
||||
Port: defaultXrayAPIPort,
|
||||
Protocol: model.VLESS,
|
||||
StreamSettings: `{"network":"tcp"}`,
|
||||
NodeID: intPtr(1),
|
||||
}
|
||||
if got, err := svc.checkPortConflict(candidate, 0); err != nil || got != nil {
|
||||
t.Fatalf("node inbound on the reserved API port must be allowed; got=%v err=%v", got, err)
|
||||
}
|
||||
}
|
||||
|
||||
// the API inbound is TCP-only, so a UDP-only inbound (e.g. hysteria) may share
|
||||
// its port — same tcp/udp coexistence the rest of the checks allow.
|
||||
func TestCheckPortConflict_ReservedAPIPortUDPCoexists(t *testing.T) {
|
||||
setupConflictDB(t)
|
||||
|
||||
svc := &InboundService{}
|
||||
candidate := &model.Inbound{
|
||||
Tag: "hyst-62789",
|
||||
Listen: "0.0.0.0",
|
||||
Port: defaultXrayAPIPort,
|
||||
Protocol: model.Hysteria,
|
||||
}
|
||||
if got, err := svc.checkPortConflict(candidate, 0); err != nil || got != nil {
|
||||
t.Fatalf("udp-only inbound must coexist with the tcp API inbound; got=%v err=%v", got, err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user