[PR #5203] [MERGED] fix: derive JSON/Clash subscription URLs from configured subURI #5818

Closed
opened 2026-11-02 04:04:18 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/5203
Author: @w3struk
Created: 6/11/2026
Status: ✅ Merged
Merged: 6/11/2026
Merged by: @MHSanaei

Base: main ← Head: main


📝 Commits (3)

  • 7aa912a fix: derive JSON/Clash subscription URLs from configured subURI
  • c59192a Merge branch 'main' into main
  • fd14c6a fix(sub): fall back to request base when configured subURI is unparseable

📊 Changes

2 files changed (+75 additions, -2 deletions)

View changed files

📝 internal/sub/build_urls_test.go (+48 -0)
📝 internal/sub/service.go (+27 -2)

📄 Description

Description

When subURI is explicitly configured (reverse-proxy setup with Caddy/Nginx) but subJsonURI or subClashURI are not, BuildSubURIBase generates URLs using the raw sub-server port (2096) and HTTP scheme, producing broken links on the subscription info page (e.g., http://domain:2096/json/SUB_ID instead of https://domain/sub-xxx/json/SUB_ID).

Root Cause

BuildURLs (internal/sub/service.go:2112) uses BuildSubURIBase as the fallback base for all unconfigured subscription URLs. BuildSubURIBase (internal/web/service/setting.go:1003) has no knowledge of the reverse proxy — it always builds URLs from the raw sub-server settings (port 2096, no TLS → http://domain:2096).

The main subURL works correctly because buildSingleURL (line 2133) returns the explicitly configured subURI directly when set. But JSON and Clash URLs fall through to BuildSubURIBase when their respective URIs are empty.

Fix

In BuildURLs, when subURI is configured, extract its scheme+host via a new extractBaseFromURI helper and use that as the base for all unconfigured sibling URLs instead of BuildSubURIBase.

This ensures JSON and Clash Copy URLs on the subscription page inherit the correct scheme+host from the configured subURI:

  • Before: http://domain:2096/json/SUB_ID
  • After: https://domain/sub-xxx/json/SUB_ID

Files Changed

  • internal/sub/service.go: modified BuildURLs to derive base from configured subURI; added extractBaseFromURI helper
  • internal/sub/build_urls_test.go: added TestBuildURLs_DerivesJsonFromConfiguredSubURI

Testing

=== RUN   TestBuildURLs_NormalizesListenIP
--- PASS: TestBuildURLs_NormalizesListenIP (0.07s)
=== RUN   TestBuildURLs_UsesSubscriberDomain
--- PASS: TestBuildURLs_UsesSubscriberDomain (0.05s)
=== RUN   TestBuildURLs_EmptySubId
--- PASS: TestBuildURLs_EmptySubId (0.06s)
=== RUN   TestBuildURLs_DerivesJsonFromConfiguredSubURI
--- PASS: TestBuildURLs_DerivesJsonFromConfiguredSubURI (0.05s)

Fixes incorrect subscription page JSON/Clash URLs when running 3x-ui behind a reverse proxy with configured subURI.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/MHSanaei/3x-ui/pull/5203 **Author:** [@w3struk](https://github.com/w3struk) **Created:** 6/11/2026 **Status:** ✅ Merged **Merged:** 6/11/2026 **Merged by:** [@MHSanaei](https://github.com/MHSanaei) **Base:** `main` ← **Head:** `main` --- ### 📝 Commits (3) - [`7aa912a`](https://github.com/MHSanaei/3x-ui/commit/7aa912a467733b08bc137b8f8f047ac83bd2d3e6) fix: derive JSON/Clash subscription URLs from configured subURI - [`c59192a`](https://github.com/MHSanaei/3x-ui/commit/c59192ae6119749749a48e0d0b90316c78a006ca) Merge branch 'main' into main - [`fd14c6a`](https://github.com/MHSanaei/3x-ui/commit/fd14c6a7003b54e30aca59a1cd81ce8a9fccc595) fix(sub): fall back to request base when configured subURI is unparseable ### 📊 Changes **2 files changed** (+75 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `internal/sub/build_urls_test.go` (+48 -0) 📝 `internal/sub/service.go` (+27 -2) </details> ### 📄 Description ## Description When `subURI` is explicitly configured (reverse-proxy setup with Caddy/Nginx) but `subJsonURI` or `subClashURI` are not, `BuildSubURIBase` generates URLs using the raw sub-server port (2096) and HTTP scheme, producing broken links on the subscription info page (e.g., `http://domain:2096/json/SUB_ID` instead of `https://domain/sub-xxx/json/SUB_ID`). ## Root Cause `BuildURLs` (`internal/sub/service.go:2112`) uses `BuildSubURIBase` as the fallback base for all unconfigured subscription URLs. `BuildSubURIBase` (`internal/web/service/setting.go:1003`) has no knowledge of the reverse proxy — it always builds URLs from the raw sub-server settings (port 2096, no TLS → `http://domain:2096`). The main `subURL` works correctly because `buildSingleURL` (line 2133) returns the explicitly configured `subURI` directly when set. But JSON and Clash URLs fall through to `BuildSubURIBase` when their respective URIs are empty. ## Fix In `BuildURLs`, when `subURI` is configured, extract its scheme+host via a new `extractBaseFromURI` helper and use that as the base for all unconfigured sibling URLs instead of `BuildSubURIBase`. This ensures JSON and Clash Copy URLs on the subscription page inherit the correct scheme+host from the configured subURI: - Before: `http://domain:2096/json/SUB_ID` - After: `https://domain/sub-xxx/json/SUB_ID` ### Files Changed - `internal/sub/service.go`: modified `BuildURLs` to derive base from configured subURI; added `extractBaseFromURI` helper - `internal/sub/build_urls_test.go`: added `TestBuildURLs_DerivesJsonFromConfiguredSubURI` ### Testing ``` === RUN TestBuildURLs_NormalizesListenIP --- PASS: TestBuildURLs_NormalizesListenIP (0.07s) === RUN TestBuildURLs_UsesSubscriberDomain --- PASS: TestBuildURLs_UsesSubscriberDomain (0.05s) === RUN TestBuildURLs_EmptySubId --- PASS: TestBuildURLs_EmptySubId (0.06s) === RUN TestBuildURLs_DerivesJsonFromConfiguredSubURI --- PASS: TestBuildURLs_DerivesJsonFromConfiguredSubURI (0.05s) ``` ### Related Issue Fixes incorrect subscription page JSON/Clash URLs when running 3x-ui behind a reverse proxy with configured subURI. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 04:04:18 +07:00
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#5818
No description provided.