[GH-ISSUE #6342] [Feature]: Expose subJsonRules as raw JSON and allow customizable subscription DNS #4305

Open
opened 2026-10-31 20:38:41 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @Thedrezik on GitHub (Aug 27, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/6342

I'm always frustrated when trying to distribute advanced routing rules to my clients via the subscription link due to two hardcoded limitations:

  1. Hardcoded DNS: The subscription JSON generation hardcodes 8.8.8.8 as the DNS server for clients. Currently, the only way to change this is to manually patch the binary using sed -i 's/8.8.8.8/1.1.1.1/g' /usr/local/x-ui/x-ui.
  2. Overwritten Routing Rules: I need to pass complex routing structures to the clients (e.g., blocking udp/443 to force HTTP/2 over TCP for XTLS-Vision stability, blocking bittorrent, 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 (subJsonRules key), 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

  1. Custom DNS Input: Add an input field in the Web UI (Panel Settings -> Subscription) to define the default DNS servers for the generated client config, replacing the hardcoded 8.8.8.8.
  2. Raw JSON Input for subJsonRules: Add a raw text area for subJsonRules in the Subscription settings page, exactly like the existing xrayTemplateConfig text 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

  1. Using the Web UI tags (comma-separated domains) — this works for basic domains but fails if I need to pass specific network parameters, ports, or protocols (like blocking bittorrent or udp/443).
  2. Injecting raw JSON directly into the SQLite database (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.
  3. For the DNS issue, I'm currently using a sed command to patch the compiled binary to replace 8.8.8.8 with 1.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:

  1. Add a simple text input field: Default Subscription DNS (defaulting to 8.8.8.8).
  2. Add a large textarea: subJsonRules Raw Config (visually identical to the existing xrayTemplateConfig textarea). 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?

  • I'd like to implement this feature myself and open a PR.
  • I can help test once a PR is open.

Before submitting

  • I searched existing issues and this feature has not been requested.
  • This feature request is written in English.
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: 1. **Hardcoded DNS:** The subscription JSON generation hardcodes `8.8.8.8` as the DNS server for clients. Currently, the only way to change this is to manually patch the binary using `sed -i 's/8.8.8.8/1.1.1.1/g' /usr/local/x-ui/x-ui`. 2. **Overwritten Routing Rules:** I need to pass complex routing structures to the clients (e.g., blocking `udp/443` to force HTTP/2 over TCP for XTLS-Vision stability, blocking `bittorrent`, 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 (`subJsonRules` key), 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 1. **Custom DNS Input:** Add an input field in the Web UI (Panel Settings -> Subscription) to define the default DNS servers for the generated client config, replacing the hardcoded `8.8.8.8`. 2. **Raw JSON Input for subJsonRules:** Add a raw text area for `subJsonRules` in the Subscription settings page, exactly like the existing `xrayTemplateConfig` text 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 1. Using the Web UI tags (comma-separated domains) — this works for basic domains but fails if I need to pass specific network parameters, ports, or protocols (like blocking `bittorrent` or `udp/443`). 2. Injecting raw JSON directly into the SQLite database (`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. 3. For the DNS issue, I'm currently using a `sed` command to patch the compiled binary to replace `8.8.8.8` with `1.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: 1. Add a simple text input field: `Default Subscription DNS` (defaulting to 8.8.8.8). 2. Add a large textarea: `subJsonRules Raw Config` (visually identical to the existing `xrayTemplateConfig` textarea). 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? - [ ] I'd like to implement this feature myself and open a PR. - [x] I can help test once a PR is open. ### Before submitting - [x] I searched [existing issues](../issues?q=is%3Aissue) and this feature has not been requested. - [x] This feature request is written in English.
Author
Owner

@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 for subJsonRules is new, so I'm leaving this open.

1. The subscription DNS really is hardcoded

internal/sub/default.json is embedded at build time (internal/sub/json_service.go:22-23):

//go:embed default.json
var defaultJson string

and its DNS block is copied verbatim into every generated client config — nothing in NewSubJsonService or GetJson ever touches configJson["dns"]:

"dns": {
  "tag": "dns_out",
  "queryStrategy": "UseIP",
  "servers": [
    { "address": "8.8.8.8", "skipFallback": false }
  ]
}

(internal/sub/default.json:3-12)

There is no subJsonDNS* key in the settings default map — "subJsonRules": "" at internal/web/service/setting.go:119 is the only routing-related one — so there is no supported override today, and your sed observation is accurate. That is exactly what #4850 asks for (subJsonDNSServers / subJsonDNSQueryStrategy / subJsonDomainStrategy); it is open and labelled backlog.

2. subJsonRules already accepts arbitrary raw JSON — the backend never sanitizes it

The setting is unmarshalled as an untyped array and prepended to routing.rules:

if rules != "" {
	var newRules []any
	routing, _ := configJson["routing"].(map[string]any)
	defaultRules, _ := routing["rules"].([]any)
	_ = json.Unmarshal([]byte(rules), &newRules)
	defaultRules = append(newRules, defaultRules...)
	routing["rules"] = defaultRules
	configJson["routing"] = routing
}

(internal/sub/json_service.go:48-56)

[]any means every Xray rule field — network, port, protocol, ip, domain, outboundTag — passes through untouched, and TestSubJsonService_CustomRulesPrepended (internal/sub/mutation_audit_test.go:30-47) pins that with an "outboundTag":"block" rule. The block (blackhole) outbound ships in every generated config (internal/sub/default.json:55-63), so the rules you want are already expressible:

[
  {"type":"field","outboundTag":"block","network":"udp","port":"443"},
  {"type":"field","outboundTag":"block","protocol":["bittorrent"]},
  {"type":"field","outboundTag":"direct","domain":["domain:example.ir"]}
]

Storage is verbatim on both sides: SubJsonRules is a plain string field (internal/web/entity/entity.go:106), written with value := fmt.Sprint(fieldV.Interface()) (internal/web/service/setting.go:1230) and read back with fieldV.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), and ObjectUtil.cloneProps copies subJsonRules as 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:

  • The switch is "on" whenever the string is non-empty — 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.
  • Clearing the IPs select drops every rule carrying an ip key — rules = rules.filter((r) => !r.ip); (line 119) — and the domains select does the same for domain (line 137).
  • The selects only ever read the first rule with 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)

sed on 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/update binds 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):

# 1. read current settings (needs a session cookie or an API token)
curl -s -X POST https://<panel>/<basePath>/panel/api/setting/all -b cookies.txt \
  | jq '.obj' > all.json

# 2. replace only subJsonRules with the contents of rules.json
jq --rawfile r rules.json '.subJsonRules = $r' all.json > payload.json

# 3. post the FULL object back
curl -s -X POST https://<panel>/<basePath>/panel/api/setting/update -b cookies.txt \
  -H 'Content-Type: application/json' --data @payload.json

Then restart the panel. The subscription server reads subJsonRules once while its router is built (internal/sub/sub.go:148, inside initRouter) 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.

  • #4850 — custom DNS / queryStrategy / domainStrategy for the JSON subscription. Same as your point 1; open, backlog.
  • #6072 — a block toggle and a domainStrategy dropdown in this same tab.
  • #5824 — per-inbound routing rules injected into the JSON subscription.

None of them proposes a raw subJsonRules editor, so this is not a duplicate and stays open. Keeping the enhancement label as filed.

Verdict: Feature request

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

<!-- gh-comment-id:5444415877 --> @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 for `subJsonRules` is new, so I'm leaving this open. ## 1. The subscription DNS really is hardcoded `internal/sub/default.json` is embedded at build time (`internal/sub/json_service.go:22-23`): ```go //go:embed default.json var defaultJson string ``` and its DNS block is copied verbatim into every generated client config — nothing in `NewSubJsonService` or `GetJson` ever touches `configJson["dns"]`: ```json "dns": { "tag": "dns_out", "queryStrategy": "UseIP", "servers": [ { "address": "8.8.8.8", "skipFallback": false } ] } ``` (`internal/sub/default.json:3-12`) There is no `subJsonDNS*` key in the settings default map — `"subJsonRules": ""` at `internal/web/service/setting.go:119` is the only routing-related one — so there is no supported override today, and your `sed` observation is accurate. That is exactly what #4850 asks for (`subJsonDNSServers` / `subJsonDNSQueryStrategy` / `subJsonDomainStrategy`); it is open and labelled `backlog`. ## 2. `subJsonRules` already accepts arbitrary raw JSON — the backend never sanitizes it The setting is unmarshalled as an untyped array and prepended to `routing.rules`: ```go if rules != "" { var newRules []any routing, _ := configJson["routing"].(map[string]any) defaultRules, _ := routing["rules"].([]any) _ = json.Unmarshal([]byte(rules), &newRules) defaultRules = append(newRules, defaultRules...) routing["rules"] = defaultRules configJson["routing"] = routing } ``` (`internal/sub/json_service.go:48-56`) `[]any` means every Xray rule field — `network`, `port`, `protocol`, `ip`, `domain`, `outboundTag` — passes through untouched, and `TestSubJsonService_CustomRulesPrepended` (`internal/sub/mutation_audit_test.go:30-47`) pins that with an `"outboundTag":"block"` rule. The `block` (blackhole) outbound ships in every generated config (`internal/sub/default.json:55-63`), so the rules you want are already expressible: ```json [ {"type":"field","outboundTag":"block","network":"udp","port":"443"}, {"type":"field","outboundTag":"block","protocol":["bittorrent"]}, {"type":"field","outboundTag":"direct","domain":["domain:example.ir"]} ] ``` Storage is verbatim on both sides: `SubJsonRules` is a plain `string` field (`internal/web/entity/entity.go:106`), written with `value := fmt.Sprint(fieldV.Interface())` (`internal/web/service/setting.go:1230`) and read back with `fieldV.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`), and `ObjectUtil.cloneProps` copies `subJsonRules` as 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`: - The switch is "on" whenever the string is non-empty — `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. - Clearing the IPs select drops **every** rule carrying an `ip` key — `rules = rules.filter((r) => !r.ip);` (line 119) — and the domains select does the same for `domain` (line 137). - The selects only ever read the *first* rule with `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) `sed` on 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/update` binds 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`): ```bash # 1. read current settings (needs a session cookie or an API token) curl -s -X POST https://<panel>/<basePath>/panel/api/setting/all -b cookies.txt \ | jq '.obj' > all.json # 2. replace only subJsonRules with the contents of rules.json jq --rawfile r rules.json '.subJsonRules = $r' all.json > payload.json # 3. post the FULL object back curl -s -X POST https://<panel>/<basePath>/panel/api/setting/update -b cookies.txt \ -H 'Content-Type: application/json' --data @payload.json ``` Then restart the panel. The subscription server reads `subJsonRules` once while its router is built (`internal/sub/sub.go:148`, inside `initRouter`) 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 - #4850 — custom DNS / `queryStrategy` / `domainStrategy` for the JSON subscription. Same as your point 1; open, `backlog`. - #6072 — a `block` toggle and a `domainStrategy` dropdown in this same tab. - #5824 — per-inbound routing rules injected into the JSON subscription. None of them proposes a raw `subJsonRules` editor, so this is not a duplicate and stays open. Keeping the `enhancement` label as filed. Verdict: Feature request *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#4305
No description provided.