[PR #6620] [MERGED] feat(sub): bind per-client host rule override for subscription SNI #6383

Closed
opened 2026-11-02 04:08:23 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/6620
Author: @NethminaYasas
Created: 9/21/2026
Status: ✅ Merged
Merged: 10/24/2026
Merged by: @MHSanaei

Base: main ← Head: feat(client)--add-per-client-host-rule-binding-for-subscription-generation


📝 Commits (10+)

  • 7a4be7c feat(sub): bind per-client host rule override for subscription SNI
  • 64b7aea style(clients): place host override beside reverse tag at half width
  • ee07347 Merge branch 'main' into feat(client)--add-per-client-host-rule-binding-for-subscription-generation
  • 3b160e4 Merge branch 'main' into feat(client)--add-per-client-host-rule-binding-for-subscription-generation
  • a0d1a72 fix(ci): repair Go test comparison, hosts mock type, and stale codegen
  • bcd5b05 Merge branch 'main' into feat(client)--add-per-client-host-rule-binding-for-subscription-generation
  • e048aa0 Merge remote-tracking branch 'upstream/main' into feat(client)--add-per-client-host-rule-binding-for-subscription-generation
  • 34489c1 fix(sub): scope per-client host bindings to their inbound
  • 8cd08aa fix(i18n): translate the client host rule override field
  • 04c5fab fix(sub): make host-rule tests fail when the endpoint resolver is stubbed

📊 Changes

47 files changed (+1940 additions, -168 deletions)

View changed files

📝 docs/content/docs/en/reference/api/hosts.mdx (+8 -1)
📝 docs/public/openapi.json (+109 -0)
📝 frontend/package.json (+1 -1)
📝 frontend/public/openapi.json (+109 -0)
➕ frontend/src/api/queries/useRawHostsQuery.ts (+51 -0)
📝 frontend/src/api/queryKeys.ts (+1 -0)
📝 frontend/src/generated/examples.ts (+8 -0)
📝 frontend/src/generated/schemas.ts (+21 -0)
📝 frontend/src/generated/types.ts (+2 -0)
📝 frontend/src/generated/zod.ts (+2 -0)
📝 frontend/src/pages/api-docs/endpoints.ts (+8 -0)
📝 frontend/src/pages/clients/ClientFormModal.tsx (+125 -26)
📝 frontend/src/schemas/client.ts (+4 -0)
➕ frontend/src/test/client-host-rule-disabled.test.tsx (+77 -0)
📝 frontend/src/test/happ-routing-editor.test.tsx (+10 -2)
📝 frontend/src/test/setup.components.ts (+5 -3)
📝 internal/database/model/client_renewal_merge_test.go (+28 -1)
📝 internal/database/model/model.go (+155 -79)
📝 internal/database/model/model_test.go (+24 -0)
📝 internal/sub/clash_service.go (+22 -6)

...and 27 more files

📄 Description

Summary

Adds per-client host rule binding: a client can now be linked to one or more host rules, and that client's subscription (raw links, JSON, Clash) renders only the bound hosts' endpoints instead of the inbound-level hosts.

Why

Host rules previously applied globally or per-inbound only, so all clients on an inbound got identical subscription endpoints. This enables per-client overrides (e.g. different SNI/address per client on the same VLESS TCP TLS inbound on port 443) without touching the host rule model itself.

Type of change

  • Bug fix
  • New feature
  • Refactoring (no behavior change)
  • Documentation
  • Tests only
  • Build / CI / tooling
  • Other

Areas affected

  • Frontend (UI / panel pages)
  • Backend (API endpoints, login, settings)
  • Xray config generation
  • Subscription (share links / Clash / JSON)
  • Statistics / traffic counters
  • Database / migrations
  • Install / upgrade script
  • Docker image
  • Multi-node (sub-nodes)
  • Telegram bot

How was this tested?

New tests in internal/sub/host_sub_test.go (all verified to fail with the resolver stubbed out, pass with it):

  • TestSub_ClientHostRule_SingleBinding — bound client renders 1 link with the bound host's ?sni=; unbound client on the same inbound still fans out to every host.
  • TestSub_ClientHostRule_MultipleBindings — client bound to 2 of 3 hosts renders exactly those 2 links.
  • TestSub_ClientHostRule_DeletedFallsBack — binding to a deleted host ID falls back to the inbound rule.
  • TestSub_ClientHostRule_JSONSNI — bound host's SNI/address win in the JSON subscription; unbound host excluded.

Plus full local suites: go test ./internal/sub/ ./internal/web/service/ ./internal/database/... ./internal/web/ and frontend vitest (client modal, hosts, openapi contracts, i18n). Manual check: client add/edit modal → "Host Rule Override" multi-select (populated from GET /panel/api/hosts/raw), save, then fetch /sub/<uuid> and confirm ?sni= reflects the bound rule.

Screenshots / recordings

image

Breaking changes

None. New columns (clients.client_host_rule_id, clients.client_host_rule_ids) are nullable and added via AutoMigrate; clients without a binding render byte-identical subscriptions. New endpoint GET /panel/api/hosts/raw is additive. The multi-id update path is nil-guarded, so API callers that omit the field cannot wipe stored bindings.

Checklist

  • I tested the change locally and confirmed the described behavior.
  • I added or updated tests for the new behavior (when applicable).
  • go build ./... and the test suite pass locally.
  • For frontend changes: npm run lint, npm run typecheck, and npm run build pass.
  • I updated the Wiki / README / API docs if user-facing behavior changed.
  • My commits follow the project's existing message style.
  • I have no unrelated changes mixed into this PR.

Closes #6618


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/MHSanaei/3x-ui/pull/6620 **Author:** [@NethminaYasas](https://github.com/NethminaYasas) **Created:** 9/21/2026 **Status:** ✅ Merged **Merged:** 10/24/2026 **Merged by:** [@MHSanaei](https://github.com/MHSanaei) **Base:** `main` ← **Head:** `feat(client)--add-per-client-host-rule-binding-for-subscription-generation` --- ### 📝 Commits (10+) - [`7a4be7c`](https://github.com/MHSanaei/3x-ui/commit/7a4be7c055f1e18f39f6d0f93df9e11da9b85635) feat(sub): bind per-client host rule override for subscription SNI - [`64b7aea`](https://github.com/MHSanaei/3x-ui/commit/64b7aea47ead7f9df41e0d753238c0392a91e4e5) style(clients): place host override beside reverse tag at half width - [`ee07347`](https://github.com/MHSanaei/3x-ui/commit/ee073478af940dbff19c788abd9be7becc018c6d) Merge branch 'main' into feat(client)--add-per-client-host-rule-binding-for-subscription-generation - [`3b160e4`](https://github.com/MHSanaei/3x-ui/commit/3b160e4a25204954b4ff85907d903d1b21f237a4) Merge branch 'main' into feat(client)--add-per-client-host-rule-binding-for-subscription-generation - [`a0d1a72`](https://github.com/MHSanaei/3x-ui/commit/a0d1a72f7e1cc0c87ffc7a7545dbfbf816d46664) fix(ci): repair Go test comparison, hosts mock type, and stale codegen - [`bcd5b05`](https://github.com/MHSanaei/3x-ui/commit/bcd5b05da6fce3827cf4c9a9bdc7efd039e7a927) Merge branch 'main' into feat(client)--add-per-client-host-rule-binding-for-subscription-generation - [`e048aa0`](https://github.com/MHSanaei/3x-ui/commit/e048aa0c36ec04c72e00545aad2577579626cbda) Merge remote-tracking branch 'upstream/main' into feat(client)--add-per-client-host-rule-binding-for-subscription-generation - [`34489c1`](https://github.com/MHSanaei/3x-ui/commit/34489c137ddd849a720ecce2a6f7caa96f4a3935) fix(sub): scope per-client host bindings to their inbound - [`8cd08aa`](https://github.com/MHSanaei/3x-ui/commit/8cd08aa5fef17d31d0a1389527b1dac2d02edad9) fix(i18n): translate the client host rule override field - [`04c5fab`](https://github.com/MHSanaei/3x-ui/commit/04c5fab504ae263653c0dce3815598020b24d911) fix(sub): make host-rule tests fail when the endpoint resolver is stubbed ### 📊 Changes **47 files changed** (+1940 additions, -168 deletions) <details> <summary>View changed files</summary> 📝 `docs/content/docs/en/reference/api/hosts.mdx` (+8 -1) 📝 `docs/public/openapi.json` (+109 -0) 📝 `frontend/package.json` (+1 -1) 📝 `frontend/public/openapi.json` (+109 -0) ➕ `frontend/src/api/queries/useRawHostsQuery.ts` (+51 -0) 📝 `frontend/src/api/queryKeys.ts` (+1 -0) 📝 `frontend/src/generated/examples.ts` (+8 -0) 📝 `frontend/src/generated/schemas.ts` (+21 -0) 📝 `frontend/src/generated/types.ts` (+2 -0) 📝 `frontend/src/generated/zod.ts` (+2 -0) 📝 `frontend/src/pages/api-docs/endpoints.ts` (+8 -0) 📝 `frontend/src/pages/clients/ClientFormModal.tsx` (+125 -26) 📝 `frontend/src/schemas/client.ts` (+4 -0) ➕ `frontend/src/test/client-host-rule-disabled.test.tsx` (+77 -0) 📝 `frontend/src/test/happ-routing-editor.test.tsx` (+10 -2) 📝 `frontend/src/test/setup.components.ts` (+5 -3) 📝 `internal/database/model/client_renewal_merge_test.go` (+28 -1) 📝 `internal/database/model/model.go` (+155 -79) 📝 `internal/database/model/model_test.go` (+24 -0) 📝 `internal/sub/clash_service.go` (+22 -6) _...and 27 more files_ </details> ### 📄 Description ## Summary Adds per-client host rule binding: a client can now be linked to one or more host rules, and that client's subscription (raw links, JSON, Clash) renders only the bound hosts' endpoints instead of the inbound-level hosts. ## Why Host rules previously applied globally or per-inbound only, so all clients on an inbound got identical subscription endpoints. This enables per-client overrides (e.g. different SNI/address per client on the same VLESS TCP TLS inbound on port 443) without touching the host rule model itself. ## Type of change - [ ] Bug fix - [X] New feature - [ ] Refactoring (no behavior change) - [ ] Documentation - [ ] Tests only - [ ] Build / CI / tooling - [ ] Other ## Areas affected - [X] Frontend (UI / panel pages) - [X] Backend (API endpoints, login, settings) - [ ] Xray config generation - [X] Subscription (share links / Clash / JSON) - [ ] Statistics / traffic counters - [X] Database / migrations - [ ] Install / upgrade script - [ ] Docker image - [ ] Multi-node (sub-nodes) - [ ] Telegram bot ## How was this tested? New tests in `internal/sub/host_sub_test.go` (all verified to fail with the resolver stubbed out, pass with it): - `TestSub_ClientHostRule_SingleBinding` — bound client renders 1 link with the bound host's `?sni=`; unbound client on the same inbound still fans out to every host. - `TestSub_ClientHostRule_MultipleBindings` — client bound to 2 of 3 hosts renders exactly those 2 links. - `TestSub_ClientHostRule_DeletedFallsBack` — binding to a deleted host ID falls back to the inbound rule. - `TestSub_ClientHostRule_JSONSNI` — bound host's SNI/address win in the JSON subscription; unbound host excluded. Plus full local suites: `go test ./internal/sub/ ./internal/web/service/ ./internal/database/... ./internal/web/` and frontend `vitest` (client modal, hosts, openapi contracts, i18n). Manual check: client add/edit modal → "Host Rule Override" multi-select (populated from `GET /panel/api/hosts/raw`), save, then fetch `/sub/<uuid>` and confirm `?sni=` reflects the bound rule. ## Screenshots / recordings <img width="1919" height="1079" alt="image" src="https://github.com/user-attachments/assets/45e0f719-7f78-4c7a-8963-2c095f906e32" /> ## Breaking changes None. New columns (`clients.client_host_rule_id`, `clients.client_host_rule_ids`) are nullable and added via AutoMigrate; clients without a binding render byte-identical subscriptions. New endpoint `GET /panel/api/hosts/raw` is additive. The multi-id update path is nil-guarded, so API callers that omit the field cannot wipe stored bindings. ## Checklist - [X] I tested the change locally and confirmed the described behavior. - [X] I added or updated tests for the new behavior (when applicable). - [X] `go build ./...` and the test suite pass locally. - [X] For frontend changes: `npm run lint`, `npm run typecheck`, and `npm run build` pass. - [X] I updated the Wiki / README / API docs if user-facing behavior changed. - [X] My commits follow the project's existing message style. - [X] I have no unrelated changes mixed into this PR. Closes #6618 --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 04:08:23 +07:00
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#6383
No description provided.