[GH-ISSUE #6357] [Feature]: Read-only HWID device-slot status on the subscription API (registered / limit / remaining) #4312

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

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

When a client has an HWID device limit, the subscriber has no way to see how many
device slots they have used. The subscription API only exposes whether the gate is
active:

  • GET /{subPath}/{subId} without a valid X-HWID returns 404 with
    X-Hwid-Active: true and X-Hwid-Not-Supported: true — a boolean state only.
  • GET /{subPath}/{subId}?format=info returns traffic, expiry and status, but no
    limitHwid and no registered-device count.

The counts already exist internally (clients.limit_hwid and the client_hwids
table) and the admin panel displays them, but that path requires an admin session.
So a subscriber whose single slot is already taken just sees a failed connection
with no explanation, and every "why can't I connect on my new phone" case has to
be answered manually by the operator.

Describe the solution you'd like

Add one additive, public, read-only aggregate endpoint on the subscription router:

GET /{subPath}/{subId}/hwid-status

Response:

{
"active": true,
"limit": 1,
"registered": 1,
"remaining": 0,
"full": true
}

Behaviour:

  • SELECT-only. It must not register an HWID, must not touch last_seen, and must
    not call the existing enforcement path.
  • Aggregate numbers only. No HWID value or hash, no email, no device model, no IP,
    no User-Agent.
  • The subscription ID is already the bearer secret for /{subPath}/{subId}, so no
    admin token and no new auth mechanism is needed.
  • Unknown or disabled subscription → 404, with no distinction between the two.
  • No HWID limit configured → {"active": false, "limit": 0, ...}.
  • No database schema change and no migration.

A separate route keeps the existing response contracts untouched: /{subPath}/{subId},
?format=info, and the JSON/Clash routes all stay exactly as they are, so no
existing client is affected.

Roughly, this is a new SELECT-only helper next to the existing HWID service, a new
handler file, and one route registration in the subscription router's initRouter.

Alternatives you've considered

  • Adding the fields to ?format=info: rejected, it changes an existing response
    contract that third-party panels already parse.
  • Adding them to the 404 gate headers: the 404 path is the failure path, so the
    data would only be visible after a connection attempt has already failed.
  • Using the admin HWID list API from a frontend: requires shipping an admin token
    to a public-facing service, which is not acceptable.
  • Patching a local fork: works, but every upgrade has to be re-applied, and this
    seems generally useful rather than specific to one deployment.

Concrete use case

I run a subscription service where each plan has a one-device HWID limit, with a
customer-facing web panel that renders the subscription link. Today that panel can
show quota and expiry but nothing about devices. With this endpoint it could show
"Devices 1/1 — no slots remaining" or "1 slot remaining", so the customer
understands why a second device fails instead of opening a support ticket.

The same applies to any reseller bot or panel built on the subscription API.

Mockups, screenshots, or examples

Request:
curl -fsS 'https://panel.example.com:2096/api/SUB_ID/hwid-status'

Full:
{"active":true,"limit":1,"registered":1,"remaining":0,"full":true}

Slot free:
{"active":true,"limit":2,"registered":1,"remaining":1,"full":false}

No HWID limit:
{"active":false,"limit":0,"registered":0,"remaining":0,"full":false}

Customer-facing rendering: "Devices 1/1 · Device limit full".

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 @Namso9 on GitHub (Aug 29, 2026). Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/6357 ### Is your feature request related to a problem? When a client has an HWID device limit, the subscriber has no way to see how many device slots they have used. The subscription API only exposes whether the gate is active: - GET /{subPath}/{subId} without a valid X-HWID returns 404 with X-Hwid-Active: true and X-Hwid-Not-Supported: true — a boolean state only. - GET /{subPath}/{subId}?format=info returns traffic, expiry and status, but no limitHwid and no registered-device count. The counts already exist internally (clients.limit_hwid and the client_hwids table) and the admin panel displays them, but that path requires an admin session. So a subscriber whose single slot is already taken just sees a failed connection with no explanation, and every "why can't I connect on my new phone" case has to be answered manually by the operator. ### Describe the solution you'd like Add one additive, public, read-only aggregate endpoint on the subscription router: GET /{subPath}/{subId}/hwid-status Response: { "active": true, "limit": 1, "registered": 1, "remaining": 0, "full": true } Behaviour: - SELECT-only. It must not register an HWID, must not touch last_seen, and must not call the existing enforcement path. - Aggregate numbers only. No HWID value or hash, no email, no device model, no IP, no User-Agent. - The subscription ID is already the bearer secret for /{subPath}/{subId}, so no admin token and no new auth mechanism is needed. - Unknown or disabled subscription → 404, with no distinction between the two. - No HWID limit configured → {"active": false, "limit": 0, ...}. - No database schema change and no migration. A separate route keeps the existing response contracts untouched: /{subPath}/{subId}, ?format=info, and the JSON/Clash routes all stay exactly as they are, so no existing client is affected. Roughly, this is a new SELECT-only helper next to the existing HWID service, a new handler file, and one route registration in the subscription router's initRouter. ### Alternatives you've considered - Adding the fields to ?format=info: rejected, it changes an existing response contract that third-party panels already parse. - Adding them to the 404 gate headers: the 404 path is the failure path, so the data would only be visible after a connection attempt has already failed. - Using the admin HWID list API from a frontend: requires shipping an admin token to a public-facing service, which is not acceptable. - Patching a local fork: works, but every upgrade has to be re-applied, and this seems generally useful rather than specific to one deployment. ### Concrete use case I run a subscription service where each plan has a one-device HWID limit, with a customer-facing web panel that renders the subscription link. Today that panel can show quota and expiry but nothing about devices. With this endpoint it could show "Devices 1/1 — no slots remaining" or "1 slot remaining", so the customer understands why a second device fails instead of opening a support ticket. The same applies to any reseller bot or panel built on the subscription API. ### Mockups, screenshots, or examples Request: curl -fsS 'https://panel.example.com:2096/api/SUB_ID/hwid-status' Full: {"active":true,"limit":1,"registered":1,"remaining":0,"full":true} Slot free: {"active":true,"limit":2,"registered":1,"remaining":1,"full":false} No HWID limit: {"active":false,"limit":0,"registered":0,"remaining":0,"full":false} Customer-facing rendering: "Devices 1/1 · Device limit full". ### 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 - [x] I searched [existing issues](../issues?q=is%3Aissue) and this feature has not been requested. - [x] This feature request is written in English.
bsakaguchi 2026-10-31 20:38:45 +07:00
Author
Owner

@github-actions[bot] commented on GitHub (Aug 29, 2026):

The gap you describe is real: I confirmed in the source that nothing on the subscription server exposes HWID slot counts today, so this is a valid feature request. Below is what I verified, plus three things that make the change smaller than your write-up assumes and two caveats worth deciding before anyone builds it.

What the code actually does today

The subscription router registers only the three body routes — there is no fourth path under subPath (internal/sub/controller.go:290-304):

gLink := g.Group(a.subPath)
gLink.GET(":subid", a.subs)
gLink.HEAD(":subid", a.subs)

?format=info returns subPageContext(page) with links deleted (internal/sub/controller.go:326-340), and that map (internal/sub/controller.go:596-619) carries traffic, expiry, online state and URLs — no limitHwid, no device count. Your reading is correct.

The only HWID signal on the wire is the four booleans in applyHwidHeaders (internal/sub/controller.go:642-655): X-Hwid-Active, X-Hwid-Not-Supported, X-Hwid-Limit, X-Hwid-Max-Devices-Reached.

The counts are otherwise admin-only, as you said: POST /panel/api/inbounds/hwids/:email (internal/web/controller/client.go:79) → ClientService.ListClientHwids (internal/web/service/client_hwid.go:159).

Three things that make this cheaper than the proposal assumes

1. The aggregate already exists and already reaches the sub controller. HwidGateResult carries both numbers (internal/web/service/client_hwid.go:30-31):

	Limit             int
	Registered        int

EnforceHwidForSubID populates them, and enforceHwid receives the whole struct at internal/sub/controller.go:634 — applyHwidHeaders just never serializes those two fields.

2. The SELECT-only helper you describe is one Count away. effectiveHwidLimitForSubID (internal/web/service/client_hwid.go:70-77) is already a pure SELECT, and the registered count is the same query used at client_hwid.go:127 and :139. So a read-only helper needs no new query shape and, as you say, no migration.

3. Your active/limit/registered shape matches storage exactly. The limit is per subscription, not per client — COALESCE(MAX(limit_hwid), 0) over enabled clients sharing the sub_id (client_hwid.go:73-74) — and devices are keyed by sub_id, so the aggregate is well defined for a subId with several clients attached.

One premise to correct, which does not change your conclusion

applyHwidHeaders(c, result) runs at internal/sub/controller.go:634, before the if !result.Allowed check on line 635 — so those headers are on 200 responses too, not only on the 404. Your conclusion still holds for your use case, though, for a different reason: a caller that sends no X-HWID (a customer-facing panel) hits the early return at client_hwid.go:100-103, which sets NotSupported and returns before any count runs. On that path Registered is 0 and Limit is set, so simply emitting the existing fields as headers would not answer "how many slots are used" for your panel.

Your other requirements are already existing behaviour rather than new work: an unknown subId on the info surface already 404s via writeSubError, pinned by TestSubInfoEndpoint_UnknownSubIs404 (internal/sub/info_endpoint_test.go:81-96), and the precedent for a non-gated info surface under subPath is TestSubscriptionHwidGateSkipsHtmlInfoPage (internal/sub/hwid_controller_test.go:124-134) plus the ordering in subs(), where maybeServeSubInfo runs at line 389 and enforceHwid only at line 397.

Two caveats for whoever decides this

  • CORS. grep for Access-Control-Allow-Origin across every .go file in the tree returns nothing — the subscription server sets no CORS headers at all. Your curl example works, and a server-side proxy in your panel works, but a browser fetch() from your panel's own origin to the sub server will be blocked. That is orthogonal to this endpoint but decides whether it is usable the way your mockup implies.
  • The cheaper alternative is less breaking than you rated it. ?format=info serializes a map[string]any; adding keys leaves every existing key and value byte-identical, so a third-party parser that reads total/expire is not affected. It would also feed the HTML sub page's window.__SUB_PAGE_DATA__ from the same place with no new route. A separate endpoint is still the cleaner contract — just noting the trade-off is smaller than "changes an existing response contract" suggests.

For scope: sub-server routes sit outside TestRouteRegistryContract (internal/web/routes_contract_test.go:25-29), so a new route here does not pull in the endpoints.ts / openapigen chain that /panel/api/* routes require.

Related, not a duplicate: #6331 asks for placeholder configs instead of a 404 when the HWID limit is hit — same underlying frustration ("the subscriber cannot tell why it failed"), different mechanism, so I have left both open. HWID limits themselves landed in 694ad6de (#5802) and shipped in v3.7.0; nothing since adds a subscription-side status surface.

Whether this is accepted and in what shape is the maintainer's call.

Verdict: Feature request

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

<!-- gh-comment-id:5459891042 --> @github-actions[bot] commented on GitHub (Aug 29, 2026): The gap you describe is real: I confirmed in the source that nothing on the subscription server exposes HWID slot counts today, so this is a valid feature request. Below is what I verified, plus three things that make the change smaller than your write-up assumes and two caveats worth deciding before anyone builds it. ### What the code actually does today The subscription router registers only the three body routes — there is no fourth path under `subPath` (`internal/sub/controller.go:290-304`): ```go gLink := g.Group(a.subPath) gLink.GET(":subid", a.subs) gLink.HEAD(":subid", a.subs) ``` `?format=info` returns `subPageContext(page)` with `links` deleted (`internal/sub/controller.go:326-340`), and that map (`internal/sub/controller.go:596-619`) carries traffic, expiry, online state and URLs — no `limitHwid`, no device count. Your reading is correct. The only HWID signal on the wire is the four booleans in `applyHwidHeaders` (`internal/sub/controller.go:642-655`): `X-Hwid-Active`, `X-Hwid-Not-Supported`, `X-Hwid-Limit`, `X-Hwid-Max-Devices-Reached`. The counts are otherwise admin-only, as you said: `POST /panel/api/inbounds/hwids/:email` (`internal/web/controller/client.go:79`) → `ClientService.ListClientHwids` (`internal/web/service/client_hwid.go:159`). ### Three things that make this cheaper than the proposal assumes **1. The aggregate already exists and already reaches the sub controller.** `HwidGateResult` carries both numbers (`internal/web/service/client_hwid.go:30-31`): ```go Limit int Registered int ``` `EnforceHwidForSubID` populates them, and `enforceHwid` receives the whole struct at `internal/sub/controller.go:634` — `applyHwidHeaders` just never serializes those two fields. **2. The SELECT-only helper you describe is one `Count` away.** `effectiveHwidLimitForSubID` (`internal/web/service/client_hwid.go:70-77`) is already a pure SELECT, and the registered count is the same query used at `client_hwid.go:127` and `:139`. So a read-only helper needs no new query shape and, as you say, no migration. **3. Your `active/limit/registered` shape matches storage exactly.** The limit is per subscription, not per client — `COALESCE(MAX(limit_hwid), 0)` over enabled clients sharing the `sub_id` (`client_hwid.go:73-74`) — and devices are keyed by `sub_id`, so the aggregate is well defined for a `subId` with several clients attached. ### One premise to correct, which does not change your conclusion `applyHwidHeaders(c, result)` runs at `internal/sub/controller.go:634`, *before* the `if !result.Allowed` check on line 635 — so those headers are on 200 responses too, not only on the 404. Your conclusion still holds for your use case, though, for a different reason: a caller that sends no `X-HWID` (a customer-facing panel) hits the early return at `client_hwid.go:100-103`, which sets `NotSupported` and returns **before** any count runs. On that path `Registered` is 0 and `Limit` is set, so simply emitting the existing fields as headers would not answer "how many slots are used" for your panel. Your other requirements are already existing behaviour rather than new work: an unknown `subId` on the info surface already 404s via `writeSubError`, pinned by `TestSubInfoEndpoint_UnknownSubIs404` (`internal/sub/info_endpoint_test.go:81-96`), and the precedent for a non-gated info surface under `subPath` is `TestSubscriptionHwidGateSkipsHtmlInfoPage` (`internal/sub/hwid_controller_test.go:124-134`) plus the ordering in `subs()`, where `maybeServeSubInfo` runs at line 389 and `enforceHwid` only at line 397. ### Two caveats for whoever decides this - **CORS.** `grep` for `Access-Control-Allow-Origin` across every `.go` file in the tree returns nothing — the subscription server sets no CORS headers at all. Your `curl` example works, and a server-side proxy in your panel works, but a browser `fetch()` from your panel's own origin to the sub server will be blocked. That is orthogonal to this endpoint but decides whether it is usable the way your mockup implies. - **The cheaper alternative is less breaking than you rated it.** `?format=info` serializes a `map[string]any`; adding keys leaves every existing key and value byte-identical, so a third-party parser that reads `total`/`expire` is not affected. It would also feed the HTML sub page's `window.__SUB_PAGE_DATA__` from the same place with no new route. A separate endpoint is still the cleaner contract — just noting the trade-off is smaller than "changes an existing response contract" suggests. For scope: sub-server routes sit outside `TestRouteRegistryContract` (`internal/web/routes_contract_test.go:25-29`), so a new route here does not pull in the `endpoints.ts` / openapigen chain that `/panel/api/*` routes require. Related, not a duplicate: #6331 asks for placeholder configs instead of a 404 when the HWID limit is hit — same underlying frustration ("the subscriber cannot tell why it failed"), different mechanism, so I have left both open. HWID limits themselves landed in 694ad6de (#5802) and shipped in v3.7.0; nothing since adds a subscription-side status surface. Whether this is accepted and in what shape is the maintainer's call. 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#4312
No description provided.