[GH-ISSUE #5305] [Bug]: IPv6 address in generated share links is not wrapped in square brackets #3715

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

Originally created by @Bryanrios-a on GitHub (Jun 14, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/5305

Describe the bug

When the server address is an IPv6 literal, the generated share link cannot be parsed correctly.

Current generated link format is similar to:

vless://uuid@2001:db8::1:443?...

This is invalid because an IPv6 address used in a URI host field must be wrapped in square brackets when a port is included.

The expected format should be:

vless://uuid@[2001:db8::1]:443?...

Because the IPv6 address is not enclosed in [], client applications fail to import or parse the share link correctly.

The panel should automatically detect IPv6 addresses and wrap them in square brackets when generating share links or QR codes.

How to reproduce the problem

  1. Open the Inbounds page.
  2. Create or edit a VLESS/VMess/Trojan inbound.
  3. Set the server address / external address to an IPv6 address, for example 2001:db8::1.
  4. Copy the generated share link or scan the QR code.
  5. Import the link into a client.
  6. The client fails to parse the link because the IPv6 address is not wrapped in square brackets.

Expected behavior

If the share link host is an IPv6 address, it should be generated as:

[IPv6-address]:port

Example:

vless://uuid@[2001:db8::1]:443?...

IPv4 addresses and domain names should remain unchanged.

Actual behavior

No response

Relevant logs


Screenshots

No response

3x-ui version

3.3.1

Xray-core version

No response

How did you install 3x-ui?

install.sh script

Operating system

ubuntu24.04

Which parts of the panel are affected?

No response

Browser (only if it is a UI bug)

No response

Is the panel behind a reverse proxy or CDN?

None

Before submitting

  • I searched existing issues and this bug has not been reported.
  • I am running the latest released version of 3x-ui (or have verified the bug still exists on it).
  • This bug report is written in English.
  • I have redacted any sensitive data (tokens, real domains, client UUIDs).
Originally created by @Bryanrios-a on GitHub (Jun 14, 2026). Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/5305 ### Describe the bug When the server address is an IPv6 literal, the generated share link cannot be parsed correctly. Current generated link format is similar to: `vless://uuid@2001:db8::1:443?...` This is invalid because an IPv6 address used in a URI host field must be wrapped in square brackets when a port is included. The expected format should be: `vless://uuid@[2001:db8::1]:443?...` Because the IPv6 address is not enclosed in `[]`, client applications fail to import or parse the share link correctly. The panel should automatically detect IPv6 addresses and wrap them in square brackets when generating share links or QR codes. ### How to reproduce the problem 1. Open the `Inbounds` page. 2. Create or edit a VLESS/VMess/Trojan inbound. 3. Set the server address / external address to an IPv6 address, for example `2001:db8::1`. 4. Copy the generated share link or scan the QR code. 5. Import the link into a client. 6. The client fails to parse the link because the IPv6 address is not wrapped in square brackets. ### Expected behavior If the share link host is an IPv6 address, it should be generated as: `[IPv6-address]:port` Example: `vless://uuid@[2001:db8::1]:443?...` IPv4 addresses and domain names should remain unchanged. ### Actual behavior _No response_ ### Relevant logs ```shell ``` ### Screenshots _No response_ ### 3x-ui version 3.3.1 ### Xray-core version _No response_ ### How did you install 3x-ui? install.sh script ### Operating system ubuntu24.04 ### Which parts of the panel are affected? _No response_ ### Browser (only if it is a UI bug) _No response_ ### Is the panel behind a reverse proxy or CDN? None ### Before submitting - [x] I searched [existing issues](../issues?q=is%3Aissue) and this bug has not been reported. - [x] I am running the latest released version of 3x-ui (or have verified the bug still exists on it). - [x] This bug report is written in English. - [x] I have redacted any sensitive data (tokens, real domains, client UUIDs).
bsakaguchi 2026-10-31 20:34:26 +07:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

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

The bug is confirmed in the source. Both the Go subscription backend and the TypeScript frontend concatenate bare IPv6 addresses into URI authority strings without RFC 3986-required bracket wrapping, producing invalid links like vless://uuid@2001:db8::1:443?... instead of vless://uuid@[2001:db8::1]:443?....

Go backend — internal/sub/service.go

All non-VMess protocol generators (VLESS, Trojan, Shadowsocks, Hysteria2) call resolveInboundAddress(), which returns a plain string, then pass it directly into fmt.Sprintf:

// line 558 — VLESS
link := fmt.Sprintf("vless://%s@%s:%d", uuid, address, port)

// line 609 — Trojan
link := fmt.Sprintf("trojan://%s@%s:%d", password, address, port)

// line 674 — Shadowsocks
link := fmt.Sprintf("ss://%s@%s:%d", base64..., address, inbound.Port)

// line 790 — Hysteria2
link := fmt.Sprintf("%s://%s@%s:%d", protocol, auth, s.resolveInboundAddress(inbound), inbound.Port)

The external-proxy variants on lines 550, 601, 666, and 779 have the same problem with their dest parameter.

VMess is not affected because the address is encoded into a base64 JSON blob rather than placed directly in the URI authority.

TypeScript frontend — frontend/src/lib/xray/inbound-link.ts

The frontend link generators (genVlessLink, genTrojanLink, genShadowsocksLink, genHysteriaLink) construct template literals like:

const url = new URL(`vless://${clientId}@${address}:${port}`);

where address is a bare IPv6 string returned by normalizeShareHost(). This produces a malformed URL that the browser's URL constructor will misparse.

Root cause

Neither resolveInboundAddress() in Go nor normalizeShareHost() in TypeScript applies any IPv6 bracket logic before the address is interpolated into the URI string.

Suggested fix (for maintainers)

Go — replace %s:%d with a helper that uses net.JoinHostPort, which correctly brackets IPv6 addresses:

import "net"
// net.JoinHostPort("2001:db8::1", "443") → "[2001:db8::1]:443"
// net.JoinHostPort("192.0.2.1", "443")   → "192.0.2.1:443"
// net.JoinHostPort("example.com", "443") → "example.com:443"

link := fmt.Sprintf("vless://%s@%s", uuid, net.JoinHostPort(address, strconv.Itoa(port)))

TypeScript — either set url.hostname (the URL API handles brackets automatically when the hostname contains :) or wrap the address before interpolation:

const hostPart = address.includes(':') ? `[${address}]` : address;
const url = new URL(`vless://${clientId}@${hostPart}:${port}`);

Both paths need the fix applied to the external-proxy closures as well as the main link builder.

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

<!-- gh-comment-id:4700368370 --> @github-actions[bot] commented on GitHub (Jun 14, 2026): The bug is confirmed in the source. Both the Go subscription backend and the TypeScript frontend concatenate bare IPv6 addresses into URI authority strings without RFC 3986-required bracket wrapping, producing invalid links like `vless://uuid@2001:db8::1:443?...` instead of `vless://uuid@[2001:db8::1]:443?...`. **Go backend — `internal/sub/service.go`** All non-VMess protocol generators (VLESS, Trojan, Shadowsocks, Hysteria2) call `resolveInboundAddress()`, which returns a plain string, then pass it directly into `fmt.Sprintf`: ```go // line 558 — VLESS link := fmt.Sprintf("vless://%s@%s:%d", uuid, address, port) // line 609 — Trojan link := fmt.Sprintf("trojan://%s@%s:%d", password, address, port) // line 674 — Shadowsocks link := fmt.Sprintf("ss://%s@%s:%d", base64..., address, inbound.Port) // line 790 — Hysteria2 link := fmt.Sprintf("%s://%s@%s:%d", protocol, auth, s.resolveInboundAddress(inbound), inbound.Port) ``` The external-proxy variants on lines 550, 601, 666, and 779 have the same problem with their `dest` parameter. VMess is not affected because the address is encoded into a base64 JSON blob rather than placed directly in the URI authority. **TypeScript frontend — `frontend/src/lib/xray/inbound-link.ts`** The frontend link generators (`genVlessLink`, `genTrojanLink`, `genShadowsocksLink`, `genHysteriaLink`) construct template literals like: ```ts const url = new URL(`vless://${clientId}@${address}:${port}`); ``` where `address` is a bare IPv6 string returned by `normalizeShareHost()`. This produces a malformed URL that the browser's `URL` constructor will misparse. **Root cause** Neither `resolveInboundAddress()` in Go nor `normalizeShareHost()` in TypeScript applies any IPv6 bracket logic before the address is interpolated into the URI string. **Suggested fix (for maintainers)** Go — replace `%s:%d` with a helper that uses `net.JoinHostPort`, which correctly brackets IPv6 addresses: ```go import "net" // net.JoinHostPort("2001:db8::1", "443") → "[2001:db8::1]:443" // net.JoinHostPort("192.0.2.1", "443") → "192.0.2.1:443" // net.JoinHostPort("example.com", "443") → "example.com:443" link := fmt.Sprintf("vless://%s@%s", uuid, net.JoinHostPort(address, strconv.Itoa(port))) ``` TypeScript — either set `url.hostname` (the `URL` API handles brackets automatically when the hostname contains `:`) or wrap the address before interpolation: ```ts const hostPart = address.includes(':') ? `[${address}]` : address; const url = new URL(`vless://${clientId}@${hostPart}:${port}`); ``` Both paths need the fix applied to the external-proxy closures as well as the main link builder. *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#3715
No description provided.