[GH-ISSUE #4850] [Feature]: Add panel settings to customize DNS, queryStrategy, and domainStrategy for generated client subscription configs #3380

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

Originally created by @rusik-afk on GitHub (Jun 3, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/4850

Yes. As discussed in issue #4848, the client subscription JSON config endpoint (/sub/json/<subId>) currently relies on a hardcoded embedded template (sub/default.json).

Because of this, parameters like dns.servers (Google DNS), dns.queryStrategy (UseIP), and routing.domainStrategy (AsIs) are hardcoded for all clients. Administrators cannot enforce privacy-centric DNS (e.g., Cloudflare) or specific routing strategies globally from the panel. This requires manually instructing every end-user to configure these parameters inside their respective client applications (Hiddify, Happ, etc.), which is inefficient and error-prone for non-technical users.

Describe the solution you'd like

I would like the panel to expose new configuration fields in Panel Settings -> Subscription Settings -> JSON Settings (similar to how subJsonRules or subJsonFragment currently work).

Ideally, add the following setting keys to the UI:

  • subJsonDNSServers: To override the default "8.8.8.8" with custom upstream DNS arrays.
  • subJsonDNSQueryStrategy: A dropdown or string field to override "UseIP" (e.g., with "UseIPv4").
  • subJsonDomainStrategy: A dropdown or string field to override "AsIs" (e.g., with "IPIfNonMatch").

When generating the subscription via the /sub/json/ endpoint, the panel should check these fields and inject them into the client config instead of using the hardcoded values from sub/default.json.

Alternatives you've considered

  1. Manually configuring every single client device: Does not scale well when managing nodes for a group of friends or clients.
  2. Building the panel from source after patching sub/default.json: This works but creates immense maintenance overhead, as every official panel update forces a manual re-compile of the binary.

Concrete use case

I manage a server providing Xray access to a close group of friends/clients. I need all generated configs to seamlessly use Cloudflare DNS (1.1.1.1), utilize the IPIfNonMatch domain strategy, and strictly enforce the UseIPv4 query/domain strategy to prevent connection issues caused by unstable IPv6 routing, DNS leaks, or geofence blocks. Having this exposed in the Web UI would allow me to manage this centrally and instantly update all clients upon subscription renewal.

Mockups, screenshots, or examples

Please refer to the discussion and hardcoded values table provided by the bot/maintainers in my previous issue: #4848

Which parts of the panel would this affect?

Subscription (share links / Clash / JSON)

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 @rusik-afk on GitHub (Jun 3, 2026). Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/4850 ### Is your feature request related to a problem? Yes. As discussed in issue #4848, the client subscription JSON config endpoint (`/sub/json/<subId>`) currently relies on a hardcoded embedded template (`sub/default.json`). Because of this, parameters like `dns.servers` (Google DNS), `dns.queryStrategy` (`UseIP`), and `routing.domainStrategy` (`AsIs`) are hardcoded for all clients. Administrators cannot enforce privacy-centric DNS (e.g., Cloudflare) or specific routing strategies globally from the panel. This requires manually instructing every end-user to configure these parameters inside their respective client applications (Hiddify, Happ, etc.), which is inefficient and error-prone for non-technical users. ### Describe the solution you'd like I would like the panel to expose new configuration fields in **Panel Settings -> Subscription Settings -> JSON Settings** (similar to how `subJsonRules` or `subJsonFragment` currently work). Ideally, add the following setting keys to the UI: - `subJsonDNSServers`: To override the default `"8.8.8.8"` with custom upstream DNS arrays. - `subJsonDNSQueryStrategy`: A dropdown or string field to override `"UseIP"` (e.g., with `"UseIPv4"`). - `subJsonDomainStrategy`: A dropdown or string field to override `"AsIs"` (e.g., with `"IPIfNonMatch"`). When generating the subscription via the `/sub/json/` endpoint, the panel should check these fields and inject them into the client config instead of using the hardcoded values from `sub/default.json`. ### Alternatives you've considered 1. Manually configuring every single client device: Does not scale well when managing nodes for a group of friends or clients. 2. Building the panel from source after patching `sub/default.json`: This works but creates immense maintenance overhead, as every official panel update forces a manual re-compile of the binary. ### Concrete use case I manage a server providing Xray access to a close group of friends/clients. I need all generated configs to seamlessly use Cloudflare DNS (`1.1.1.1`), utilize the `IPIfNonMatch` domain strategy, and strictly enforce the `UseIPv4` query/domain strategy to prevent connection issues caused by unstable IPv6 routing, DNS leaks, or geofence blocks. Having this exposed in the Web UI would allow me to manage this centrally and instantly update all clients upon subscription renewal. ### Mockups, screenshots, or examples Please refer to the discussion and hardcoded values table provided by the bot/maintainers in my previous issue: #4848 ### Which parts of the panel would this affect? Subscription (share links / Clash / JSON) ### 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 (Jun 3, 2026):

Thanks for the detailed and well-researched request. Your analysis is correct — the values you want to control are indeed hardcoded in the embedded template today.

What the code currently does

sub/default.json is the template that sub/subJsonService.go unmarshals at startup (//go:embed default.json). It contains these hardcoded values:

Field Location in JSON Hardcoded value
DNS query strategy dns.queryStrategy "UseIP"
DNS servers dns.servers[0].address "8.8.8.8"
Routing domain strategy routing.domainStrategy "AsIs"
Freedom outbound domain strategy outbounds[0].settings.domainStrategy "AsIs"

The only runtime overrides NewSubJsonService currently applies to these fields are: when fragment or noises is set, the freedom outbound's domainStrategy is overridden to "UseIP" (see subJsonService.go:47). There is no path today to override dns.servers, dns.queryStrategy, or routing.domainStrategy from panel settings.

The existing pattern to follow

The subJsonRules setting is the closest precedent. Here's how it flows end-to-end:

  1. web/service/setting.go — default "subJsonRules": "" + GetSubJsonRules() getter
  2. web/entity/entity.go AllSetting struct — SubJsonRules string field
  3. sub/sub.go — fetches SubJsonRules and passes it to NewSUBController
  4. sub/subController.go NewSUBController — forwards it to NewSubJsonService
  5. sub/subJsonService.go NewSubJsonService — unmarshals and prepends the rules into configJson["routing"]["rules"]

Adding the three new settings would require the same changes across all five files, plus a frontend form in the Panel Settings → Subscription Settings → JSON Settings section.

Specific code points for a PR

  • sub/subJsonService.go:33 — NewSubJsonService signature and the init block; add new params and apply them to configJson["dns"] and configJson["routing"] after json.Unmarshal.
  • sub/subController.go:54 — NewSUBController signature.
  • sub/sub.go:123–141 — where SubJsonFragment, SubJsonNoises, etc. are fetched; add analogous calls for the new getters.
  • web/service/setting.go:59–85 — defaults map; add e.g. "subJsonDNSServers": "", "subJsonDNSQueryStrategy": "", "subJsonDomainStrategy": "".
  • web/entity/entity.go:86–89 — AllSetting struct; add the three new fields.

One subtlety: dns.servers is a JSON array of objects (not a plain string), so the setting value would need to be stored as a JSON string and unmarshaled before being injected — the same approach used for subJsonRules and subJsonFragment.

If you'd like to open a PR, the five files above plus the React frontend component for the settings form are all that need to change.

<!-- gh-comment-id:4610885746 --> @github-actions[bot] commented on GitHub (Jun 3, 2026): Thanks for the detailed and well-researched request. Your analysis is correct — the values you want to control are indeed hardcoded in the embedded template today. ## What the code currently does `sub/default.json` is the template that `sub/subJsonService.go` unmarshals at startup (`//go:embed default.json`). It contains these hardcoded values: | Field | Location in JSON | Hardcoded value | |---|---|---| | DNS query strategy | `dns.queryStrategy` | `"UseIP"` | | DNS servers | `dns.servers[0].address` | `"8.8.8.8"` | | Routing domain strategy | `routing.domainStrategy` | `"AsIs"` | | Freedom outbound domain strategy | `outbounds[0].settings.domainStrategy` | `"AsIs"` | The only runtime overrides `NewSubJsonService` currently applies to these fields are: when `fragment` or `noises` is set, the freedom outbound's `domainStrategy` is overridden to `"UseIP"` (see `subJsonService.go:47`). There is no path today to override `dns.servers`, `dns.queryStrategy`, or `routing.domainStrategy` from panel settings. ## The existing pattern to follow The `subJsonRules` setting is the closest precedent. Here's how it flows end-to-end: 1. **`web/service/setting.go`** — default `"subJsonRules": ""` + `GetSubJsonRules()` getter 2. **`web/entity/entity.go`** `AllSetting` struct — `SubJsonRules string` field 3. **`sub/sub.go`** — fetches `SubJsonRules` and passes it to `NewSUBController` 4. **`sub/subController.go`** `NewSUBController` — forwards it to `NewSubJsonService` 5. **`sub/subJsonService.go`** `NewSubJsonService` — unmarshals and prepends the rules into `configJson["routing"]["rules"]` Adding the three new settings would require the same changes across all five files, plus a frontend form in the Panel Settings → Subscription Settings → JSON Settings section. ## Specific code points for a PR - **`sub/subJsonService.go:33`** — `NewSubJsonService` signature and the init block; add new params and apply them to `configJson["dns"]` and `configJson["routing"]` after `json.Unmarshal`. - **`sub/subController.go:54`** — `NewSUBController` signature. - **`sub/sub.go:123–141`** — where `SubJsonFragment`, `SubJsonNoises`, etc. are fetched; add analogous calls for the new getters. - **`web/service/setting.go:59–85`** — defaults map; add e.g. `"subJsonDNSServers": ""`, `"subJsonDNSQueryStrategy": ""`, `"subJsonDomainStrategy": ""`. - **`web/entity/entity.go:86–89`** — `AllSetting` struct; add the three new fields. One subtlety: `dns.servers` is a JSON array of objects (not a plain string), so the setting value would need to be stored as a JSON string and unmarshaled before being injected — the same approach used for `subJsonRules` and `subJsonFragment`. If you'd like to open a PR, the five files above plus the React frontend component for the settings form are all that need to change.
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#3380
No description provided.