mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[PR #5802] [MERGED] feat(sub): add per-client subscription HWID limits #5991
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#5991
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?
📋 Pull Request Information
Original PR: https://github.com/MHSanaei/3x-ui/pull/5802
Author: @rqzbeh
Created: 7/5/2026
Status: ✅ Merged
Merged: 8/15/2026
Merged by: @MHSanaei
Base:
main← Head:feat/hwid-limits📝 Commits (5)
7b1cb85feat(sub): add per-client subscription HWID limitsf3b598dfix(sub): address HWID review on shared subId and bulk createb80facafix(sub): store HWID devices by sub_id and drop anchor client workaround6243f78fix(sub): restore UA auto-detect and HTML page routing in subs()5cb99c5fix(frontend): drop axios from HttpUtil.delete📊 Changes
45 files changed (+1212 additions, -50 deletions)
View changed files
📝
frontend/public/openapi.json(+105 -1)📝
frontend/src/generated/examples.ts(+1 -0)📝
frontend/src/generated/schemas.ts(+4 -0)📝
frontend/src/generated/types.ts(+1 -0)📝
frontend/src/generated/zod.ts(+1 -0)📝
frontend/src/hooks/useClients.ts(+1 -0)📝
frontend/src/pages/api-docs/endpoints.ts(+24 -7)📝
frontend/src/pages/clients/ClientBulkAddModal.tsx(+11 -0)📝
frontend/src/pages/clients/ClientFormModal.tsx(+117 -3)📝
frontend/src/schemas/client.ts(+3 -0)📝
frontend/src/utils/index.ts(+17 -0)➕
internal/database/client_hwid_schema_test.go(+62 -0)📝
internal/database/db.go(+1 -0)📝
internal/database/migrate_data.go(+1 -0)📝
internal/database/model/model.go(+25 -0)📝
internal/sub/controller.go(+45 -0)➕
internal/sub/hwid_controller_test.go(+134 -0)📝
internal/web/controller/client.go(+21 -3)📝
internal/web/service/api_scale_postgres_test.go(+1 -1)📝
internal/web/service/client.go(+30 -0)...and 25 more files
📄 Description
Summary
This PR adds an optional per-client HWID limit for subscription downloads only. Admins set
limitHwidon a client (same place as traffic and IP limits). When the limit is greater than zero, the subscription server only serves link/config bodies to clients that send a stable device id inX-HWID(and optionally device metadata headers). Registered devices are stored as SHA-256 hashes; raw HWIDs are never persisted.This does not change Xray inbounds, proxy auth, or live connection handling. It is enforced on the panel’s subscription HTTP routes before config is returned.
Behavior before this PR
/sub,/json, and/clashconfig without proving which device was asking.Behavior after this PR
Admin / panel
limitHwid(default 0 = unlimited, same semantics as “0 means off” for other limits).limitHwidwith the rest of the client record.POST /panel/api/clients/hwids/:email— list registered device metadata (no raw HWID / hash exposed as an identifier).DELETE /panel/api/clients/hwids/:email— delete allclient_hwidsrows for that client.Database
clients.limit_hwid.client_hwidskeyed byclient_id(not inbound), with unique(client_id, hwid_hash)and optional metadata columns.Subscription HTTP (what end users see)
Enforcement applies to subscription bodies:
GET/HEADon/sub/:subid,/json/:subid,/clash/:subidNot gated (unchanged on purpose):
Accept: text/html(or?html=1/?view=html) — users can still open the summary page withoutX-HWID.When
limitHwid > 0for the enabled client behind thatsubId:X-HWID, or value shorter than 6 charactersX-Hwid-Active: true,X-Hwid-Not-Supported: trueX-HWIDmatches an already registered devicelast_seenand metadata updatedX-HWIDand registered count < limitX-HWIDand registered count ≥ limitX-Hwid-Max-Devices-Reached: true,X-Hwid-Limit: trueOptional headers stored on registration / update (when sent by the app):
User-AgentX-Device-OS,X-Ver-OS,X-Device-ModelClients that support subscription HWID must send
X-HWIDon sub/json/clash fetches when the admin has set a non-zero limit.Multi-node
Subscription is served from the panel that owns the client record and
subId. HWID state lives in that panel’s database only. Remote nodes are not involved in subscription fetch or HWID registration, so this PR does not add cross-node sync for HWIDs.Explicitly out of scope (v1)
Why
Operators asked for a way to reduce subscription link sharing across many physical devices without modifying Xray core. Gating at the subscription endpoint matches how many mobile/desktop apps already identify themselves when pulling configs.
Type of change
Areas affected
How was this tested?
go test ./internal/sub -run Hwidgo test ./internal/web/service -run Hwidgo test ./internal/database -run Hwid(PostgreSQL schema test runs whenXUI_TEST_PG_DSNis set; otherwise skipped)limitHwidon a client → fetch/sub,/json,/clashwith and withoutX-HWID→ confirm registration, block at limit, allow known device after limit → clear HWIDs from client formScreenshots / recordings
N/A (UI follows existing client form / IP log patterns).
Breaking changes
None.
limitHwiddefaults to0(disabled). Existing subscriptions behave as before until an admin sets a non-zero limit.Checklist
go build ./...and targeted tests pass locally.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.