mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[GH-ISSUE #6342] [Feature]: Expose subJsonRules as raw JSON and allow customizable subscription DNS #4305
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#4305
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 @Thedrezik on GitHub (Aug 27, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/6342
Is your feature request related to a problem?
I'm always frustrated when trying to distribute advanced routing rules to my clients via the subscription link due to two hardcoded limitations:
8.8.8.8as the DNS server for clients. Currently, the only way to change this is to manually patch the binary usingsed -i 's/8.8.8.8/1.1.1.1/g' /usr/local/x-ui/x-ui.udp/443to force HTTP/2 over TCP for XTLS-Vision stability, blockingbittorrent, and routing custom domain arrays). The current Web UI only supports simple string tags. If I manually inject a complex JSON array into the SQLite database (subJsonRuleskey), the Web UI completely overwrites and deletes my advanced rules the next time I click "Save" in the Panel Settings.Describe the solution you'd like
8.8.8.8.subJsonRulesin the Subscription settings page, exactly like the existingxrayTemplateConfigtext area. This would allow advanced users to inject complete, complex JSON routing arrays directly into the database without the UI parsing logic breaking or resetting them upon saving.Alternatives you've considered
bittorrentorudp/443).x-ui.db) using the CLI. This works temporarily, but as soon as any setting is changed and saved via the Web UI, the custom JSON is overwritten and deleted.sedcommand to patch the compiled binary to replace8.8.8.8with1.1.1.1, which is highly unideal and breaks on every panel update.Concrete use case
I manage a server for several non-technical users using clients like v2rayNG and NekoBox. I use XTLS-Vision, which requires UDP/443 (QUIC) to be blocked on the client side for maximum stability and to bypass ISP throttling. I also need to route a specific list of 50+ regional domains directly and block torrents locally.
Asking non-technical users to manually configure their client routing rules is impossible. Pushing these complex rules and a custom reliable DNS (e.g., 1.1.1.1) directly through the subscription link ensures all users have the correct and optimal setup automatically without any manual intervention.
Mockups, screenshots, or examples
In Panel Settings -> Subscription tab:
Default Subscription DNS(defaulting to 8.8.8.8).subJsonRules Raw Config(visually identical to the existingxrayTemplateConfigtextarea). This textarea should allow saving raw JSON arrays directly to the database without the UI sanitizing or overwriting it with simple string tags.Which parts of the panel would this affect?
Frontend (UI / panel pages)
Are you willing to help?
Before submitting
@github-actions[bot] commented on GitHub (Aug 27, 2026):
Both limitations are real and I confirmed them in the source — with one correction: a plain Save does not wipe
subJsonRules; only the "Direct Connection" controls do. The DNS half of your request is already tracked as an accepted request (#4850); the raw-JSON editor forsubJsonRulesis new, so I'm leaving this open.1. The subscription DNS really is hardcoded
internal/sub/default.jsonis embedded at build time (internal/sub/json_service.go:22-23):and its DNS block is copied verbatim into every generated client config — nothing in
NewSubJsonServiceorGetJsonever touchesconfigJson["dns"]:(
internal/sub/default.json:3-12)There is no
subJsonDNS*key in the settings default map —"subJsonRules": ""atinternal/web/service/setting.go:119is the only routing-related one — so there is no supported override today, and yoursedobservation is accurate. That is exactly what #4850 asks for (subJsonDNSServers/subJsonDNSQueryStrategy/subJsonDomainStrategy); it is open and labelledbacklog.2.
subJsonRulesalready accepts arbitrary raw JSON — the backend never sanitizes itThe setting is unmarshalled as an untyped array and prepended to
routing.rules:(
internal/sub/json_service.go:48-56)[]anymeans every Xray rule field —network,port,protocol,ip,domain,outboundTag— passes through untouched, andTestSubJsonService_CustomRulesPrepended(internal/sub/mutation_audit_test.go:30-47) pins that with an"outboundTag":"block"rule. Theblock(blackhole) outbound ships in every generated config (internal/sub/default.json:55-63), so the rules you want are already expressible:Storage is verbatim on both sides:
SubJsonRulesis a plainstringfield (internal/web/entity/entity.go:106), written withvalue := fmt.Sprint(fieldV.Interface())(internal/web/service/setting.go:1230) and read back withfieldV.SetString(value)(internal/web/service/setting.go:236). No validation, no normalization.3. What actually deletes your rules
Not the Save button.
saveAll()posts the whole settings object back exactly as it was read (frontend/src/api/queries/useAllSettings.ts:84-87), andObjectUtil.clonePropscopiessubJsonRulesas an opaque string (frontend/src/utils/index.ts:383-393). So if you never open Settings → Subscription → Direct Connection, saving other settings round-trips your JSON unchanged. (I can't run the panel here — that is read from the code path, not observed.)The three controls on that one tab are what rewrite it, all in
frontend/src/pages/settings/SubscriptionFormatsTab.tsx:const directEnabled = allSetting.subJsonRules !== '';(line 77) — so your custom rules make it look enabled. Toggling it off and on replaces everything:updateSetting({ subJsonRules: v ? JSON.stringify(DEFAULT_RULES) : '' });(line 112). That is the total wipe you saw.ipkey —rules = rules.filter((r) => !r.ip);(line 119) — and the domains select does the same fordomain(line 137).ip/domain(lines 101 and 107), so a 50-domain, multi-rule set is invisible in the UI even while it is intact in the database.So the raw textarea you're asking for is a genuine gap, and the backend needs no change to support it.
Workaround today (no binary patching, rules only)
sedon the binary is not needed for the rules half. Either keep editing the DB and simply never touch the Direct Connection tab, or do it through the panel API. Note that/panel/api/setting/updatebinds and replaces the whole settings object (internal/web/controller/setting.go:122-127), so send the full object, not a partial one — blank secret fields are preserved rather than cleared (internal/web/service/setting.go:1291-1321):Then restart the panel. The subscription server reads
subJsonRulesonce while its router is built (internal/sub/sub.go:148, insideinitRouter) and is only rebuilt on restart (main.go:182-184) — saving settings does not reload it.For the DNS half there is no equivalent workaround; no code path reads a setting for it.
Related
queryStrategy/domainStrategyfor the JSON subscription. Same as your point 1; open,backlog.blocktoggle and adomainStrategydropdown in this same tab.None of them proposes a raw
subJsonRuleseditor, so this is not a duplicate and stays open. Keeping theenhancementlabel as filed.Verdict: Feature request
This reply was generated automatically; a maintainer may follow up.