[PR #6369] [MERGED] fix(mtproto): use hosts for public share links #6237

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

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/6369
Author: @samssh
Created: 8/30/2026
Status: ✅ Merged
Merged: 9/8/2026
Merged by: @MHSanaei

Base: main ← Head: codex/fix-mtproto-host-share-links


📝 Commits (7)

  • 77a6195 fix(mtproto): use hosts for public share links
  • 0c085ad fix(mtproto): keep host share links lossless and consistent
  • 11c8469 Merge branch 'main' into codex/fix-mtproto-host-share-links
  • 6066c3c Merge branch 'main' into codex/fix-mtproto-host-share-links
  • 7b7c834 fix(mtproto): migrate legacy share address past unusable hosts
  • 604373d Merge branch 'main' into codex/fix-mtproto-host-share-links
  • 735aade fix(inbounds): wait for the hosts list before building mtproto links

📊 Changes

21 files changed (+735 additions, -76 deletions)

View changed files

📝 docs/content/docs/en/reference/api/clients.mdx (+14 -14)
📝 docs/public/openapi.json (+1 -1)
📝 frontend/public/openapi.json (+1 -1)
📝 frontend/src/lib/hosts/host-link.ts (+50 -1)
📝 frontend/src/pages/api-docs/endpoints.ts (+1 -1)
📝 frontend/src/pages/inbounds/InboundsPage.tsx (+42 -9)
📝 frontend/src/pages/inbounds/form/InboundFormModal.tsx (+42 -31)
📝 frontend/src/pages/inbounds/info/InboundInfoModal.tsx (+14 -2)
📝 frontend/src/pages/inbounds/info/types.ts (+2 -0)
📝 frontend/src/pages/inbounds/qr/QrCodeModal.tsx (+18 -4)
📝 frontend/src/test/host-link.test.ts (+68 -1)
📝 frontend/src/test/inbound-form-modal.test.tsx (+35 -0)
📝 internal/database/db.go (+55 -0)
📝 internal/database/host_migration_test.go (+165 -0)
📝 internal/sub/links.go (+5 -0)
📝 internal/sub/links_test.go (+21 -0)
📝 internal/sub/service.go (+23 -11)
📝 internal/sub/service_mtproto_test.go (+65 -0)
📝 internal/web/service/inbound.go (+29 -0)
📝 internal/web/service/inbound_import_external_proxy_test.go (+72 -0)

...and 1 more files

📄 Description

Generate MTProto subscription, client, copy, QR, and export links from managed Hosts so reverse-proxied public ports are advertised correctly. Migrate the redundant legacy custom share address into a Host and keep old imports compatible.

Closes #5126.

Summary

Fix MTProto share-link generation to use managed Hosts, allowing a public host and port such as proxy.example.com:443 while MTG listens internally on another port.

This also removes the redundant custom share-address option from MTProto inbounds and migrates legacy values to Hosts.

Why

MTProto links always used the inbound listener port, so reverse-proxied deployments exposed an internal port such as 4060 instead of the public port 443.

Managed Hosts are already the canonical mechanism for advertising alternative endpoints. This change applies them consistently to MTProto subscription links, client links, Copy/QR output, and exports.

Closes #5126.
Refs #5534.

Type of change

  • Bug fix
  • New feature
  • Refactoring (no behavior change)
  • Documentation
  • Tests only
  • Build / CI / tooling
  • Other

Areas affected

  • Frontend (UI / panel pages)
  • Backend (API endpoints, login, settings)
  • Xray config generation
  • Subscription (share links / Clash / JSON)
  • Statistics / traffic counters
  • Database / migrations
  • Install / upgrade script
  • Docker image
  • Multi-node (sub-nodes)
  • Telegram bot

How was this tested?

Added regression coverage for the following cases:

  • An MTProto inbound listening on port 4060 with a Host configured as proxy.example.com:443 generates:
    • server=proxy.example.com
    • port=443
  • Hosts without an explicit port inherit the inbound port.
  • Disabled, unrelated, and raw-excluded Hosts are ignored.
  • Subscription and per-client link providers both use Host endpoints.
  • Legacy MTProto custom share addresses migrate to Hosts.
  • Existing Hosts are preserved without creating duplicates.
  • Re-running the migration is idempotent.
  • Legacy inbound imports convert MTProto custom share addresses to Hosts.
  • The MTProto form no longer displays the custom share-address controls.

Commands run:

go test ./internal/database -run 'TestMigrateMtprotoCustomShareAddr' -count=1
go test ./internal/web/service -run 'TestAddInboundImportConvertsMtprotoCustomShareAddrToHost|TestNormalizeInboundShareAddressStrict' -count=1
go test ./internal/sub -run 'TestGenMtproto|TestGetSubsMtproto' -count=1

cd frontend
npm run lint
npm run format:check
npm run typecheck
npm test
npm run build

Frontend result:

Test Files  126 passed (126)
Tests       1214 passed (1214)

make test-go passed all affected packages. One unrelated timing-sensitive test, TestEnsureHotReloadKeepsProcess, failed once during the full shuffled run and passed when rerun independently.

Screenshots / recordings

Not included. The UI change only removes the redundant Share address strategy and Custom share address controls from the MTProto inbound form.

Breaking changes

None.

Existing MTProto inbounds using a custom share address are migrated automatically:

  • If no Host exists, a Host is created from the custom address.
  • Its port remains inherited from the inbound.
  • If Hosts already exist, no duplicate Host is created.
  • The legacy custom share-address fields are reset to the default listen strategy.
  • Legacy imported inbound configurations receive the same conversion.

No manual migration or API change is required.

Checklist

  • I tested the change locally and confirmed the described behavior.
  • I added or updated tests for the new behavior (when applicable).
  • go build ./... and the test suite pass locally.
  • For frontend changes: npm run lint, npm run typecheck, and npm run build pass.
  • I updated the Wiki / README / API docs if user-facing behavior changed.
  • My commits follow the project's existing message style.
  • I have no unrelated changes mixed into this PR.

🔄 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/6369 **Author:** [@samssh](https://github.com/samssh) **Created:** 8/30/2026 **Status:** ✅ Merged **Merged:** 9/8/2026 **Merged by:** [@MHSanaei](https://github.com/MHSanaei) **Base:** `main` ← **Head:** `codex/fix-mtproto-host-share-links` --- ### 📝 Commits (7) - [`77a6195`](https://github.com/MHSanaei/3x-ui/commit/77a61951b7bd43761281c2f7167eda05ec6c7869) fix(mtproto): use hosts for public share links - [`0c085ad`](https://github.com/MHSanaei/3x-ui/commit/0c085ad10cbbb12287a8929d55f517a7d5faa8f2) fix(mtproto): keep host share links lossless and consistent - [`11c8469`](https://github.com/MHSanaei/3x-ui/commit/11c84693ff581797c4c45d414861476b2ce23ed3) Merge branch 'main' into codex/fix-mtproto-host-share-links - [`6066c3c`](https://github.com/MHSanaei/3x-ui/commit/6066c3cb27d56e6f8e34da0f397d699037e991f9) Merge branch 'main' into codex/fix-mtproto-host-share-links - [`7b7c834`](https://github.com/MHSanaei/3x-ui/commit/7b7c83463494784e0ecd37bf8f2b0d490f9b0161) fix(mtproto): migrate legacy share address past unusable hosts - [`604373d`](https://github.com/MHSanaei/3x-ui/commit/604373d084650e534b1f94d8319bb1b421f88632) Merge branch 'main' into codex/fix-mtproto-host-share-links - [`735aade`](https://github.com/MHSanaei/3x-ui/commit/735aadecd1521fe73071f847fcf255d965c45b98) fix(inbounds): wait for the hosts list before building mtproto links ### 📊 Changes **21 files changed** (+735 additions, -76 deletions) <details> <summary>View changed files</summary> 📝 `docs/content/docs/en/reference/api/clients.mdx` (+14 -14) 📝 `docs/public/openapi.json` (+1 -1) 📝 `frontend/public/openapi.json` (+1 -1) 📝 `frontend/src/lib/hosts/host-link.ts` (+50 -1) 📝 `frontend/src/pages/api-docs/endpoints.ts` (+1 -1) 📝 `frontend/src/pages/inbounds/InboundsPage.tsx` (+42 -9) 📝 `frontend/src/pages/inbounds/form/InboundFormModal.tsx` (+42 -31) 📝 `frontend/src/pages/inbounds/info/InboundInfoModal.tsx` (+14 -2) 📝 `frontend/src/pages/inbounds/info/types.ts` (+2 -0) 📝 `frontend/src/pages/inbounds/qr/QrCodeModal.tsx` (+18 -4) 📝 `frontend/src/test/host-link.test.ts` (+68 -1) 📝 `frontend/src/test/inbound-form-modal.test.tsx` (+35 -0) 📝 `internal/database/db.go` (+55 -0) 📝 `internal/database/host_migration_test.go` (+165 -0) 📝 `internal/sub/links.go` (+5 -0) 📝 `internal/sub/links_test.go` (+21 -0) 📝 `internal/sub/service.go` (+23 -11) 📝 `internal/sub/service_mtproto_test.go` (+65 -0) 📝 `internal/web/service/inbound.go` (+29 -0) 📝 `internal/web/service/inbound_import_external_proxy_test.go` (+72 -0) _...and 1 more files_ </details> ### 📄 Description Generate MTProto subscription, client, copy, QR, and export links from managed Hosts so reverse-proxied public ports are advertised correctly. Migrate the redundant legacy custom share address into a Host and keep old imports compatible. Closes #5126. ## Summary Fix MTProto share-link generation to use managed Hosts, allowing a public host and port such as `proxy.example.com:443` while MTG listens internally on another port. This also removes the redundant custom share-address option from MTProto inbounds and migrates legacy values to Hosts. ## Why MTProto links always used the inbound listener port, so reverse-proxied deployments exposed an internal port such as `4060` instead of the public port `443`. Managed Hosts are already the canonical mechanism for advertising alternative endpoints. This change applies them consistently to MTProto subscription links, client links, Copy/QR output, and exports. Closes #5126. Refs #5534. ## Type of change - [x] Bug fix - [ ] New feature - [ ] Refactoring (no behavior change) - [ ] Documentation - [ ] Tests only - [ ] Build / CI / tooling - [ ] Other ## Areas affected - [x] Frontend (UI / panel pages) - [x] Backend (API endpoints, login, settings) - [ ] Xray config generation - [x] Subscription (share links / Clash / JSON) - [ ] Statistics / traffic counters - [x] Database / migrations - [ ] Install / upgrade script - [ ] Docker image - [ ] Multi-node (sub-nodes) - [ ] Telegram bot ## How was this tested? Added regression coverage for the following cases: - An MTProto inbound listening on port `4060` with a Host configured as `proxy.example.com:443` generates: - `server=proxy.example.com` - `port=443` - Hosts without an explicit port inherit the inbound port. - Disabled, unrelated, and raw-excluded Hosts are ignored. - Subscription and per-client link providers both use Host endpoints. - Legacy MTProto custom share addresses migrate to Hosts. - Existing Hosts are preserved without creating duplicates. - Re-running the migration is idempotent. - Legacy inbound imports convert MTProto custom share addresses to Hosts. - The MTProto form no longer displays the custom share-address controls. Commands run: ```bash go test ./internal/database -run 'TestMigrateMtprotoCustomShareAddr' -count=1 go test ./internal/web/service -run 'TestAddInboundImportConvertsMtprotoCustomShareAddrToHost|TestNormalizeInboundShareAddressStrict' -count=1 go test ./internal/sub -run 'TestGenMtproto|TestGetSubsMtproto' -count=1 cd frontend npm run lint npm run format:check npm run typecheck npm test npm run build ``` Frontend result: ```text Test Files 126 passed (126) Tests 1214 passed (1214) ``` `make test-go` passed all affected packages. One unrelated timing-sensitive test, `TestEnsureHotReloadKeepsProcess`, failed once during the full shuffled run and passed when rerun independently. ## Screenshots / recordings Not included. The UI change only removes the redundant `Share address strategy` and `Custom share address` controls from the MTProto inbound form. ## Breaking changes None. Existing MTProto inbounds using a custom share address are migrated automatically: - If no Host exists, a Host is created from the custom address. - Its port remains inherited from the inbound. - If Hosts already exist, no duplicate Host is created. - The legacy custom share-address fields are reset to the default listen strategy. - Legacy imported inbound configurations receive the same conversion. No manual migration or API change is required. ## Checklist - [x] I tested the change locally and confirmed the described behavior. - [x] I added or updated tests for the new behavior (when applicable). - [ ] `go build ./...` and the test suite pass locally. - [x] For frontend changes: `npm run lint`, `npm run typecheck`, and `npm run build` pass. - [ ] I updated the Wiki / README / API docs if user-facing behavior changed. - [x] My commits follow the project's existing message style. - [x] I have no unrelated changes mixed into this PR. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 04:07:19 +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#6237
No description provided.