fix(wireguard): preserve all Allowed IPs in share link, .conf, and subscription (#6051)

The WireGuard client address is stored end-to-end as a string slice
(model.AllowedIPs []string, comma-split/joined in the DB), and the UI
hint documents comma-separated multi-value input. Three export paths
only read index [0], silently dropping every address after the first
(e.g. a dual-stack IPv4+IPv6 client never receives its second address):

- genWireguardLink share link address param (inbound-link.ts)
- genWireguardConfig .conf Address line (inbound-link.ts)
- SubService.genWireguardLink raw subscription address (service.go)

The sibling JSON and Clash subscriptions already emit the full slice,
and WireguardPeerFromClient passes the whole slice into the real Xray
peer config, so only the exported text was wrong. Join all entries,
matching the model's strings.Join(..., ",") convention for the link
params and the ', '-joined AllowedIPs line already used a few lines
below in genWireguardConfig.

Fixes #6031
This commit is contained in:
H-TTTTT
2026-07-21 21:50:16 +08:00
committed by GitHub
parent 22ff07b24b
commit c80e5e276b
4 changed files with 72 additions and 5 deletions
+3 -3
View File
@@ -822,8 +822,8 @@ export function genWireguardLink(input: GenWireguardLinkInput): string {
? Wireguard.generateKeypair(settings.secretKey).publicKey
: '';
if (pubKey.length > 0) url.searchParams.set('publickey', pubKey);
if (peer.allowedIPs.length > 0 && peer.allowedIPs[0]) {
url.searchParams.set('address', peer.allowedIPs[0]);
if (peer.allowedIPs.length > 0) {
url.searchParams.set('address', peer.allowedIPs.join(','));
}
if (typeof settings.mtu === 'number' && settings.mtu > 0) {
url.searchParams.set('mtu', String(settings.mtu));
@@ -850,7 +850,7 @@ export function genWireguardConfig(input: GenWireguardLinkInput): string {
let txt = `[Interface]\n`;
txt += `PrivateKey = ${peer.privateKey ?? ''}\n`;
txt += `Address = ${peer.allowedIPs[0] ?? ''}\n`;
txt += `Address = ${peer.allowedIPs.join(', ')}\n`;
txt += `DNS = ${settings.dns || '1.1.1.1, 1.0.0.1'}\n`;
if (typeof settings.mtu === 'number' && settings.mtu > 0) {
txt += `MTU = ${settings.mtu}\n`;
+37
View File
@@ -308,6 +308,43 @@ describe('genWireguardLink + genWireguardConfig', () => {
}
});
describe('genWireguardLink + genWireguardConfig multi allowedIPs', () => {
const settings = {
secretKey: '',
mtu: 1280,
dns: '',
peers: [
{
privateKey: 'cLI',
allowedIPs: ['10.0.0.2/32', 'fd00::2/128'],
},
],
} as unknown as WireguardInboundSettings;
it('joins every allowed IP into the share-link address param', () => {
const link = genWireguardLink({
settings,
address: 'wg.example.test',
port: 51820,
remark: 'dual-stack',
peerIndex: 0,
});
const u = new URL(link);
expect(u.searchParams.get('address')).toBe('10.0.0.2/32,fd00::2/128');
});
it('joins every allowed IP into the .conf Address line', () => {
const config = genWireguardConfig({
settings,
address: 'wg.example.test',
port: 51820,
remark: 'dual-stack',
peerIndex: 0,
});
expect(config).toContain('Address = 10.0.0.2/32, fd00::2/128\n');
});
});
describe('resolveAddr precedence', () => {
const baseInbound = {
listen: '',