[GH-ISSUE #5570] [Feature]: Clash and XRay subscriptions on one URL #3891

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

Originally created by @indx0 on GitHub (Jun 25, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/5570

Right now clash and XRay subs are on different URLs, which is uncomfortable for users and for administrators, moving from other panels with this functionality.

Describe the solution you'd like

The client can be determined with user agent, which is passed when getting a subscription. The regex expressions used for client detection can be found in remnawave or pasarguard source code.

Alternatives you've considered

This can be done via a reverse proxy, but since 3x-ui is a user-friendly panel, it would be better to add this in panel directly, like everywhere else.

Concrete use case

No response

Mockups, screenshots, or examples

No response

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 @indx0 on GitHub (Jun 25, 2026). Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/5570 ### Is your feature request related to a problem? Right now clash and XRay subs are on different URLs, which is uncomfortable for users and for administrators, moving from other panels with this functionality. ### Describe the solution you'd like The client can be determined with user agent, which is passed when getting a subscription. The regex expressions used for client detection can be found in remnawave or pasarguard source code. ### Alternatives you've considered This can be done via a reverse proxy, but since 3x-ui is a user-friendly panel, it would be better to add this in panel directly, like everywhere else. ### Concrete use case _No response_ ### Mockups, screenshots, or examples _No response_ ### 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. - [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:35:41 +07:00
Author
Owner

@github-actions[bot] commented on GitHub (Jun 25, 2026):

The panel currently exposes three fully separate URL prefixes for subscription formats, with no user-agent routing between them. This is confirmed in internal/sub/controller.go (initRouter, lines 132–146): the subs handler serves raw base64 share links, subJsons serves the JSON config, and subClashs serves Clash YAML — each registered under its own path group (/sub/, /json/, /clash/ by default, all configurable in Settings).

What implementing this would require

The cleanest approach would be to add an optional handler on the existing /sub/<subid> path that inspects the User-Agent header before delegating:

  1. If User-Agent matches a known Clash/Mihomo pattern → call SubClashService.GetClash and return YAML.
  2. If it matches a known JSON-capable client pattern → call SubJsonService.GetJson and return JSON.
  3. Otherwise → fall through to the current base64 share-link output.

The existing per-format paths would remain active alongside, so existing client configurations would not break.

Implementation notes for a contributor

  • The user-agent matching logic would live in internal/sub/controller.go, most naturally at the top of subs(), before the current branch on wantsHTML.
  • The SubClashService and SubJsonService are already members of SUBController, so no new wiring is needed to call them from subs().
  • A new setting (e.g., subAutoDetect bool) could gate the feature so admins can opt out if they want strict path separation.
  • The YAML response must set Content-Type: application/yaml and the JSON response application/json, matching what subClashs and subJsons already do.
  • For the user-agent regex patterns, the referenced projects (remnawave, pasarguard) are reasonable prior art to study. Clash Meta/Mihomo, Stash, Surfboard, and similar clients all emit distinctive User-Agent strings.

This is a reasonable quality-of-life feature. Whether and when it is added is up to the maintainers.

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

<!-- gh-comment-id:4802620403 --> @github-actions[bot] commented on GitHub (Jun 25, 2026): The panel currently exposes three fully separate URL prefixes for subscription formats, with no user-agent routing between them. This is confirmed in `internal/sub/controller.go` (`initRouter`, lines 132–146): the `subs` handler serves raw base64 share links, `subJsons` serves the JSON config, and `subClashs` serves Clash YAML — each registered under its own path group (`/sub/`, `/json/`, `/clash/` by default, all configurable in Settings). **What implementing this would require** The cleanest approach would be to add an optional handler on the existing `/sub/<subid>` path that inspects the `User-Agent` header before delegating: 1. If `User-Agent` matches a known Clash/Mihomo pattern → call `SubClashService.GetClash` and return YAML. 2. If it matches a known JSON-capable client pattern → call `SubJsonService.GetJson` and return JSON. 3. Otherwise → fall through to the current base64 share-link output. The existing per-format paths would remain active alongside, so existing client configurations would not break. **Implementation notes for a contributor** - The user-agent matching logic would live in `internal/sub/controller.go`, most naturally at the top of `subs()`, before the current branch on `wantsHTML`. - The `SubClashService` and `SubJsonService` are already members of `SUBController`, so no new wiring is needed to call them from `subs()`. - A new setting (e.g., `subAutoDetect bool`) could gate the feature so admins can opt out if they want strict path separation. - The YAML response must set `Content-Type: application/yaml` and the JSON response `application/json`, matching what `subClashs` and `subJsons` already do. - For the user-agent regex patterns, the referenced projects (remnawave, pasarguard) are reasonable prior art to study. Clash Meta/Mihomo, Stash, Surfboard, and similar clients all emit distinctive `User-Agent` strings. This is a reasonable quality-of-life feature. Whether and when it is added is up to the maintainers. *This reply was generated automatically; a maintainer may follow up.*
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#3891
No description provided.