mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[GH-ISSUE #6536] [Bug]: JSON subscription routing ignores "direct" fallback — catch-all rule sends all unmatched traffic to proxy #4389
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#4389
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?
Originally created by @NooNooJoo on GitHub (Sep 15, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/6536
Describe the bug
When a routing profile (incy://routing/onadd/...) is set on a client's subscription with RouteOrder "block-proxy-direct", the JSON subscription output correctly generates rules for the "block" and "proxy" groups, but never generates a rule sending unmatched traffic to the "direct" outbound. Instead, a catch-all rule
{"network":"tcp,udp","outboundTag":"proxy"}is appended at the end of routing.rules, which matches everything that wasn't already caught by the domain/geoip rules. The "direct" outbound is present in outbounds[] but no rule ever points to it, so it's dead and all traffic ends up going through the proxy regardless of the routing profile's intent.I tried the panel's own "Direct Connection" feature (Xray Configuration → Routing → Direct Connection) as a workaround, adding 0.0.0.0/0 and ::/0 to "Direct Connection IPs" to force a catch-all direct rule. This setting is silently ignored — it has no effect on the generated JSON subscription output at all.
How to reproduce the problem
proxy(e.g. some geosite entries) and RouteOrder "block-proxy-direct"routing.rulesarrayExpected behavior
I expected a rule routing unmatched traffic to the "direct" outbound (e.g. {"network":"tcp,udp","outboundTag":"direct"}), matching the routing profile's RouteOrder intent, and I expected the Direct Connection IPs setting (0.0.0.0/0 / ::/0) to actually affect the generated subscription if used as a workaround.
Actual behavior
Instead, the panel appends {"network":"tcp,udp","outboundTag":"proxy"} as the final catch-all rule. The "direct" outbound is declared in outbounds[] but is unreachable — no rule references it. All traffic not matched by the explicit proxy rules is routed through proxy anyway. The Direct Connection IPs setting has no observable effect on the JSON subscription output.
Relevant logs
Screenshots
No response
3x-ui version
3.8.0
Xray-core version
26.7.28
How did you install 3x-ui?
install.sh script
Operating system
Ubuntu 24.04
Which parts of the panel are affected?
Subscription (share links / Clash / JSON)
Browser (only if it is a UI bug)
No response
Is the panel behind a reverse proxy or CDN?
Yes — Cloudflare (proxied DNS)
Before submitting
@github-actions[bot] commented on GitHub (Sep 15, 2026):
Both behaviours you hit are intentional, and neither is a defect:
RouteOrderonly orders the three rule groups — it does not pick the default outbound — and the panel's Xray Configuration → Routing → Direct Connection fields belong to the server's Xray config, not to what a client downloads. There is a working way to get what you want, below.1. The
proxycatch-all is the JSON subscription's default, not a missingdirectruleThe final rule is appended unconditionally in
applyJsonRouting:It is there because that rule is the JSON subscription template's default and predates the routing-profile feature entirely —
internal/sub/default.json:81-90already ships:A routing profile replaces the
dns/routingsubtrees but keeps that default route, which is what makes the emitted document a usable VPN config: unmatched traffic goes through the server.RouteOrderis only the iteration order of the block/direct/proxy groups — it is not a fallback selector, and the format carries no field for one:The behaviour is pinned by a test that uses your exact
"RouteOrder": "block-proxy-direct"(internal/sub/json_routing_baked_test.go:25):The
directoutbound is not dead in the general case — rules 3 and 4 above point at it. In your configuration it looks unreferenced becauseDirectSites/DirectIpare empty, and an empty group emits nothing (internal/sub/json_routing.go:345:if len(rule[key].([]string)) == 0 { continue }).Making the catch-all
directwould also break the feature's main use case: for a balancer document the same rule is rewritten to the balancer tag, so a client-side balancer would never be reached —internal/sub/json_routing_baked_test.go:157asserts"network->balancer:balancer"as the last rule.Workaround that does what you want
Put the catch-all inside the profile itself, as the
directgroup. WithRouteOrder: "block-proxy-direct"the direct rules are emitted after the proxy rules and before the finalproxyrule, so they win:That emits
{"type":"field","ip":["0.0.0.0/0","::/0"],"outboundTag":"direct"}ahead of thetcp,udp → proxyrule. KeepDomainStrategyatIPIfNonMatch(the default,internal/sub/json_routing.go:317-320) so a domain that matched no domain rule is resolved and then caught by the0.0.0.0/0rule.2. "Direct Connection IPs" is a server-side setting — it cannot affect a subscription
Those fields edit the Xray template config, which is the config the panel feeds to its own Xray process:
templateSettings—frontend/src/pages/xray/routing/RoutingBasic.tsx:137-154(ruleSetter(tt, 'direct', 'ip', v));xrayTemplateConfigsetting —internal/web/service/setting.go:463-465;XrayService.GetXrayConfig—internal/web/service/xray.go:145-146:templateConfig, err := s.settingService.GetXrayConfigTemplate().internal/sub/never readsxrayTemplateConfig(no match anywhere in the package), so "no observable effect on the JSON subscription output" is the designed behaviour, not a silent failure.The JSON subscription has its own direct/block rule editor, under Subscription settings → Formats → JSON, which writes the
subJsonRulessetting (frontend/src/pages/settings/SubscriptionFormatsTab.tsx:408-420). Note it is mutually exclusive with the routing profile — with a profile set it is ignored by design:So: use
subJsonRulesor the routing profile'sDirectIp, not the Xray routing page.Verdict: Not a bug (expected behaviour)
Severity: N/A
Confidence: High
Root cause: No defect. The unconditional catch-all at
internal/sub/json_routing.go:352inapplyJsonRoutingpreserves the JSON subscription template's own default route (internal/sub/default.json:84-88);RouteOrderis consumed only byrouteOrderGroups(internal/sub/json_routing.go:271-276) as a group ordering, never as a default-outbound selector. The Direct Connection fields writexrayTemplateConfig, whichinternal/sub/does not read.Already fixed: Not applicable — behaviour is current on the default branch (
a810f497), introduced together with the feature in2dd903ea"feat(sub): bake Happ/INCY routing profiles into the JSON subscription (#6402)".Duplicate of: None.
Related: #6305(routing for the client-side load balancer) overlaps in area only.Evidence:
internal/sub/json_routing.go:352—rules = append(rules, map[string]any{"type": "field", "network": "tcp,udp", "outboundTag": "proxy"})internal/sub/default.json:84-88— the template's pre-existingtcp,udp → proxyruleinternal/sub/json_routing.go:25—RouteOrder []string // e.g. {"block","proxy","direct"}; default {"block","direct","proxy"}internal/sub/json_routing.go:271-276—routeOrderGroupsorders groups onlyinternal/sub/json_routing.go:345—if len(rule[key].([]string)) == 0 { continue }(empty group emits no rule)internal/sub/json_routing_baked_test.go:111—TestSubJson_BakedRoutingInEveryDocumentpinsnetwork->PROXYlast forRouteOrder: "block-proxy-direct"internal/sub/json_routing_baked_test.go:157—TestSubJson_BakedRoutingWithBalancerpinsnetwork->balancer:balancerlastinternal/sub/json_service.go:65—subJsonRulesapplies only when no routing profile is setinternal/web/service/setting.go:463-465+internal/web/service/xray.go:145-146—xrayTemplateConfigfeeds the server's own Xray configNot determined: Whether Happ's and INCY's own reference implementations treat the last
RouteOrdersegment as a fallback — that is upstream and not in this repository. It would not change the verdict for 3x-ui, whose behaviour here is deliberate and test-pinned; if an upstream spec does define a default-outbound field, quoting it would be the thing that turns this into a feature request.Closing as expected behaviour and relabelling from
bugtoquestion. If the workaround above does not produce the rule order you need, comment with the profile JSON you used and the resultingrouting.rulesarray as text and it can be reopened.This reply was generated automatically; a maintainer may follow up.