fix(xray): read the last two inboundTag protocol ids like the core (#6530)

The core lowercases an outbound's protocol id before it resolves the handler,
so an outbound spelled "Loopback" still is the loopback outbound. Both
readers that keep a loopback outbound's inboundTag in step with the inbound
it names compared the id exactly, so such an outbound was skipped: renaming
or deleting that inbound left settings.inboundTag pointing at a tag that no
longer exists, and traffic returning through the loopback outbound arrives
under a tag no routing rule can match (infra/conf/loopback.go:15 carries the
tag, proxy/loopback/loopback.go:43 uses it as the inbound identity).

The probe lane's "nothing to test here" gate had the same exact comparison,
so a "Freedom"/"Blackhole" outbound reported the vaguer "No testable
endpoint" where the canonical spelling reports "Outbound has no testable
endpoint" — the two spellings took different paths to the same rejection.

Both readers now compare case-insensitively; the outbound package reuses its
existing equalsAnyFold helper rather than adding a second one. The service
reads the config template an operator edits, so a case variant is reachable
there; server.go's GetDefaultLogOutboundTags scans the embedded config.json
instead, whose protocols are canonical by construction, so it is left as is
and no test can tell a case-insensitive read there from an exact one.
This commit is contained in:
BlindMaster24
2026-09-14 21:18:31 +03:00
committed by GitHub
parent 837addf66e
commit a810f497e6
4 changed files with 102 additions and 3 deletions
+1 -1
View File
@@ -157,7 +157,7 @@ func (s *OutboundService) testOutboundTCP(outboundJSON string) (*TestOutboundRes
}
tag, _ := ob["tag"].(string)
protocol, _ := ob["protocol"].(string)
if protocol == "blackhole" || protocol == "freedom" || tag == "blocked" {
if equalsAnyFold(protocol, "blackhole", "freedom") || tag == "blocked" {
return &TestOutboundResult{Tag: tag, Mode: "tcp", Success: false, Error: "Outbound has no testable endpoint"}, nil
}
@@ -110,6 +110,37 @@ func TestBuildBatchTestConfigReadsTheProtocolIDLikeTheCore(t *testing.T) {
}
}
func TestTestOutboundsRejectsUntestableIDsInAnyCase(t *testing.T) {
tests := []struct {
name string
protocol string
}{
{"canonical freedom", "freedom"},
{"capitalised freedom", "Freedom"},
{"upper freedom", "FREEDOM"},
{"canonical blackhole", "blackhole"},
{"capitalised blackhole", "Blackhole"},
}
const wantErr = "Outbound has no testable endpoint"
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
batch := mustJSON(t, []any{map[string]any{"tag": "t1", "protocol": tt.protocol}})
results, err := (&OutboundService{}).TestOutbounds(batch, "", "", "tcp")
if err != nil {
t.Fatalf("TestOutbounds: %v", err)
}
r := results[0]
if r.Success {
t.Errorf("%q outbound = %+v, want a rejection", tt.protocol, r)
}
if r.Error != wantErr {
t.Errorf("%q error = %q, want %q", tt.protocol, r.Error, wantErr)
}
})
}
}
func TestTestOutboundsTCPLaneReadsProtocolIDCaseInsensitively(t *testing.T) {
l, err := net.Listen("tcp", "127.0.0.1:0")
if err != nil {