mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 19:11:53 +07:00
[PR #6521] [MERGED] fix(xray): read an outbound protocol id the way the core does #6328
Labels
No labels
backlog
bug
clarification needed
documentation
duplicate
enhancement
github_actions
good first issue
invalid
javascript
New Feature
PR welcomed
pull-request
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
MHSanaei/3x-ui#6328
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/MHSanaei/3x-ui/pull/6521
Author: @BlindMaster24
Created: 9/14/2026
Status: ✅ Merged
Merged: 9/14/2026
Merged by: @BlindMaster24
Base:
main← Head:fix/rewriter-protocol-case📝 Commits (3)
35e4d75fix(xray): read an outbound protocol id the way the core doesf9f84f9fix(xray): match an outbound protocol id case-insensitively11cabcefix(xray): re-run the freedom finalRules rewrite where its seeder was gated📊 Changes
3 files changed (+336 additions, -5 deletions)
View changed files
📝
internal/database/db.go(+82 -5)📝
internal/database/freedom_domain_strategy_migration_test.go(+5 -0)➕
internal/database/rewriter_protocol_case_test.go(+249 -0)📄 Description
Summary
The three seeders that rewrite
xrayTemplateConfigcomparedprotocolcase-sensitively (proto != "freedom"), while xray-core lowercases that id before it looks up the handler. A template that spells the direct outboundFreedomtherefore runs as freedom and escapes all three rewrites — and each seeder still records itself as applied, so it never runs again.Why
The core's loader,
infra/conf/loader.go:infra/conf/xray.go:329calls it withc.Protocolfor every outbound, so"protocol": "Freedom"is the freedom handler, not an unknown protocol. That id is also the only thing the panel's rewriters look at, which is where the two sides disagree.User story — a panel whose Xray template was hand-edited (the template is an editable JSON setting in the panel, and it is also what an imported config lands in) with
"Freedom"for the direct outbound:rewriteRemovedOutboundKeysexists precisely becausesockopt.addressPortStrategyon freedom is a hard error in the core (infra/conf/xray.go:340-344): a panel carrying that key cannot start xray at all. SpelledFreedom, the key is never dropped, the seed is recorded as applied, and the install stays dead on a key the seeder was written to remove.rewriteFreedomFinalRulesPrivateEgressis the fix for #6037: withdomainStrategy: AsIsthe router never resolves domains, so a domain with a private A record (e.g.127-0-0-1.nip.io) sails past thegeoip:privaterouting block, and freedom's allow-allfinalRuleslet it reach loopback services such as the xray gRPC API and metrics listener. Skipped, the outbound keeps the allow-only rules, the seed is recorded, and no later start ever retries the hardening.rewriteFreedomFinalRulesreplaces the legacy private-only-allowfinalRules, a state an intermediate release shipped, with allow-all; skipped, that outbound keeps its broken egress.All three are one root cause in one file, so the change is one predicate each.
Type of change
Areas affected
How was this tested?
internal/database/rewriter_protocol_case_test.goadds two tests, both red before the change and green after (verified by reverting the fix and watching each subtest fail):TestRewriteRemovedOutboundKeysSeesAnUppercaseFreedomdrives the vendored core: it assertsxray.ValidateOutboundConfigrefuses the"Freedom"outbound carryingsockopt.addressPortStrategy(which is the proof the core loaded it as freedom rather than rejecting the id), then requires the rewrite to drop the key and the core to accept the result.TestRewritersTreatProtocolCaseAlikeruns all three rewriters on the same outbound spelledfreedomandFreedomand requires the same verdict and the same migrated keys.Reproducing locally:
go test ./internal/database/ -run 'RewritersTreatProtocolCaseAlike|SeesAnUppercaseFreedom'.Honest note about my machine: it has no C compiler, so
internal/databasebuilds only underCGO_ENABLED=0with the cgo-onlysqlite3.SQLiteConn.Backupcall stubbed by a-overlayfile (no file of this PR is substituted). The pure-function tests above run that way; every DB-backed test in the package needs cgo and is left to CI, as isgo build ./....Screenshots / recordings
N/A
Breaking changes
None. The seeders only match strictly more configs than before, and every config they newly match is one the core already treats as freedom.
Checklist
go build ./...and the test suite pass locally. (no C compiler here — CI verifies)npm run lint,npm run typecheck, andnpm run buildpass.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.