[GH-ISSUE #6364] [Feature]: Age-encrypted subscription output for Clash/Mihomo clients #4319

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

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

Operators who serve subscriptions from 3x-ui want the subscription content to be encrypted so that only clients holding the matching age secret key can read node addresses, credentials, traffic quotas, and expiry data. Currently, both the raw share-link subscription (/sub/) and the Clash-format subscription (/clash/) return content that can be read by anyone with the URL.

Meta/Mihomo clients already support age-encrypted subscription input via the CLASH_AGE_SECRET_KEY environment variable — the core decrypts received content before parsing it. However, 3x-ui has no way to produce such encrypted output.

Describe the solution you'd like

Add a toggle and a key field in the Subscription settings so operators can produce age-encrypted responses for all subscription endpoints: /sub/ (share links), /clash/ (Clash YAML), and /json/ (Xray config).

New settings (in internal/web/service/setting.go):

Setting key Type Default Purpose
subAgeEnable boolean false When false, all endpoints behave exactly as today.
subAgeSecretKey string "" The age private key in standard AGE-SECRET-KEY-... form. Used to derive the public key for encryption.

Backend behavior:

When subAgeEnable is true and subAgeSecretKey is non-empty, after generating the plaintext body for any subscription endpoint:

  1. Derive the age public key from the private key (computed once at startup, cached).
  2. Encrypt the plaintext body with FiloSottile/age (pure Go, no CGO).
  3. Return the result as age ASCII armor (standard -----BEGIN AGE ENCRYPTED FILE----- format).
  4. Set Content-Type: application/x-age-encrypted.

All three endpoints use the same code path — no per-format special casing:

Endpoint Plaintext content After encryption
/sub/ base64-encoded share links (vless://...) age armor wrapping the base64 bytes
/clash/ Clash YAML age armor wrapping the YAML bytes
/json/ Xray JSON config age armor wrapping the JSON bytes

Clients set CLASH_AGE_SECRET_KEY=<private-key>, request any subscription URL, and the client core detects the age armor preamble, decrypts the body, then parses it normally.

Key management:

  • The age private key is stored in the settings table. It is masked in API responses.
  • The derived public key is shown in the UI ("Public key for clients") so operators can distribute it to users out-of-band.
  • No database migration needed — both settings are nullable with safe defaults.
  • Rotating the key in the panel is instant; all clients simply re-subscribe with the new key.

Alternatives you've considered

  1. HTTPS-only — protects against transport-level eavesdropping, but anyone who copies the URL can read the full plaintext configuration.
  2. Base64 encoding (subEncrypt: true) — already available on /sub/; trivially reversible, provides only obfuscation.
  3. External Sub-Converter pipe — adds a separate service to maintain; creates a single point of failure and operational overhead.
  4. Separate encrypted domain — still requires an encryption step somewhere; putting it in 3x-ui removes the external dependency.

Concrete use case

An operator manages ~80 clients across a single 3x-ui panel. Subscriptions are distributed via URLs shared within their network. Without encryption, anyone with the URL can read all node addresses, credentials, and quota data.

With this feature, the operator:

  1. Runs mihomo age keygen to generate a key pair, then mihomo age convert <secret> to get the public key.
  2. Enters the private key into the panel's new "Age Encryption" setting.
  3. Distributes the public key to clients via an out-of-band channel (admin page, QR code, etc.).
  4. Clients start with CLASH_AGE_SECRET_KEY=<private-key> and subscribe normally.
  5. All three subscription formats (/sub/, /clash/, /json/) are returned as age-encrypted armor. Old unencrypted URLs continue to work for clients that haven't been upgraded.

Mockups, screenshots, or examples

Expected UI in Settings → Subscription → new section at the bottom:

┌─ Age Encryption ──────────────────────────────────────────────────┐
│                                                                   │
│  [✓] Enable age encryption for subscriptions                      │
│                                                                   │
│  Age Secret Key:                                                  │
│  ┌───────────────────────────────────────────────────────────┐    │
│  │ AGE-SECRET-KEY-1ZTQLLN0A4U3ZTT3DCZKYN0CGZEZQLWX2DFTX...   │    │
│  └───────────────────────────────────────────────────────────┘    │
│                                                                   │
│  Public key (for clients):                                        │
│  age1ql3z7hjy2g0...                                               │
│  [Copy]                                                           │
│                                                                   │
│  Applies to: /sub/  /clash/  /json/                               │
└───────────────────────────────────────────────────────────────────┘

Example /clash/<sub-id> response when encryption is enabled (what the client receives):

-----BEGIN AGE ENCRYPTED FILE-----
Version: age-encryption.org/v1
PubKey: age1ql3z7hjy2g0...
-----END AGE ENCRYPTED FILE-----
U2VjcmV0IGRhdGEgZm9yIGFnZQ==

Example /sub/<sub-id> response (encrypted base64 share links):

-----BEGIN AGE ENCRYPTED FILE-----
Version: age-encryption.org/v1
PubKey: age1ql3z7hjy2g0...
-----END AGE ENCRYPTED FILE-----
U2VjcmV0IGRhdGEgZm9yIGFnZQ==

After client decryption + base64 decoding, /sub/ yields the same content as today:

vless://xxx@...
vmess://yyy@...

References:

Which parts of the panel would this affect?

Frontend (UI / panel pages), Backend (API endpoints, login, settings), 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 @jshir700 on GitHub (Aug 29, 2026). Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/6364 ### Is your feature request related to a problem? Operators who serve subscriptions from 3x-ui want the subscription content to be encrypted so that only clients holding the matching age secret key can read node addresses, credentials, traffic quotas, and expiry data. Currently, both the raw share-link subscription (`/sub/`) and the Clash-format subscription (`/clash/`) return content that can be read by anyone with the URL. Meta/Mihomo clients already support age-encrypted subscription input via the `CLASH_AGE_SECRET_KEY` environment variable — the core decrypts received content before parsing it. However, 3x-ui has no way to produce such encrypted output. ### Describe the solution you'd like Add a toggle and a key field in the Subscription settings so operators can produce age-encrypted responses for **all subscription endpoints**: `/sub/` (share links), `/clash/` (Clash YAML), and `/json/` (Xray config). **New settings** (in `internal/web/service/setting.go`): | Setting key | Type | Default | Purpose | |---|---|---|---| | `subAgeEnable` | boolean | `false` | When false, all endpoints behave exactly as today. | | `subAgeSecretKey` | string | `""` | The age private key in standard `AGE-SECRET-KEY-...` form. Used to derive the public key for encryption. | **Backend behavior:** When `subAgeEnable` is true and `subAgeSecretKey` is non-empty, after generating the plaintext body for any subscription endpoint: 1. Derive the age public key from the private key (computed once at startup, cached). 2. Encrypt the plaintext body with `FiloSottile/age` (pure Go, no CGO). 3. Return the result as age ASCII armor (standard `-----BEGIN AGE ENCRYPTED FILE-----` format). 4. Set `Content-Type: application/x-age-encrypted`. All three endpoints use the same code path — no per-format special casing: | Endpoint | Plaintext content | After encryption | |---|---|---| | `/sub/` | base64-encoded share links (`vless://...`) | age armor wrapping the base64 bytes | | `/clash/` | Clash YAML | age armor wrapping the YAML bytes | | `/json/` | Xray JSON config | age armor wrapping the JSON bytes | Clients set `CLASH_AGE_SECRET_KEY=<private-key>`, request any subscription URL, and the client core detects the age armor preamble, decrypts the body, then parses it normally. **Key management:** - The age private key is stored in the settings table. It is masked in API responses. - The derived public key is shown in the UI ("Public key for clients") so operators can distribute it to users out-of-band. - No database migration needed — both settings are nullable with safe defaults. - Rotating the key in the panel is instant; all clients simply re-subscribe with the new key. ### Alternatives you've considered 1. **HTTPS-only** — protects against transport-level eavesdropping, but anyone who copies the URL can read the full plaintext configuration. 2. **Base64 encoding (`subEncrypt: true`)** — already available on `/sub/`; trivially reversible, provides only obfuscation. 3. **External Sub-Converter pipe** — adds a separate service to maintain; creates a single point of failure and operational overhead. 4. **Separate encrypted domain** — still requires an encryption step somewhere; putting it in 3x-ui removes the external dependency. ### Concrete use case An operator manages ~80 clients across a single 3x-ui panel. Subscriptions are distributed via URLs shared within their network. Without encryption, anyone with the URL can read all node addresses, credentials, and quota data. With this feature, the operator: 1. Runs `mihomo age keygen` to generate a key pair, then `mihomo age convert <secret>` to get the public key. 2. Enters the private key into the panel's new "Age Encryption" setting. 3. Distributes the public key to clients via an out-of-band channel (admin page, QR code, etc.). 4. Clients start with `CLASH_AGE_SECRET_KEY=<private-key>` and subscribe normally. 5. All three subscription formats (`/sub/`, `/clash/`, `/json/`) are returned as age-encrypted armor. Old unencrypted URLs continue to work for clients that haven't been upgraded. ### Mockups, screenshots, or examples Expected UI in Settings → Subscription → new section at the bottom: ``` ┌─ Age Encryption ──────────────────────────────────────────────────┐ │ │ │ [✓] Enable age encryption for subscriptions │ │ │ │ Age Secret Key: │ │ ┌───────────────────────────────────────────────────────────┐ │ │ │ AGE-SECRET-KEY-1ZTQLLN0A4U3ZTT3DCZKYN0CGZEZQLWX2DFTX... │ │ │ └───────────────────────────────────────────────────────────┘ │ │ │ │ Public key (for clients): │ │ age1ql3z7hjy2g0... │ │ [Copy] │ │ │ │ Applies to: /sub/ /clash/ /json/ │ └───────────────────────────────────────────────────────────────────┘ ``` Example `/clash/<sub-id>` response when encryption is enabled (what the client receives): ``` -----BEGIN AGE ENCRYPTED FILE----- Version: age-encryption.org/v1 PubKey: age1ql3z7hjy2g0... -----END AGE ENCRYPTED FILE----- U2VjcmV0IGRhdGEgZm9yIGFnZQ== ``` Example `/sub/<sub-id>` response (encrypted base64 share links): ``` -----BEGIN AGE ENCRYPTED FILE----- Version: age-encryption.org/v1 PubKey: age1ql3z7hjy2g0... -----END AGE ENCRYPTED FILE----- U2VjcmV0IGRhdGEgZm9yIGFnZQ== ``` After client decryption + base64 decoding, `/sub/` yields the same content as today: ``` vless://xxx@... vmess://yyy@... ``` References: - Meta/Mihomo age support: https://wiki.metacubex.one/en/config/proxy-providers/#age-secret-key - Golang age library: https://github.com/FiloSottile/age - Key generation: `mihomo age keygen` → `mihomo age convert <secret>` ### Which parts of the panel would this affect? Frontend (UI / panel pages), Backend (API endpoints, login, settings), 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 (Aug 29, 2026):

Reasonable request, and your description of today's behaviour is correct — nothing in the tree encrypts any subscription body, and there is no age dependency at all (go.mod has no filippo.io/age; AGE-SECRET-KEY / CLASH_AGE appear nowhere in the repo). But four parts of the proposal don't survive contact with the current code, and they change the design enough that they're worth settling before anyone writes a line.

What the panel does today (confirmed)

endpoint code body
/sub/ internal/sub/controller.go:439-443 base64.StdEncoding.EncodeToString(...) when subEncrypt, else raw
/clash/ internal/sub/controller.go:807 c.Data(200, "application/yaml; charset=utf-8", []byte(clashSub))
/json/ internal/sub/controller.go:757 c.Data(200, contentType, []byte(jsonSub))

subEncrypt defaults to "true" (internal/web/service/setting.go:109) and is base64 only — the docs already say as much: "Base64-encode the raw subscription body" (docs/content/docs/en/config/subscription.mdx:24). So your alternative #2 is accurately characterised.

1. A panel-global toggle breaks every non-mihomo client

/sub/ is the generic endpoint. It also auto-serves Clash and Xray-JSON bodies off the same path by User-Agent:

// internal/sub/controller.go:400-409
if shouldAutoServeClash(a.subClashAutoDetect, a.clashEnabled, false, userAgent, a.clashUserAgent) && a.serveClashBody(c, false) {
if shouldAutoServeJson(a.jsonAutoDetect, a.jsonEnabled, false, userAgent, a.jsonUserAgent) && a.serveJsonBody(c, true, "application/json; charset=utf-8", false) {

Two global settings give one body per subId, so step 5's "Old unencrypted URLs continue to work for clients that haven't been upgraded" isn't achievable — the URL is the same URL. With subAgeEnable=true, v2rayNG, Streisand, Happ, sing-box and Hiddify users on that panel all get an unparseable armor blob. If this is built, the encryption needs to be scoped to requests that can actually decrypt it (the Clash UA regex already exists at internal/sub/controller.go:269), or opted into per request/per client — not flipped panel-wide.

2. Encrypting the body doesn't close the threat you described

The same URL keeps handing out the quota, expiry and node data in plaintext through three other paths:

  • The Subscription-Userinfo header. Built at internal/sub/controller.go:426 as upload=%d; download=%d; total=%d; expire=%d and set at :824. That is exactly the "traffic quotas, and expiry data" the request wants hidden, and it is a header, not a body.
  • The HTML info page. Any request with Accept: text/html is served before the body branch (maybeServeSubPage, internal/sub/controller.go:312-324) and subPageContext injects the real share links into the page: "links": page.Result (:615), where Result []string (internal/sub/service.go:2638) is the link list. A browser with the URL reads everything.
  • ?format=info. Returns the same view-model as JSON (internal/sub/controller.go:326-340).

Against "anyone who copies the URL can read the full plaintext configuration", encrypting only the three bodies is cosmetic. A workable proposal has to say what happens to the header, the HTML page and format=info.

3. The key roles are swapped

age encrypts to a recipient public key; only the holder of the private key decrypts. Putting AGE-SECRET-KEY-… in the panel and distributing the public key to clients (steps 2–4 of your use case) inverts that — and it parks a decryption secret in the settings table that the server has no cryptographic need for. The shape that matches age is a subAgeRecipients setting holding one or more age1… public keys, with every private key living only on the clients. Masking is not a blocker either way; frontend/src/pages/settings/SecretInput.tsx already exists for that.

Two smaller corrections in the same area:

  • "Rotating the key in the panel is instant" — no. Every sub-server setting is snapshotted once while the router is built (GetSubEncrypt() at internal/sub/sub.go:128, handed in via WithSUBEncryption(Encrypt) at :283); a new setting read the same way takes effect only after a panel restart (POST /panel/setting/restartPanel, internal/web/controller/setting.go:73).
  • The armor block in your mockup isn't age's armor format. age armor is strict PEM — BEGIN line, base64 payload lines, END line — with no Version:/PubKey: headers and nothing after END. Don't implement from that snippet.

4. The mihomo prerequisite is unverified

The whole feature rests on CLASH_AGE_SECRET_KEY existing on the client side, and I have no network access here, so I could not check the wiki page you linked or confirm the variable name. Could you add:

  1. The mihomo version you tested this against, and
  2. A link to the mihomo commit or release notes that introduced it — specifically whether it decrypts any subscription/config fetch, or only bodies loaded through proxy-providers. If it's providers-only, /sub/ and /json/ are out of scope and this becomes a /clash/-only feature.

What exists today for the same goal

Neither is encryption, but both narrow "anyone with the URL":

  • TLS on the subscription server — subCertFile / subKeyFile (internal/web/service/setting.go:106-107); see docs/content/docs/en/config/subscription.mdx.
  • Per-client HWID device limiting — limit_hwid on the client record; EnforceHwidForSubID (internal/web/service/client_hwid.go:79-95) 404s a subId fetched from more devices than allowed, which is the closest thing to "a copied URL stops working". Note it runs at internal/sub/controller.go:397, after the HTML-page branch, so it gates the body fetch and not a browser view.

Leaving this open with enhancement; title and label are accurate as filed.

Verdict: Feature request

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

<!-- gh-comment-id:5464229846 --> @github-actions[bot] commented on GitHub (Aug 29, 2026): Reasonable request, and your description of today's behaviour is correct — nothing in the tree encrypts any subscription body, and there is no `age` dependency at all (`go.mod` has no `filippo.io/age`; `AGE-SECRET-KEY` / `CLASH_AGE` appear nowhere in the repo). But four parts of the proposal don't survive contact with the current code, and they change the design enough that they're worth settling before anyone writes a line. ## What the panel does today (confirmed) | endpoint | code | body | | --- | --- | --- | | `/sub/` | `internal/sub/controller.go:439-443` | `base64.StdEncoding.EncodeToString(...)` when `subEncrypt`, else raw | | `/clash/` | `internal/sub/controller.go:807` | `c.Data(200, "application/yaml; charset=utf-8", []byte(clashSub))` | | `/json/` | `internal/sub/controller.go:757` | `c.Data(200, contentType, []byte(jsonSub))` | `subEncrypt` defaults to `"true"` (`internal/web/service/setting.go:109`) and is base64 only — the docs already say as much: *"Base64-encode the raw subscription body"* (`docs/content/docs/en/config/subscription.mdx:24`). So your alternative #2 is accurately characterised. ## 1. A panel-global toggle breaks every non-mihomo client `/sub/` is the *generic* endpoint. It also auto-serves Clash and Xray-JSON bodies off the same path by User-Agent: ```go // internal/sub/controller.go:400-409 if shouldAutoServeClash(a.subClashAutoDetect, a.clashEnabled, false, userAgent, a.clashUserAgent) && a.serveClashBody(c, false) { if shouldAutoServeJson(a.jsonAutoDetect, a.jsonEnabled, false, userAgent, a.jsonUserAgent) && a.serveJsonBody(c, true, "application/json; charset=utf-8", false) { ``` Two global settings give one body per subId, so step 5's *"Old unencrypted URLs continue to work for clients that haven't been upgraded"* isn't achievable — the URL is the same URL. With `subAgeEnable=true`, v2rayNG, Streisand, Happ, sing-box and Hiddify users on that panel all get an unparseable armor blob. If this is built, the encryption needs to be scoped to requests that can actually decrypt it (the Clash UA regex already exists at `internal/sub/controller.go:269`), or opted into per request/per client — not flipped panel-wide. ## 2. Encrypting the body doesn't close the threat you described The same URL keeps handing out the quota, expiry and node data in plaintext through three other paths: - **The `Subscription-Userinfo` header.** Built at `internal/sub/controller.go:426` as `upload=%d; download=%d; total=%d; expire=%d` and set at `:824`. That is exactly the "traffic quotas, and expiry data" the request wants hidden, and it is a header, not a body. - **The HTML info page.** Any request with `Accept: text/html` is served *before* the body branch (`maybeServeSubPage`, `internal/sub/controller.go:312-324`) and `subPageContext` injects the real share links into the page: `"links": page.Result` (`:615`), where `Result []string` (`internal/sub/service.go:2638`) is the link list. A browser with the URL reads everything. - **`?format=info`.** Returns the same view-model as JSON (`internal/sub/controller.go:326-340`). Against "anyone who copies the URL can read the full plaintext configuration", encrypting only the three bodies is cosmetic. A workable proposal has to say what happens to the header, the HTML page and `format=info`. ## 3. The key roles are swapped age encrypts to a **recipient public key**; only the holder of the private key decrypts. Putting `AGE-SECRET-KEY-…` in the panel and distributing the *public* key to clients (steps 2–4 of your use case) inverts that — and it parks a decryption secret in the settings table that the server has no cryptographic need for. The shape that matches age is a `subAgeRecipients` setting holding one or more `age1…` public keys, with every private key living only on the clients. Masking is not a blocker either way; `frontend/src/pages/settings/SecretInput.tsx` already exists for that. Two smaller corrections in the same area: - *"Rotating the key in the panel is instant"* — no. Every sub-server setting is snapshotted once while the router is built (`GetSubEncrypt()` at `internal/sub/sub.go:128`, handed in via `WithSUBEncryption(Encrypt)` at `:283`); a new setting read the same way takes effect only after a panel restart (`POST /panel/setting/restartPanel`, `internal/web/controller/setting.go:73`). - The armor block in your mockup isn't age's armor format. age armor is strict PEM — `BEGIN` line, base64 payload lines, `END` line — with no `Version:`/`PubKey:` headers and nothing after `END`. Don't implement from that snippet. ## 4. The mihomo prerequisite is unverified The whole feature rests on `CLASH_AGE_SECRET_KEY` existing on the client side, and I have no network access here, so I could not check the wiki page you linked or confirm the variable name. Could you add: 1. The mihomo version you tested this against, and 2. A link to the mihomo commit or release notes that introduced it — specifically whether it decrypts **any** subscription/config fetch, or only bodies loaded through `proxy-providers`. If it's providers-only, `/sub/` and `/json/` are out of scope and this becomes a `/clash/`-only feature. ## What exists today for the same goal Neither is encryption, but both narrow "anyone with the URL": - **TLS on the subscription server** — `subCertFile` / `subKeyFile` (`internal/web/service/setting.go:106-107`); see `docs/content/docs/en/config/subscription.mdx`. - **Per-client HWID device limiting** — `limit_hwid` on the client record; `EnforceHwidForSubID` (`internal/web/service/client_hwid.go:79-95`) 404s a subId fetched from more devices than allowed, which is the closest thing to "a copied URL stops working". Note it runs at `internal/sub/controller.go:397`, *after* the HTML-page branch, so it gates the body fetch and not a browser view. Leaving this open with `enhancement`; title and label are accurate as filed. 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#4319
No description provided.