mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 19:11:53 +07:00
[GH-ISSUE #6364] [Feature]: Age-encrypted subscription output for Clash/Mihomo clients #4319
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#4319
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?
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_KEYenvironment 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):subAgeEnablefalsesubAgeSecretKey""AGE-SECRET-KEY-...form. Used to derive the public key for encryption.Backend behavior:
When
subAgeEnableis true andsubAgeSecretKeyis non-empty, after generating the plaintext body for any subscription endpoint:FiloSottile/age(pure Go, no CGO).-----BEGIN AGE ENCRYPTED FILE-----format).Content-Type: application/x-age-encrypted.All three endpoints use the same code path — no per-format special casing:
/sub/vless://...)/clash//json/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:
Alternatives you've considered
subEncrypt: true) — already available on/sub/; trivially reversible, provides only obfuscation.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:
mihomo age keygento generate a key pair, thenmihomo age convert <secret>to get the public key.CLASH_AGE_SECRET_KEY=<private-key>and subscribe normally./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:
Example
/clash/<sub-id>response when encryption is enabled (what the client receives):Example
/sub/<sub-id>response (encrypted base64 share links):After client decryption + base64 decoding,
/sub/yields the same content as today:References:
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?
Before submitting
@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
agedependency at all (go.modhas nofilippo.io/age;AGE-SECRET-KEY/CLASH_AGEappear 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)
/sub/internal/sub/controller.go:439-443base64.StdEncoding.EncodeToString(...)whensubEncrypt, else raw/clash/internal/sub/controller.go:807c.Data(200, "application/yaml; charset=utf-8", []byte(clashSub))/json/internal/sub/controller.go:757c.Data(200, contentType, []byte(jsonSub))subEncryptdefaults 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: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 atinternal/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:
Subscription-Userinfoheader. Built atinternal/sub/controller.go:426asupload=%d; download=%d; total=%d; expire=%dand set at:824. That is exactly the "traffic quotas, and expiry data" the request wants hidden, and it is a header, not a body.Accept: text/htmlis served before the body branch (maybeServeSubPage,internal/sub/controller.go:312-324) andsubPageContextinjects the real share links into the page:"links": page.Result(:615), whereResult []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 asubAgeRecipientssetting holding one or moreage1…public keys, with every private key living only on the clients. Masking is not a blocker either way;frontend/src/pages/settings/SecretInput.tsxalready exists for that.Two smaller corrections in the same area:
GetSubEncrypt()atinternal/sub/sub.go:128, handed in viaWithSUBEncryption(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).BEGINline, base64 payload lines,ENDline — with noVersion:/PubKey:headers and nothing afterEND. Don't implement from that snippet.4. The mihomo prerequisite is unverified
The whole feature rests on
CLASH_AGE_SECRET_KEYexisting 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: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":
subCertFile/subKeyFile(internal/web/service/setting.go:106-107); seedocs/content/docs/en/config/subscription.mdx.limit_hwidon 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 atinternal/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.