[PR #6923] [MERGED] feat(sub): support multiple SNIs with randomized per-config and shared selection #6524

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

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/6923
Author: @Pejman-Yousefi-Official
Created: 10/24/2026
Status: ✅ Merged
Merged: 10/24/2026
Merged by: @MHSanaei

Base: main ← Head: feat/multi-sni


📝 Commits (5)

  • 443f1c4 feat(sub): support multiple SNIs with randomized per-config and shared selection
  • cb0b349 fix(sub): address PR review findings on host security, REST SNI sync, and tests
  • 4f82b02 Merge remote-tracking branch 'origin/main' into pr/6923
  • bc93dfd refactor(hosts): one shared-SNI switch for a multi-SNI pool
  • 1a9ee84 Merge remote-tracking branch 'origin/main' into pr/6923

📊 Changes

33 files changed (+675 additions, -13 deletions)

View changed files

📝 docs/public/openapi.json (+49 -0)
📝 frontend/public/openapi.json (+49 -0)
📝 frontend/src/generated/examples.ts (+8 -0)
📝 frontend/src/generated/schemas.ts (+21 -0)
📝 frontend/src/generated/types.ts (+4 -0)
📝 frontend/src/generated/zod.ts (+4 -0)
📝 frontend/src/lib/hosts/host-link.ts (+17 -2)
📝 frontend/src/pages/hosts/HostFormModal.tsx (+57 -4)
📝 frontend/src/schemas/api/host.ts (+4 -0)
📝 frontend/src/test/host-link.test.ts (+95 -1)
📝 internal/database/db.go (+1 -0)
📝 internal/database/model/model.go (+2 -0)
📝 internal/sub/host_order.go (+1 -1)
📝 internal/sub/host_sub.go (+52 -4)
📝 internal/sub/host_sub_test.go (+170 -0)
📝 internal/sub/service.go (+2 -0)
📝 internal/web/entity/entity.go (+2 -0)
📝 internal/web/service/host.go (+47 -1)
📝 internal/web/service/host_test.go (+76 -0)
📝 internal/web/translation/ar-EG.json (+1 -0)

...and 13 more files

📄 Description

Summary

Add support for configuring multiple Server Name Indication (SNI) domains for Host entries in Security settings. When multiple SNIs are specified, operators can choose between two mutually exclusive randomization modes:

  • Randomize per config (sniRandomizePerConfig, default): Each generated subscription endpoint / config receives an independently chosen random SNI from the pool on every fetch.
  • Shared random SNI (sniSharedRandom): A single random SNI is selected from the pool and applied consistently across all endpoints and expanded CIDR addresses in that host group for that subscription fetch, re-randomized on subsequent fetches.

Why

Operators and reverse-proxy frontends frequently rely on multiple SNI domains to distribute TLS fingerprints, balance traffic across CDN edge domains, and enhance censorship resistance against domain-specific SNI blocking. Previously, Host entries only accepted a single static SNI, requiring operators to duplicate host entries and configuration groups to use multiple SNIs. Supporting multi-SNI tags with configurable per-config or shared randomization allows dynamic domain rotation across client subscriptions without database or UI bloat.

Type of change

  • New feature
  • Bug fix
  • 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?

  • Unit tests:

    • Added internal/sub/host_sub_test.go covering TestSub_HostMultiSNI_RandomizePerConfig, TestSub_HostMultiSNI_SharedRandom, and TestSub_HostMultiSNI_Overrides.
    • Added internal/web/service/host_test.go covering TestHostGroup_MultiSNIRoundTrip and validation of mutual exclusivity enforcement.
    • Added frontend/src/test/host-link.test.ts asserting multi-SNI per-config and shared random resolution in client link generators.
    • All repository tests pass locally: go test ./internal/sub/... ./internal/web/service/... and npm test.
  • Manual verification:

    1. Opened the Hosts modal in the panel and navigated to the Security tab.
    2. Input single SNI (example.com) — confirmed randomization switches remain hidden to avoid UI clutter.
    3. Input multiple SNIs (domain1.com, domain2.com) — confirmed both switches dynamically appear with smooth animation, defaulting to "Randomize per config".
    4. Verified mutual exclusivity: toggling one switch automatically deactivates the other; unchecking the active switch falls back cleanly.
    5. Tested subscription endpoints (/sub/... raw share links, Clash YAML proxies, and Xray JSON outbounds):
      • Under per-config mode: verified configs receive distributed random SNIs across the defined pool.
      • Under shared mode: verified all endpoints within the host group share the exact same randomly picked SNI for that fetch, and re-fetch yields fresh random selections.
    6. Verified OpenAPI spec synchronization (tools/openapigen, npm run gen:api, and docs/public/openapi.json).
    7. Verified all 14 locale translation dictionaries (internal/web/translation/*.json).
    8. Verified frontend code quality: npm run lint, npm run typecheck, and npm run build pass with 0 errors.

Breaking changes

None. Existing database records retain their single sni field, and the new snis JSON column seamlessly defaults to empty/single SNI. Hosts with <= 1 SNI retain identical legacy behavior.

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.

🔄 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/6923 **Author:** [@Pejman-Yousefi-Official](https://github.com/Pejman-Yousefi-Official) **Created:** 10/24/2026 **Status:** ✅ Merged **Merged:** 10/24/2026 **Merged by:** [@MHSanaei](https://github.com/MHSanaei) **Base:** `main` ← **Head:** `feat/multi-sni` --- ### 📝 Commits (5) - [`443f1c4`](https://github.com/MHSanaei/3x-ui/commit/443f1c4a2f169f724affef968802447efac91ce0) feat(sub): support multiple SNIs with randomized per-config and shared selection - [`cb0b349`](https://github.com/MHSanaei/3x-ui/commit/cb0b349b52b910eb1d2b0f4a98fb3e85654705f0) fix(sub): address PR review findings on host security, REST SNI sync, and tests - [`4f82b02`](https://github.com/MHSanaei/3x-ui/commit/4f82b023eacb5f2bf6235389cb72125189aeb203) Merge remote-tracking branch 'origin/main' into pr/6923 - [`bc93dfd`](https://github.com/MHSanaei/3x-ui/commit/bc93dfd330eb71a1f71bb0bd8542d6e58e7f54bb) refactor(hosts): one shared-SNI switch for a multi-SNI pool - [`1a9ee84`](https://github.com/MHSanaei/3x-ui/commit/1a9ee845e75fcf2419f545b6840764ac299595a0) Merge remote-tracking branch 'origin/main' into pr/6923 ### 📊 Changes **33 files changed** (+675 additions, -13 deletions) <details> <summary>View changed files</summary> 📝 `docs/public/openapi.json` (+49 -0) 📝 `frontend/public/openapi.json` (+49 -0) 📝 `frontend/src/generated/examples.ts` (+8 -0) 📝 `frontend/src/generated/schemas.ts` (+21 -0) 📝 `frontend/src/generated/types.ts` (+4 -0) 📝 `frontend/src/generated/zod.ts` (+4 -0) 📝 `frontend/src/lib/hosts/host-link.ts` (+17 -2) 📝 `frontend/src/pages/hosts/HostFormModal.tsx` (+57 -4) 📝 `frontend/src/schemas/api/host.ts` (+4 -0) 📝 `frontend/src/test/host-link.test.ts` (+95 -1) 📝 `internal/database/db.go` (+1 -0) 📝 `internal/database/model/model.go` (+2 -0) 📝 `internal/sub/host_order.go` (+1 -1) 📝 `internal/sub/host_sub.go` (+52 -4) 📝 `internal/sub/host_sub_test.go` (+170 -0) 📝 `internal/sub/service.go` (+2 -0) 📝 `internal/web/entity/entity.go` (+2 -0) 📝 `internal/web/service/host.go` (+47 -1) 📝 `internal/web/service/host_test.go` (+76 -0) 📝 `internal/web/translation/ar-EG.json` (+1 -0) _...and 13 more files_ </details> ### 📄 Description ## Summary Add support for configuring multiple Server Name Indication (SNI) domains for Host entries in Security settings. When multiple SNIs are specified, operators can choose between two mutually exclusive randomization modes: - **Randomize per config** (`sniRandomizePerConfig`, default): Each generated subscription endpoint / config receives an independently chosen random SNI from the pool on every fetch. - **Shared random SNI** (`sniSharedRandom`): A single random SNI is selected from the pool and applied consistently across all endpoints and expanded CIDR addresses in that host group for that subscription fetch, re-randomized on subsequent fetches. ## Why Operators and reverse-proxy frontends frequently rely on multiple SNI domains to distribute TLS fingerprints, balance traffic across CDN edge domains, and enhance censorship resistance against domain-specific SNI blocking. Previously, Host entries only accepted a single static SNI, requiring operators to duplicate host entries and configuration groups to use multiple SNIs. Supporting multi-SNI tags with configurable per-config or shared randomization allows dynamic domain rotation across client subscriptions without database or UI bloat. ## Type of change - [x] New feature - [ ] Bug fix - [ ] 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? - **Unit tests:** - Added `internal/sub/host_sub_test.go` covering `TestSub_HostMultiSNI_RandomizePerConfig`, `TestSub_HostMultiSNI_SharedRandom`, and `TestSub_HostMultiSNI_Overrides`. - Added `internal/web/service/host_test.go` covering `TestHostGroup_MultiSNIRoundTrip` and validation of mutual exclusivity enforcement. - Added `frontend/src/test/host-link.test.ts` asserting multi-SNI per-config and shared random resolution in client link generators. - All repository tests pass locally: `go test ./internal/sub/... ./internal/web/service/...` and `npm test`. - **Manual verification:** 1. Opened the **Hosts** modal in the panel and navigated to the **Security** tab. 2. Input single SNI (`example.com`) — confirmed randomization switches remain hidden to avoid UI clutter. 3. Input multiple SNIs (`domain1.com`, `domain2.com`) — confirmed both switches dynamically appear with smooth animation, defaulting to "Randomize per config". 4. Verified mutual exclusivity: toggling one switch automatically deactivates the other; unchecking the active switch falls back cleanly. 5. Tested subscription endpoints (`/sub/...` raw share links, Clash YAML proxies, and Xray JSON outbounds): - Under per-config mode: verified configs receive distributed random SNIs across the defined pool. - Under shared mode: verified all endpoints within the host group share the exact same randomly picked SNI for that fetch, and re-fetch yields fresh random selections. 6. Verified OpenAPI spec synchronization (`tools/openapigen`, `npm run gen:api`, and `docs/public/openapi.json`). 7. Verified all 14 locale translation dictionaries (`internal/web/translation/*.json`). 8. Verified frontend code quality: `npm run lint`, `npm run typecheck`, and `npm run build` pass with 0 errors. ## Breaking changes None. Existing database records retain their single `sni` field, and the new `snis` JSON column seamlessly defaults to empty/single SNI. Hosts with <= 1 SNI retain identical legacy behavior. ## 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. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 04:09:22 +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#6524
No description provided.