mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[PR #5310] [MERGED] fix(links): bracket ipv6 hosts in share links and qr codes #5845
Labels
No labels
backlog
bug
clarification needed
documentation
duplicate
enhancement
github_actions
good first issue
invalid
javascript
New Feature
PR welcomed
pull-request
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
MHSanaei/3x-ui#5845
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 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)
46e7eb8fix(sub): bracket ipv6 hosts in share links24e2254fix(frontend): bracket ipv6 hosts in share links2e1b028Merge 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 intoscheme://user@host:port, producing invalid links for any inbound whose advertised endpoint is an IPv6 address.Type of change
Areas affected
How was this tested?
go build ./...— passes.go test ./internal/sub/...— passes.cd frontend && npm run typecheck— passes.cd frontend && npm run lint— passes.cd frontend && npm run test— passes.new URL(link).hostfor VLESS, Trojan, Shadowsocks, Hysteria2, and WireGuard share links using bare IPv6, bracketed IPv6, IPv4, and hostname inputs.Implementation details
Backend (Go):
joinHostPort()helper ininternal/sub/service.gothat strips any pre-existing brackets and usesnet.JoinHostPort()to produce RFC-compliant[host]:portauthorities for IPv6 while leaving IPv4 and hostnames unchanged.%s:%dauthority interpolations in VLESS, Trojan, Shadowsocks, and Hysteria2 link generators (including external-proxy variants).addfield is a bare address inside a base64 JSON payload, not a URI authority.Frontend (TypeScript):
formatUrlHost()helper infrontend/src/lib/xray/inbound-link.tsthat strips existing brackets and re-adds them only when the host contains a colon (IPv6).URLconstructors ingenVlessLink,genTrojanLink,genShadowsocksLink,genHysteriaLink, andgenWireguardLink.Tests:
TestJoinHostPortininternal/sub/service_test.gocovering IPv4, IPv6, already-bracketed IPv6, and hostname inputs.frontend/src/test/inbound-link.test.tsasserting[2001:db8::1]:443for every affected protocol and a regression check that IPv4/hostname hosts remain unbracketed.Files changed
internal/sub/service.gointernal/sub/service_test.gofrontend/src/lib/xray/inbound-link.tsfrontend/src/test/inbound-link.test.tsScreenshots / recordings
Breaking changes
None.
Checklist
go build ./...and the test suite pass locally.npm run typecheckandnpm run buildpass.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.