Skip to content

Commit 8ea4a88

Browse files
fix(server): Tailscale Serve forwards to the address a specific --host binds (pingdotgg#34741)
1 parent d353fba commit 8ea4a88

2 files changed

Lines changed: 17 additions & 3 deletions

File tree

‎apps/server/src/startupAccess.test.ts‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import type * as NodeOS from "node:os";
22

33
import { describe, expect, it } from "@effect/vitest";
4+
import * as NetAddress from "effect/net/NetAddress";
45

56
import {
67
acceptsPrivateNetworkConnection,
8+
loopbackUrlHostForAddress,
79
resolveHeadlessConnectionString,
810
} from "./startupAccess.ts";
911

@@ -55,6 +57,18 @@ it("prefers a LAN address over a tailnet one for a private-network pairing URL",
5557
).toBe("http://192.168.1.42:3773");
5658
});
5759

60+
it("targets the bound interface when the listener binds a specific address", () => {
61+
const hostFor = (ip: string) =>
62+
loopbackUrlHostForAddress(NetAddress.inetAddressFromIpStringUnsafe(ip, 3773));
63+
64+
expect(hostFor("0.0.0.0")).toBe("127.0.0.1");
65+
expect(hostFor("::")).toBe("127.0.0.1");
66+
expect(hostFor("::1")).toBe("[::1]");
67+
expect(hostFor("127.0.0.1")).toBe("127.0.0.1");
68+
expect(hostFor("127.0.0.2")).toBe("127.0.0.2");
69+
expect(hostFor("100.101.102.103")).toBe("100.101.102.103");
70+
});
71+
5872
describe("acceptsPrivateNetworkConnection", () => {
5973
const accepts = (localAddress: string | undefined, remoteAddress: string | undefined) =>
6074
acceptsPrivateNetworkConnection({ localAddress, remoteAddress });

‎apps/server/src/startupAccess.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ export const acceptsPrivateNetworkConnection = (socket: {
7171
);
7272

7373
export const loopbackUrlHostForAddress = (address: NetAddress.InetAddress): string =>
74-
address._tag === "InetAddressV6" && NetAddress.isLoopback(address.address)
75-
? "[::1]"
76-
: "127.0.0.1";
74+
NetAddress.isUnspecified(address.address)
75+
? "127.0.0.1"
76+
: NetAddress.formatUrlHostString(NetAddress.formatIp(address.address));
7777

7878
const normalizeHost = (host: string): string =>
7979
host.startsWith("[") && host.endsWith("]") ? host.slice(1, -1) : host;

0 commit comments

Comments
 (0)