[GH-ISSUE #6381] [Feature]: Add opt-in Happ crypt5 generation to the client QR modal #4328

Closed
opened 2026-10-31 20:38:51 +07:00 by bsakaguchi · 2 comments
Owner

Originally created by @NgaiYeanCoi on GitHub (Sep 1, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/6381

Administrators who need a Happ happ://crypt5/ link do not currently have a safe and explicit workflow for generating it from a client's current subscription in the panel.

Doing this manually requires copying a complete subscription URL to an external service. That URL is sensitive because possession of it may grant access to the subscription.

Describe the solution you'd like

Add an optional Happ view to the QR modal for an individual client on the Clients page.

Expected behavior:

  • Open the modal on Standard by default. Opening the modal must not contact any external service.
  • Let the administrator explicitly select Happ.
  • Display the validated happ://crypt5/... link using the existing QR, copy, and image-download flow.
  • If generation fails, show a generic error and Retry action while leaving the Standard link fully usable.

Backend and privacy constraints:

  • The browser sends only the client's internal record ID, not a caller-supplied subscription URL.
  • The authenticated backend loads the current client and constructs the current canonical subscription URL.
  • Use the existing authorization and CSRF protections.
  • Send the URL only to the fixed HTTPS Happ endpoint documented at:
    https://www.happ.su/main/zh/dev-docs/crypto-link
  • Do not follow redirects or automatically retry the provider request.
  • Apply a bounded timeout and response-size limit, and accept only one valid, non-empty happ://crypt5/ result.
  • Mark responses as no-store.
  • Keep generation stateless: no database fields, cache, history, background jobs, or persisted generated links.
  • Logs and user-facing errors must not contain subscription URLs, subscription tokens, provider bodies, or generated Happ links.

Alternatives you've considered

  • Continue using only the Standard subscription link, which does not provide the requested happ://crypt5/ representation.
  • Ask administrators to paste sensitive subscription URLs into the Happ website manually. This makes the disclosure easy to overlook and may result in using a stale or incorrect client URL.
  • Call the provider directly from frontend code. This would expose the integration to browser and CORS behavior and make consistent validation and redacted diagnostics harder.
  • Store generated Happ links for reuse. This introduces unnecessary sensitive state and may return stale links after client or panel settings change.

Concrete use case

An administrator opens the QR modal for one client. The existing Standard QR code is displayed and no external request is made.

The administrator selects Happ, The backend receives only the client record ID, reconstructs the client's current subscription URL, performs one bounded provider request, validates the response, and returns a fresh happ://crypt5/... link.

If the provider is unavailable or returns an invalid response, only the Happ view reports a failure. The administrator can immediately return to the unchanged Standard QR code.

Mockups, screenshots, or examples

Client QR

Image

After success:
happ://crypt5/

Image

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 @NgaiYeanCoi on GitHub (Sep 1, 2026). Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/6381 ### Is your feature request related to a problem? Administrators who need a Happ `happ://crypt5/` link do not currently have a safe and explicit workflow for generating it from a client's current subscription in the panel. Doing this manually requires copying a complete subscription URL to an external service. That URL is sensitive because possession of it may grant access to the subscription. ### Describe the solution you'd like Add an optional **Happ** view to the QR modal for an individual client on the **Clients** page. Expected behavior: - Open the modal on **Standard** by default. Opening the modal must not contact any external service. - Let the administrator explicitly select **Happ**. - Display the validated `happ://crypt5/...` link using the existing QR, copy, and image-download flow. - If generation fails, show a generic error and Retry action while leaving the Standard link fully usable. Backend and privacy constraints: - The browser sends only the client's internal record ID, not a caller-supplied subscription URL. - The authenticated backend loads the current client and constructs the current canonical subscription URL. - Use the existing authorization and CSRF protections. - Send the URL only to the fixed HTTPS Happ endpoint documented at: https://www.happ.su/main/zh/dev-docs/crypto-link - Do not follow redirects or automatically retry the provider request. - Apply a bounded timeout and response-size limit, and accept only one valid, non-empty `happ://crypt5/` result. - Mark responses as `no-store`. - Keep generation stateless: no database fields, cache, history, background jobs, or persisted generated links. - Logs and user-facing errors must not contain subscription URLs, subscription tokens, provider bodies, or generated Happ links. ### Alternatives you've considered - Continue using only the Standard subscription link, which does not provide the requested `happ://crypt5/` representation. - Ask administrators to paste sensitive subscription URLs into the Happ website manually. This makes the disclosure easy to overlook and may result in using a stale or incorrect client URL. - Call the provider directly from frontend code. This would expose the integration to browser and CORS behavior and make consistent validation and redacted diagnostics harder. - Store generated Happ links for reuse. This introduces unnecessary sensitive state and may return stale links after client or panel settings change. ### Concrete use case An administrator opens the QR modal for one client. The existing Standard QR code is displayed and no external request is made. The administrator selects Happ, The backend receives only the client record ID, reconstructs the client's current subscription URL, performs one bounded provider request, validates the response, and returns a fresh `happ://crypt5/...` link. If the provider is unavailable or returns an invalid response, only the Happ view reports a failure. The administrator can immediately return to the unchanged Standard QR code. ### Mockups, screenshots, or examples Client QR <img width="511" height="680" alt="Image" src="https://github.com/user-attachments/assets/91e86cc6-1ff9-4e6d-b0eb-b91431596875" /> After success: happ://crypt5/<opaque-payload> <img width="513" height="712" alt="Image" src="https://github.com/user-attachments/assets/45c7960d-a8d3-4d3b-9a24-d966c0d007b3" /> ### 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? - [x] 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.
bsakaguchi 2026-10-31 20:38:51 +07:00
Author
Owner

@NgaiYeanCoi commented on GitHub (Sep 1, 2026):

This issue is related to #3902

<!-- gh-comment-id:5491219407 --> @NgaiYeanCoi commented on GitHub (Sep 1, 2026): This issue is related to #3902
Author
Owner

@github-actions[bot] commented on GitHub (Sep 1, 2026):

Valid feature request — nothing in the panel generates happ://crypt5/ today, and the design you describe maps cleanly onto machinery that already exists in the tree. Below is what is already there, what is missing, and three details in the spec I would change before writing code.

I could not open the two screenshots (images are not readable in this analysis), so the UI notes below are based on the current component source; if a mockup detail matters, please describe it as text.

What the panel does today

  • Plain Happ import already exists — the subscription page emits happ://add/<subUrl> deeplinks at frontend/src/pages/sub/SubPage.tsx:151, with the Android and iOS menu entries at SubPage.tsx:218 and SubPage.tsx:231. That path makes no external request, but the subscription URL is visible in the link — which is exactly the gap crypt5 closes.
  • A Happ-facing outbound HTTPS fetcher already exists, for routing rules, in internal/sub/remote_routing.go. It is the closest precedent to what you are proposing.
  • crypt5 support does not exist. git log -S 'crypt5' --all returns nothing, and there is no crypt5, crypto.happ or happ.su string anywhere in the checkout.

Prior art you probably did not find because it is titled differently: #3902 ("Feature request add encryption support") asked for happ://crypt5/ with the same vendor doc link. It was closed as completed on 2026-05-29 with no comment, and no commit in history ever introduced crypt5 — so as far as the source shows, that request was closed without being implemented. I am linking it as related rather than closing this one, since your report is the far more specific spec.

The pieces your design would plug into

what you specified what already exists
"browser sends only the client's internal record ID" ClientRecord.id (frontend/src/generated/types.ts:313)
"backend constructs the current canonical subscription URL" SettingService.BuildSubURIBase — internal/web/service/setting.go:1410, documented as the shared source of truth
bounded timeout, size limit, no SSRF newRemoteRoutingHTTPClient — internal/sub/remote_routing.go:464: DialContext: netsafe.SSRFGuardedDialContext, TLSClientConfig: &tls.Config{MinVersion: tls.VersionTLS12}, Timeout: remoteRoutingHTTPTimeout (6s), plus io.LimitReader at remote_routing.go:307
"fixed HTTPS endpoint" precedent for a pinned third-party constant: internal/pia/endpoints.go:9
no-store internal/web/controller/base.go:24, internal/web/controller/index.go:148
"existing authorization and CSRF" already automatic on /panel/api/*: BaseController.checkLogin (internal/web/controller/base.go:19) and CSRFMiddleware (internal/web/middleware/security.go:41)
"existing QR, copy, image-download flow" QrPanel, already imported by the modal (frontend/src/pages/clients/ClientQrModal.tsx:7)

Three things I would change in the spec

1. "Do not follow redirects" is probably too strict. The panel's existing Happ integration discovered that these services return the deeplink as the Location of a 3xx, and handles it without issuing a second request:

// internal/sub/remote_routing.go:484
if strings.EqualFold(req.URL.Scheme, "happ") {
    // routing.help-style services publish the deeplink as the final Location;
    // hand the 3xx back to fetch(), which validates it without a request.
    return http.ErrUseLastResponse
}

with the 3xx consumed at remote_routing.go:284-297. A client that rejects all redirects would throw away a valid response if crypt5 behaves the same way. The rule that gives you the same safety is "never issue a follow-up request, but accept a happ:// Location". I have not verified the crypt5 endpoint's actual response shape — that is the one thing worth confirming against the vendor doc before coding.

2. The Standard link and the generated one can disagree. The modal builds the Standard link entirely client-side today:

// frontend/src/pages/clients/ClientQrModal.tsx:64
const subLink = subId && subEnabled && subSettings?.subURI ? subSettings.subURI + subId : '';

Server-side, the subURI setting wins when it is non-empty and BuildSubURIBase(host) + subPath is only the fallback (internal/web/service/setting.go:1478-1494). A backend that re-derives the URL from resolveHost(c) without reusing that same resolution order will encode a different URL than the QR sitting next to it — behind a reverse proxy or with subDomain set, silently. Reuse the resolution, do not re-implement it.

3. Consider a setting that turns the whole thing off. Some operators forbid any outbound call from the panel host. A single boolean next to the existing Happ settings (internal/web/service/setting.go:1345 maps "Happ routing source" → SubRoutingRules) is cheaper than an admin discovering the capability exists at all.

Minor UI note: the modal is an Ant Design Collapse of sections (ClientQrModal.tsx:240-248), not the Standard/Happ switcher in your mockup — worth deciding whether Happ becomes another collapse panel or the modal grows a real segmented control.

If you open the PR

This is backend-plus-frontend, so the route contract chain applies in full:

  1. the new g.POST needs a matching entry in frontend/src/pages/api-docs/endpoints.ts, then make gen — pinned both ways by TestRouteRegistryContract in internal/web/routes_contract_test.go;
  2. any new struct crossing the API boundary must be added to the StructAllow allowlist in tools/openapigen/main.go, or it is silently dropped from the schemas and the OpenAPI build then fails;
  3. the step nothing checks: copy frontend/public/openapi.json → docs/public/openapi.json, then cd docs && pnpm gen:api;
  4. every new English i18n key goes into all 13 files under internal/web/translation/ and must be referenced in the same commit.

Two rules you do not need to satisfy, given the stateless design: no runtime.Runtime dispatch (nothing changes inbound or client state) and no migration in internal/database/db.go (nothing is persisted). Keeping it that way is what keeps the change small.

Verdict: Feature request

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

<!-- gh-comment-id:5491239061 --> @github-actions[bot] commented on GitHub (Sep 1, 2026): Valid feature request — nothing in the panel generates `happ://crypt5/` today, and the design you describe maps cleanly onto machinery that already exists in the tree. Below is what is already there, what is missing, and three details in the spec I would change before writing code. I could not open the two screenshots (images are not readable in this analysis), so the UI notes below are based on the current component source; if a mockup detail matters, please describe it as text. ## What the panel does today - **Plain Happ import already exists** — the subscription page emits `happ://add/<subUrl>` deeplinks at `frontend/src/pages/sub/SubPage.tsx:151`, with the Android and iOS menu entries at `SubPage.tsx:218` and `SubPage.tsx:231`. That path makes no external request, but the subscription URL is visible in the link — which is exactly the gap `crypt5` closes. - **A Happ-facing outbound HTTPS fetcher already exists**, for routing rules, in `internal/sub/remote_routing.go`. It is the closest precedent to what you are proposing. - **`crypt5` support does not exist.** `git log -S 'crypt5' --all` returns nothing, and there is no `crypt5`, `crypto.happ` or `happ.su` string anywhere in the checkout. Prior art you probably did not find because it is titled differently: **#3902 ("Feature request add encryption support")** asked for `happ://crypt5/` with the same vendor doc link. It was closed as *completed* on 2026-05-29 with no comment, and no commit in history ever introduced `crypt5` — so as far as the source shows, that request was closed without being implemented. I am linking it as related rather than closing this one, since your report is the far more specific spec. ## The pieces your design would plug into | what you specified | what already exists | | --- | --- | | "browser sends only the client's internal record ID" | `ClientRecord.id` (`frontend/src/generated/types.ts:313`) | | "backend constructs the current canonical subscription URL" | `SettingService.BuildSubURIBase` — `internal/web/service/setting.go:1410`, documented as the shared source of truth | | bounded timeout, size limit, no SSRF | `newRemoteRoutingHTTPClient` — `internal/sub/remote_routing.go:464`: `DialContext: netsafe.SSRFGuardedDialContext`, `TLSClientConfig: &tls.Config{MinVersion: tls.VersionTLS12}`, `Timeout: remoteRoutingHTTPTimeout` (6s), plus `io.LimitReader` at `remote_routing.go:307` | | "fixed HTTPS endpoint" | precedent for a pinned third-party constant: `internal/pia/endpoints.go:9` | | `no-store` | `internal/web/controller/base.go:24`, `internal/web/controller/index.go:148` | | "existing authorization and CSRF" | already automatic on `/panel/api/*`: `BaseController.checkLogin` (`internal/web/controller/base.go:19`) and `CSRFMiddleware` (`internal/web/middleware/security.go:41`) | | "existing QR, copy, image-download flow" | `QrPanel`, already imported by the modal (`frontend/src/pages/clients/ClientQrModal.tsx:7`) | ## Three things I would change in the spec **1. "Do not follow redirects" is probably too strict.** The panel's existing Happ integration discovered that these services return the deeplink as the `Location` of a 3xx, and handles it without issuing a second request: ```go // internal/sub/remote_routing.go:484 if strings.EqualFold(req.URL.Scheme, "happ") { // routing.help-style services publish the deeplink as the final Location; // hand the 3xx back to fetch(), which validates it without a request. return http.ErrUseLastResponse } ``` with the 3xx consumed at `remote_routing.go:284-297`. A client that rejects all redirects would throw away a valid response if `crypt5` behaves the same way. The rule that gives you the same safety is "never issue a follow-up request, but accept a `happ://` `Location`". I have **not** verified the crypt5 endpoint's actual response shape — that is the one thing worth confirming against the vendor doc before coding. **2. The Standard link and the generated one can disagree.** The modal builds the Standard link entirely client-side today: ```ts // frontend/src/pages/clients/ClientQrModal.tsx:64 const subLink = subId && subEnabled && subSettings?.subURI ? subSettings.subURI + subId : ''; ``` Server-side, the `subURI` **setting** wins when it is non-empty and `BuildSubURIBase(host) + subPath` is only the fallback (`internal/web/service/setting.go:1478-1494`). A backend that re-derives the URL from `resolveHost(c)` without reusing that same resolution order will encode a different URL than the QR sitting next to it — behind a reverse proxy or with `subDomain` set, silently. Reuse the resolution, do not re-implement it. **3. Consider a setting that turns the whole thing off.** Some operators forbid any outbound call from the panel host. A single boolean next to the existing Happ settings (`internal/web/service/setting.go:1345` maps `"Happ routing source"` → `SubRoutingRules`) is cheaper than an admin discovering the capability exists at all. Minor UI note: the modal is an Ant Design `Collapse` of sections (`ClientQrModal.tsx:240-248`), not the Standard/Happ switcher in your mockup — worth deciding whether Happ becomes another collapse panel or the modal grows a real segmented control. ## If you open the PR This is backend-plus-frontend, so the route contract chain applies in full: 1. the new `g.POST` needs a matching entry in `frontend/src/pages/api-docs/endpoints.ts`, then `make gen` — pinned both ways by `TestRouteRegistryContract` in `internal/web/routes_contract_test.go`; 2. any new struct crossing the API boundary must be added to the `StructAllow` allowlist in `tools/openapigen/main.go`, or it is silently dropped from the schemas and the OpenAPI build then fails; 3. the step nothing checks: copy `frontend/public/openapi.json` → `docs/public/openapi.json`, then `cd docs && pnpm gen:api`; 4. every new English i18n key goes into all 13 files under `internal/web/translation/` and must be referenced in the same commit. Two rules you do **not** need to satisfy, given the stateless design: no `runtime.Runtime` dispatch (nothing changes inbound or client state) and no migration in `internal/database/db.go` (nothing is persisted). Keeping it that way is what keeps the change small. 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#4328
No description provided.