@devries-cameron20 / t3code-1 / commits / 368b4feb6d
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(server): IPv4-mapped loopback SSH device targets count as this machine (#35774)

Julius Marminge committed Nov 12, 2026 at 17:50 UTC 368b4feb6dea43e93ed99a0a0781c3654e5d49c9
2 files changed +22 -4
apps/server/src/device/localSshDeviceHost.test.ts
+2 -1
@@ -27,6 +27,7 @@ const spawner = ChildProcessSpawner.make((command) =>
27 remote: "hostname 192.0.2.1\nport 22\n",
28 loopback: "hostname 127.0.1.1\nport 22\n",
29 ipv6: "hostname ::1\nport 22\n",
30 + mapped: "hostname ::ffff:127.0.0.1\nport 22\n",
31 forwarded: "hostname 127.0.0.1\nport 2222\n",
32 proxy: "hostname 127.0.0.1\nport 22\nproxyjump bastion\n",
33 command: "hostname 127.0.0.1\nport 22\nproxycommand nc remote 22\n",
@@ -59,7 +60,7 @@ const provide = <A, E>(
60 it.effect("skips SSH aliases resolving to this machine, including loopback", () =>
61 provide(
62 Effect.gen(function* () {
62 - for (const target of ["mac-mini", "loopback", "ipv6"]) {
63 + for (const target of ["mac-mini", "loopback", "ipv6", "mapped"]) {
64 expect(yield* isLocalSshDeviceHost(host(target))).toBe(true);
65 }
66 }),
apps/server/src/device/localSshDeviceHost.ts
+20 -3
@@ -19,6 +19,21 @@ export const LocalDeviceHostAddresses = Context.Reference<ReadonlySet<string>>(
19 },
20 );
21
22 +/** Unwraps IPv4-mapped IPv6 (`::ffff:127.0.0.1`, `::ffff:7f00:1`) to plain IPv4. */
23 +const unmapIPv4 = (address: string) => {
24 + if (NodeNet.isIP(address) !== 6) return address;
25 + let canonical: string;
26 + try {
27 + canonical = new URL(`http://[${address}]`).hostname;
28 + } catch {
29 + return address;
30 + }
31 + const match = /^\[::ffff:([0-9a-f]{1,4}):([0-9a-f]{1,4})\]$/.exec(canonical);
32 + if (!match) return address;
33 + const [high, low] = [parseInt(match[1]!, 16), parseInt(match[2]!, 16)];
34 + return [high >> 8, high & 0xff, low >> 8, low & 0xff].join(".");
35 +};
36 +
37 export const isLocalSshDeviceHost = Effect.fn("isLocalSshDeviceHost")(function* (
38 host: SshDeviceHostConfig,
39 ) {
@@ -57,9 +72,11 @@ export const isLocalSshDeviceHost = Effect.fn("isLocalSshDeviceHost")(function*
72 const localAddresses = yield* LocalDeviceHostAddresses;
73 return (
74 addresses.length > 0 &&
60 - addresses.every(
61 - (address) => localAddresses.has(address) || address === "::1" || address.startsWith("127."),
62 - )
75 + addresses
76 + .map(unmapIPv4)
77 + .every(
78 + (address) => localAddresses.has(address) || address === "::1" || address.startsWith("127."),
79 + )
80 );
81 });
82