mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[GH-ISSUE #6072] [Feature]: Add block outbound option and domainStrategy selector for JSON Subscription routing rules #4203
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#4203
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 @SpeedeMiner on GitHub (Jul 22, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/6072
Is your feature request related to a problem?
Description
Currently, the JSON Subscription settings page (
/panel/settings#subscription-formats) allows configuring routing rules only with thedirectoutbound (and the default proxy rule).However, Xray already supports the
block(blackhole) outbound, and the generated JSON subscription already contains ablockoutbound. The UI simply does not provide a way to use it.It would also be useful to allow changing the
routing.domainStrategyvalue from the UI instead of keeping it fixed toAsIs.Proposed changes
Suggested values:
Example
Current generated routing:
@MHSanaei commented on GitHub (Jul 25, 2026):
@claude
@github-actions[bot] commented on GitHub (Jul 25, 2026):
Claude finished @MHSanaei's task in 6m 49s —— View job
Analysis
Both requests are implementable. They are not the same size of change:
blockis frontend-only (the backend already supports it end to end), whiledomainStrategyneeds a new setting plumbed through six files plusmake gen.1. Block outbound: the backend is already done, only the UI is missing
internal/sub/default.jsonalready ships the blackhole outbound in every generated profile:(
internal/sub/default.json:55-63; it is appended to every config vias.defaultOutbounds—internal/sub/json_service.go:241for inbound profiles,:108for external links.)NewSubJsonServicemerges thesubJsonRulessetting verbatim and prepends it to the default rules (internal/sub/json_service.go:41-49), so a rule with"outboundTag": "block"works today. There is even a test that already does exactly that —internal/sub/mutation_audit_test.go:29-46feeds[{"type":"field","domain":["geosite:ads"],"outboundTag":"block"}]and asserts it lands first inrouting.rules.So the only gap is
frontend/src/pages/settings/SubscriptionFormatsTab.tsx, which hardcodesdirect.The hazard to avoid
The current helpers locate rules by which key is present, not by outbound tag:
If block rules are added to the same array, a block rule can be picked up and overwritten by the Direct selectors. Also
directEnabled = allSetting.subJsonRules !== ''(line 80) means turning Direct off wipes the whole string, taking block rules with it. Both need to be scoped byoutboundTagfirst.Proposed replacement for the module constants and state helpers
Inside the component, replacing lines 96-147:
The existing Direct tab (key
'4') then becomes:and a new tab is appended:
StopOutlinedis added to the@ant-design/iconsimport.Three details worth keeping:
block, notblocked. The server-side Xray template usesblocked(frontend/src/pages/xray/basics/constants.ts:63), but the subscription profile's blackhole tag isblock(internal/sub/default.json:56). A rule pointing atblockedwould silently reference a non-existent outbound in the generated client config.blockFirst()keeps block ahead of direct; otherwise a domain covered by both lists would go direct.BLOCK_DOMAINS_OPTIONSfromfrontend/src/pages/xray/basics/constants.ts:32-50. Most of its entries areext:geosite_IR.dat:.../ext:geosite_RU.dat:..., which resolve against files in the panel'sbinfolder. The subscription config runs on the user's device, which usually does not ship those.datfiles. That is why the existingdirectIPsOptions/directDomainsOptionsin this file (lines 44-64) use plaingeoip:/geosite:values only — the block presets should follow the same rule.2. Domain strategy: new setting, six files
routing.domainStrategyis fixed atAsIsininternal/sub/default.json:80and never overwritten. Adding a selector means a new setting key; nothing else reads it.internal/web/service/setting.go— add todefaultValueMapnext tosubJsonRules(line 115) and a getter next toGetSubJsonRules(line 864):internal/web/entity/entity.go— new field afterSubJsonRules(line 103), plus a whitelist check inCheckValid(line 154) so an arbitrary string cannot reach the generated config:internal/sub/json_service.go—NewSubJsonServicehas ~30 call sites in tests, so a variadic option keeps them all compiling and matches the option pattern already used incontroller.go:Signature and the routing block (replacing lines 41-49):
With no option passed the behaviour is byte-identical to today, so
TestSubJsonService_CustomRulesPrependedandTestSubJsonService_EmptyRulesLeavesDefaultstay green unchanged.internal/sub/controller.go— field insubControllerConfig(line 99), option, and the constructor call (line 271):internal/sub/sub.go— read it next toSubJsonRules(line 148) and pass it next toWithSUBJsonRules(line 283):Frontend —
frontend/src/models/setting.ts:65andfrontend/src/schemas/setting.ts:70:and the control, which can sit at the top of the routing tab in
SubscriptionFormatsTab.tsx:ROUTING_DOMAIN_STRATEGIESalready exists with exactly the three values requested (frontend/src/pages/xray/basics/constants.ts:1), imported as@/pages/xray/basics/constants.Repo checklist for this change
getStringfalls back todefaultValueMapwhen the row is missing (internal/web/service/setting.go:340-350) andGetAllSettingfills absent keys from the same map (:248). Existing installs readAsIswithout any write.endpoints.tsentry — no newg.POST/g.GETroute.make genis required after the entity change:AllSetting/AllSettingVieware already in openapigen'sStructAllow(tools/openapigen/main.go:66-67), so the new field flows intofrontend/src/generated/*andfrontend/public/openapi.jsonautomatically.make gen-checkfails otherwise.pages.xray.RoutingStrategy/RoutingStrategyDesc(en-US.json:1597-1598) andpages.xray.blockips/blockdomains(:1580-1581). Only the Block section title needs new keys,pages.settings.blockandpages.settings.blockDesc, and those must be added to all 13 files ininternal/web/translation/, alongside the existingdirect/directDescpair (en-US.json:1436-1437).//comments in the Go/TS above, perCLAUDE.md.frontend/srcedits only reach users once Vite regeneratesinternal/web/dist/.Suggested tests:
internal/sub/json_service_test.go:NewSubJsonService("", "", "", nil, WithRoutingDomainStrategy("IPIfNonMatch"))setsrouting.domainStrategy, and the no-option case still yieldsAsIs— mirroring the shape ofTestSubJsonService_EmptyRulesLeavesDefault.frontend/src/test/subscription-general-tab.test.tsx: enabling Block writes ablockrule ahead of thedirectrules, disabling Direct leaves the block rules intact, andsubJsonRulesbecomes''only when nothing remains.One behavioural note for the changelog: the subscription server reads these settings when it is constructed (
internal/sub/sub.go:148,:283), and it is rebuilt on restart (main.go:135-152), so a changed strategy applies exactly likesubJsonRulesdoes today — after the panel restarts, not on the next subscription fetch.This workflow only investigates and replies, so nothing here has been committed; the snippets are written to be applied as-is.