[GH-ISSUE #6536] [Bug]: JSON subscription routing ignores "direct" fallback — catch-all rule sends all unmatched traffic to proxy #4389

Closed
opened 2026-10-31 20:39:19 +07:00 by bsakaguchi · 1 comment
Owner

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

  1. Open a routing profile editor for a client, set a domain/geoip allowlist for proxy (e.g. some geosite entries) and RouteOrder "block-proxy-direct"
  2. Encode it as incy://routing/onadd/... and attach it to a client's JSON subscription
  3. Fetch the client's JSON subscription (subJsonEnable) from the panel
  4. Inspect the generated routing.rules array

Expected 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

  • I searched existing issues and this bug has not been reported.
  • I am running the latest released version of 3x-ui (or have verified the bug still exists on it).
  • This bug report is written in English.
  • I have redacted any sensitive data (tokens, real domains, client UUIDs).
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 1. Open a routing profile editor for a client, set a domain/geoip allowlist for `proxy` (e.g. some geosite entries) and RouteOrder "block-proxy-direct" 2. Encode it as incy://routing/onadd/... and attach it to a client's JSON subscription 3. Fetch the client's JSON subscription (subJsonEnable) from the panel 4. Inspect the generated `routing.rules` array ### Expected 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 ```shell ``` ### 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 - [x] I searched [existing issues](../issues?q=is%3Aissue) and this bug has not been reported. - [x] I am running the latest released version of 3x-ui (or have verified the bug still exists on it). - [x] This bug report is written in English. - [x] I have redacted any sensitive data (tokens, real domains, client UUIDs).
bsakaguchi 2026-10-31 20:39:19 +07:00
  • closed this issue
  • added the
    question
    label
Author
Owner

@github-actions[bot] commented on GitHub (Sep 15, 2026):

Both behaviours you hit are intentional, and neither is a defect: RouteOrder only 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 proxy catch-all is the JSON subscription's default, not a missing direct rule

The final rule is appended unconditionally in applyJsonRouting:

// internal/sub/json_routing.go:352
rules = append(rules, map[string]any{"type": "field", "network": "tcp,udp", "outboundTag": "proxy"})

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-90 already ships:

"routing": {
  "domainStrategy": "AsIs",
  "rules": [
    { "type": "field", "network": "tcp,udp", "outboundTag": "proxy" }
  ]
}

A routing profile replaces the dns/routing subtrees but keeps that default route, which is what makes the emitted document a usable VPN config: unmatched traffic goes through the server.

RouteOrder is only the iteration order of the block/direct/proxy groups — it is not a fallback selector, and the format carries no field for one:

// internal/sub/json_routing.go:25
RouteOrder []string // e.g. {"block","proxy","direct"}; default {"block","direct","proxy"}
// internal/sub/json_routing.go:271
func routeOrderGroups(order []string) []string {
	if len(order) == 0 {
		return []string{"block", "direct", "proxy"}
	}
	return order
}

The behaviour is pinned by a test that uses your exact "RouteOrder": "block-proxy-direct" (internal/sub/json_routing_baked_test.go:25):

// internal/sub/json_routing_baked_test.go:111
want := []string{"domain->block", "domain->PROXY", "domain->direct", "ip->direct", "network->PROXY"}

The direct outbound is not dead in the general case — rules 3 and 4 above point at it. In your configuration it looks unreferenced because DirectSites/DirectIp are empty, and an empty group emits nothing (internal/sub/json_routing.go:345: if len(rule[key].([]string)) == 0 { continue }).

Making the catch-all direct would 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:157 asserts "network->balancer:balancer" as the last rule.

Workaround that does what you want

Put the catch-all inside the profile itself, as the direct group. With RouteOrder: "block-proxy-direct" the direct rules are emitted after the proxy rules and before the final proxy rule, so they win:

{
  "DomainStrategy": "IPIfNonMatch",
  "RouteOrder": "block-proxy-direct",
  "BlockSites": ["geosite:category-ads"],
  "ProxySites": ["geosite:youtube"],
  "DirectIp": ["0.0.0.0/0", "::/0"]
}

That emits {"type":"field","ip":["0.0.0.0/0","::/0"],"outboundTag":"direct"} ahead of the tcp,udp → proxy rule. Keep DomainStrategy at IPIfNonMatch (the default, internal/sub/json_routing.go:317-320) so a domain that matched no domain rule is resolved and then caught by the 0.0.0.0/0 rule.

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:

  • the control writes into templateSettings — frontend/src/pages/xray/routing/RoutingBasic.tsx:137-154 (ruleSetter(tt, 'direct', 'ip', v));
  • that is stored under the xrayTemplateConfig setting — internal/web/service/setting.go:463-465;
  • and read only by XrayService.GetXrayConfig — internal/web/service/xray.go:145-146: templateConfig, err := s.settingService.GetXrayConfigTemplate().

internal/sub/ never reads xrayTemplateConfig (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 subJsonRules setting (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:

// internal/sub/json_service.go:65
if routingRules == "" && rules != "" {

So: use subJsonRules or the routing profile's DirectIp, 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:352 in applyJsonRouting preserves the JSON subscription template's own default route (internal/sub/default.json:84-88); RouteOrder is consumed only by routeOrderGroups (internal/sub/json_routing.go:271-276) as a group ordering, never as a default-outbound selector. The Direct Connection fields write xrayTemplateConfig, which internal/sub/ does not read.
Already fixed: Not applicable — behaviour is current on the default branch (a810f497), introduced together with the feature in 2dd903ea "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-existing tcp,udp → proxy rule
  • internal/sub/json_routing.go:25 — RouteOrder []string // e.g. {"block","proxy","direct"}; default {"block","direct","proxy"}
  • internal/sub/json_routing.go:271-276 — routeOrderGroups orders groups only
  • internal/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_BakedRoutingInEveryDocument pins network->PROXY last for RouteOrder: "block-proxy-direct"
  • internal/sub/json_routing_baked_test.go:157 — TestSubJson_BakedRoutingWithBalancer pins network->balancer:balancer last
  • internal/sub/json_service.go:65 — subJsonRules applies only when no routing profile is set
  • internal/web/service/setting.go:463-465 + internal/web/service/xray.go:145-146 — xrayTemplateConfig feeds the server's own Xray config
    Not determined: Whether Happ's and INCY's own reference implementations treat the last RouteOrder segment 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 bug to question. If the workaround above does not produce the rule order you need, comment with the profile JSON you used and the resulting routing.rules array as text and it can be reopened.

This reply was generated automatically; a maintainer may follow up.

<!-- gh-comment-id:5673466262 --> @github-actions[bot] commented on GitHub (Sep 15, 2026): Both behaviours you hit are intentional, and neither is a defect: `RouteOrder` only 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 `proxy` catch-all is the JSON subscription's default, not a missing `direct` rule The final rule is appended unconditionally in `applyJsonRouting`: ```go // internal/sub/json_routing.go:352 rules = append(rules, map[string]any{"type": "field", "network": "tcp,udp", "outboundTag": "proxy"}) ``` 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-90` already ships: ```json "routing": { "domainStrategy": "AsIs", "rules": [ { "type": "field", "network": "tcp,udp", "outboundTag": "proxy" } ] } ``` A routing profile replaces the `dns`/`routing` subtrees but keeps that default route, which is what makes the emitted document a usable VPN config: unmatched traffic goes through the server. `RouteOrder` is only the iteration order of the block/direct/proxy groups — it is not a fallback selector, and the format carries no field for one: ```go // internal/sub/json_routing.go:25 RouteOrder []string // e.g. {"block","proxy","direct"}; default {"block","direct","proxy"} ``` ```go // internal/sub/json_routing.go:271 func routeOrderGroups(order []string) []string { if len(order) == 0 { return []string{"block", "direct", "proxy"} } return order } ``` The behaviour is pinned by a test that uses your exact `"RouteOrder": "block-proxy-direct"` (`internal/sub/json_routing_baked_test.go:25`): ```go // internal/sub/json_routing_baked_test.go:111 want := []string{"domain->block", "domain->PROXY", "domain->direct", "ip->direct", "network->PROXY"} ``` The `direct` outbound is not dead in the general case — rules 3 and 4 above point at it. In your configuration it looks unreferenced because `DirectSites`/`DirectIp` are empty, and an empty group emits nothing (`internal/sub/json_routing.go:345`: `if len(rule[key].([]string)) == 0 { continue }`). Making the catch-all `direct` would 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:157` asserts `"network->balancer:balancer"` as the last rule. ### Workaround that does what you want Put the catch-all inside the profile itself, as the `direct` group. With `RouteOrder: "block-proxy-direct"` the direct rules are emitted *after* the proxy rules and *before* the final `proxy` rule, so they win: ```json { "DomainStrategy": "IPIfNonMatch", "RouteOrder": "block-proxy-direct", "BlockSites": ["geosite:category-ads"], "ProxySites": ["geosite:youtube"], "DirectIp": ["0.0.0.0/0", "::/0"] } ``` That emits `{"type":"field","ip":["0.0.0.0/0","::/0"],"outboundTag":"direct"}` ahead of the `tcp,udp → proxy` rule. Keep `DomainStrategy` at `IPIfNonMatch` (the default, `internal/sub/json_routing.go:317-320`) so a domain that matched no domain rule is resolved and then caught by the `0.0.0.0/0` rule. ## 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: - the control writes into `templateSettings` — `frontend/src/pages/xray/routing/RoutingBasic.tsx:137-154` (`ruleSetter(tt, 'direct', 'ip', v)`); - that is stored under the `xrayTemplateConfig` setting — `internal/web/service/setting.go:463-465`; - and read only by `XrayService.GetXrayConfig` — `internal/web/service/xray.go:145-146`: `templateConfig, err := s.settingService.GetXrayConfigTemplate()`. `internal/sub/` never reads `xrayTemplateConfig` (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 `subJsonRules` setting (`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: ```go // internal/sub/json_service.go:65 if routingRules == "" && rules != "" { ``` So: use `subJsonRules` **or** the routing profile's `DirectIp`, 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:352` in `applyJsonRouting` preserves the JSON subscription template's own default route (`internal/sub/default.json:84-88`); `RouteOrder` is consumed only by `routeOrderGroups` (`internal/sub/json_routing.go:271-276`) as a group ordering, never as a default-outbound selector. The Direct Connection fields write `xrayTemplateConfig`, which `internal/sub/` does not read. Already fixed: Not applicable — behaviour is current on the default branch (`a810f497`), introduced together with the feature in `2dd903ea` "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-existing `tcp,udp → proxy` rule - `internal/sub/json_routing.go:25` — `RouteOrder []string // e.g. {"block","proxy","direct"}; default {"block","direct","proxy"}` - `internal/sub/json_routing.go:271-276` — `routeOrderGroups` orders groups only - `internal/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_BakedRoutingInEveryDocument` pins `network->PROXY` last for `RouteOrder: "block-proxy-direct"` - `internal/sub/json_routing_baked_test.go:157` — `TestSubJson_BakedRoutingWithBalancer` pins `network->balancer:balancer` last - `internal/sub/json_service.go:65` — `subJsonRules` applies only when no routing profile is set - `internal/web/service/setting.go:463-465` + `internal/web/service/xray.go:145-146` — `xrayTemplateConfig` feeds the server's own Xray config Not determined: Whether Happ's and INCY's own reference implementations treat the last `RouteOrder` segment 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 `bug` to `question`. If the workaround above does not produce the rule order you need, comment with the profile JSON you used and the resulting `routing.rules` array as text and it can be reopened. *This reply was generated automatically; a maintainer may follow up.* <!-- claude-issue:analyst -->
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#4389
No description provided.