[PR #5310] [MERGED] fix(links): bracket ipv6 hosts in share links and qr codes #5845

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

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/5310
Author: @NikanZeyaei
Created: 6/14/2026
Status: ✅ Merged
Merged: 6/14/2026
Merged by: @MHSanaei

Base: main ← Head: fix/ipv6-share-link-brackets


📝 Commits (3)

  • 46e7eb8 fix(sub): bracket ipv6 hosts in share links
  • 24e2254 fix(frontend): bracket ipv6 hosts in share links
  • 2e1b028 Merge branch 'main' into fix/ipv6-share-link-brackets

📊 Changes

4 files changed (+135 additions, -13 deletions)

View changed files

📝 frontend/src/lib/xray/inbound-link.ts (+13 -5)
📝 frontend/src/test/inbound-link.test.ts (+85 -0)
📝 internal/sub/service.go (+18 -8)
📝 internal/sub/service_test.go (+19 -0)

📄 Description

Summary

Fixes https://github.com/MHSanaei/3x-ui/issues/5305

Fixes IPv6 share links and QR codes by wrapping bare IPv6 literals in square brackets when they are interpolated into URI authorities. Without brackets, clients cannot parse links like vless://uuid@2001:db8::1:443?... because the colons in the address are mistaken for the host/port separator.

Why

RFC 3986 requires IPv6 addresses in URI authorities to be enclosed in square brackets ([2001:db8::1]:443). The panel's Go subscription backend and TypeScript frontend were both concatenating the resolved host directly into scheme://user@host:port, producing invalid links for any inbound whose advertised endpoint is an IPv6 address.

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?

  1. go build ./... — passes.
  2. go test ./internal/sub/... — passes.
  3. cd frontend && npm run typecheck — passes.
  4. cd frontend && npm run lint — passes.
  5. cd frontend && npm run test — passes.
  6. Verified link authority parsing with new URL(link).host for VLESS, Trojan, Shadowsocks, Hysteria2, and WireGuard share links using bare IPv6, bracketed IPv6, IPv4, and hostname inputs.

Implementation details

Backend (Go):

  • Added joinHostPort() helper in internal/sub/service.go that strips any pre-existing brackets and uses net.JoinHostPort() to produce RFC-compliant [host]:port authorities for IPv6 while leaving IPv4 and hostnames unchanged.
  • Replaced all bare %s:%d authority interpolations in VLESS, Trojan, Shadowsocks, and Hysteria2 link generators (including external-proxy variants).
  • VMess JSON links are intentionally unchanged because the add field is a bare address inside a base64 JSON payload, not a URI authority.

Frontend (TypeScript):

  • Added formatUrlHost() helper in frontend/src/lib/xray/inbound-link.ts that strips existing brackets and re-adds them only when the host contains a colon (IPv6).
  • Applied the helper to the URL constructors in genVlessLink, genTrojanLink, genShadowsocksLink, genHysteriaLink, and genWireguardLink.

Tests:

  • Added TestJoinHostPort in internal/sub/service_test.go covering IPv4, IPv6, already-bracketed IPv6, and hostname inputs.
  • Added a dedicated IPv6 describe block in frontend/src/test/inbound-link.test.ts asserting [2001:db8::1]:443 for every affected protocol and a regression check that IPv4/hostname hosts remain unbracketed.

Files changed

  • internal/sub/service.go
  • internal/sub/service_test.go
  • frontend/src/lib/xray/inbound-link.ts
  • frontend/src/test/inbound-link.test.ts

Screenshots / recordings

Breaking changes

None.

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 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/5310 **Author:** [@NikanZeyaei](https://github.com/NikanZeyaei) **Created:** 6/14/2026 **Status:** ✅ Merged **Merged:** 6/14/2026 **Merged by:** [@MHSanaei](https://github.com/MHSanaei) **Base:** `main` ← **Head:** `fix/ipv6-share-link-brackets` --- ### 📝 Commits (3) - [`46e7eb8`](https://github.com/MHSanaei/3x-ui/commit/46e7eb8c78f37e06efaefdbb12f1456a1824aa52) fix(sub): bracket ipv6 hosts in share links - [`24e2254`](https://github.com/MHSanaei/3x-ui/commit/24e22546977a7c274e44217be4c7b98a0c457a37) fix(frontend): bracket ipv6 hosts in share links - [`2e1b028`](https://github.com/MHSanaei/3x-ui/commit/2e1b028ed9831bec43cd587f475013306c378736) Merge branch 'main' into fix/ipv6-share-link-brackets ### 📊 Changes **4 files changed** (+135 additions, -13 deletions) <details> <summary>View changed files</summary> 📝 `frontend/src/lib/xray/inbound-link.ts` (+13 -5) 📝 `frontend/src/test/inbound-link.test.ts` (+85 -0) 📝 `internal/sub/service.go` (+18 -8) 📝 `internal/sub/service_test.go` (+19 -0) </details> ### 📄 Description ## Summary Fixes https://github.com/MHSanaei/3x-ui/issues/5305 Fixes IPv6 share links and QR codes by wrapping bare IPv6 literals in square brackets when they are interpolated into URI authorities. Without brackets, clients cannot parse links like `vless://uuid@2001:db8::1:443?...` because the colons in the address are mistaken for the host/port separator. ## Why RFC 3986 requires IPv6 addresses in URI authorities to be enclosed in square brackets (`[2001:db8::1]:443`). The panel's Go subscription backend and TypeScript frontend were both concatenating the resolved host directly into `scheme://user@host:port`, producing invalid links for any inbound whose advertised endpoint is an IPv6 address. ## 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 - [ ] Database / migrations - [ ] Install / upgrade script - [ ] Docker image - [ ] Multi-node (sub-nodes) - [ ] Telegram bot ## How was this tested? 1. `go build ./...` — passes. 2. `go test ./internal/sub/...` — passes. 3. `cd frontend && npm run typecheck` — passes. 4. `cd frontend && npm run lint` — passes. 5. `cd frontend && npm run test` — passes. 6. Verified link authority parsing with `new URL(link).host` for VLESS, Trojan, Shadowsocks, Hysteria2, and WireGuard share links using bare IPv6, bracketed IPv6, IPv4, and hostname inputs. ## Implementation details **Backend (Go):** - Added `joinHostPort()` helper in `internal/sub/service.go` that strips any pre-existing brackets and uses `net.JoinHostPort()` to produce RFC-compliant `[host]:port` authorities for IPv6 while leaving IPv4 and hostnames unchanged. - Replaced all bare `%s:%d` authority interpolations in VLESS, Trojan, Shadowsocks, and Hysteria2 link generators (including external-proxy variants). - VMess JSON links are intentionally unchanged because the `add` field is a bare address inside a base64 JSON payload, not a URI authority. **Frontend (TypeScript):** - Added `formatUrlHost()` helper in `frontend/src/lib/xray/inbound-link.ts` that strips existing brackets and re-adds them only when the host contains a colon (IPv6). - Applied the helper to the `URL` constructors in `genVlessLink`, `genTrojanLink`, `genShadowsocksLink`, `genHysteriaLink`, and `genWireguardLink`. **Tests:** - Added `TestJoinHostPort` in `internal/sub/service_test.go` covering IPv4, IPv6, already-bracketed IPv6, and hostname inputs. - Added a dedicated IPv6 describe block in `frontend/src/test/inbound-link.test.ts` asserting `[2001:db8::1]:443` for every affected protocol and a regression check that IPv4/hostname hosts remain unbracketed. ## Files changed - `internal/sub/service.go` - `internal/sub/service_test.go` - `frontend/src/lib/xray/inbound-link.ts` - `frontend/src/test/inbound-link.test.ts` ## Screenshots / recordings ## Breaking changes None. ## Checklist - [x] I tested the change locally and confirmed the described behavior. - [x] I added or updated tests for the new behavior (when applicable). - [x] `go build ./...` and the test suite pass locally. - [x] For frontend changes: `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:04:29 +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#5845
No description provided.