From f0ea66009916685b67532945e138147e92d9ba90 Mon Sep 17 00:00:00 2001 From: Michael Welnick <11799228+bijeebuss@users.noreply.github.com> Date: Mon, 2 Nov 2026 16:08:41 -0700 Subject: [PATCH 1/4] fix(server): link machines over plain http on a private network Linking refused every plain-http address off loopback and the tailnet, so two machines that pair over their LAN, the only address `t3 pair` prints there, could not be linked. Client pairing, advertised endpoints and the LAN listener all accept plain http on a private network. Links now accept plain http to a private-network address, as pairing does, and still refuse it to a public one. As with a paired client's token, a link made over https, loopback or the tailnet keeps to those addresses: plain http is used only when no address that encrypts answers, and is never kept as a fallback for a link made over one. Written with Claude Opus 5.5 (claude-opus-5-5) via Claude Code in T3 Code. Co-Authored-By: Claude Opus 5.5 --- apps/server/src/peer/PeerLinks.test.ts | 81 +++++++++++++++++++---- apps/server/src/peer/PeerLinks.testkit.ts | 5 +- apps/server/src/peer/PeerLinks.ts | 44 ++++++++---- docs/user/remote-access.md | 4 ++ 4 files changed, 106 insertions(+), 28 deletions(-) diff --git a/apps/server/src/peer/PeerLinks.test.ts b/apps/server/src/peer/PeerLinks.test.ts index 3c510c35e690..43a238de00ac 100644 --- a/apps/server/src/peer/PeerLinks.test.ts +++ b/apps/server/src/peer/PeerLinks.test.ts @@ -1,4 +1,5 @@ -import { NodeHttpServer } from "@effect/platform-node"; +import { NodeHttpClient, NodeHttpServer } from "@effect/platform-node"; +import * as Undici from "@effect/platform-node/Undici"; import { type ExecutionEnvironmentDescriptor, OrchestratorMcpFailure } from "@t3tools/contracts"; import { expect, it } from "@effect/vitest"; import * as Context from "effect/Context"; @@ -81,8 +82,9 @@ const serveB = (descriptor: ExecutionEnvironmentDescriptor) => const makeA = ( descriptor: ExecutionEnvironmentDescriptor, secrets?: typeof ServerSecretStore.layer, + machine?: Layer.Layer, ) => - layerLinkingEnvironment(descriptor, secrets).pipe( + layerLinkingEnvironment(descriptor, secrets, machine).pipe( Layer.build, Effect.map((context) => ({ links: Context.get(context, PeerLinks.PeerLinks), @@ -115,6 +117,18 @@ const serveApart = (descriptor: ExecutionEnvironmentDescriptor) => Effect.flatMap((server) => serveB(descriptor).pipe(Effect.provideContext(server))), ); +/** Connections to `host` reach 127.0.0.1 instead, as a LAN route would reach the peer. */ +const layerRouteHostToLoopback = (host: string) => { + const connect = Undici.buildConnector({}); + return NodeHttpClient.layerUndiciOptions({ + connect: (options, callback) => + connect( + { ...options, hostname: options.hostname === host ? "127.0.0.1" : options.hostname }, + callback, + ), + }); +}; + it.effect("links with a pairing code, and the peer holds its agents to the limits they carry", () => Effect.scoped( Effect.gen(function* () { @@ -468,7 +482,7 @@ it.effect("tells the agent to link again once the peer revokes the link or it ex ); it.effect( - "refuses to link itself, plain http off this machine and the tailnet, or a peer that cannot hold a linked agent to its limits", + "refuses to link itself, plain http off a private network, or a peer that cannot hold a linked agent to its limits", () => Effect.scoped( Effect.gen(function* () { @@ -488,24 +502,24 @@ it.effect( .pipe(Effect.flip); expect(unfenced.reason).toBe("incompatible"); - // Plain http to a LAN address would carry the code and token in clear. - const lan = yield* a.links + // Plain http to a public address would carry the code and token in clear. + const exposed = yield* a.links .link({ - url: "http://192.168.1.20:3773", + url: "http://203.0.113.7:3773", pairingCode: pairing.credential, access: "auto", }) .pipe(Effect.flip); - expect(lan.message).toContain("plain http"); - const lanAlternate = yield* a.links + expect(exposed.message).toContain("plain http"); + const exposedAlternate = yield* a.links .link({ url: b.url, - alternateUrls: ["http://192.168.1.20:3773"], + alternateUrls: ["http://203.0.113.7:3773"], pairingCode: pairing.credential, access: "auto", }) .pipe(Effect.flip); - expect(lanAlternate.message).toContain("plain http"); + expect(exposedAlternate.message).toContain("plain http"); yield* Ref.set(b.descriptor, laptop); const self = yield* a.links @@ -518,6 +532,47 @@ it.effect( ).pipe(Effect.provide(NodeHttpServer.layerTest)), ); +it.effect( + "links over plain http on a private network, but never moves a link made over an encrypted address onto it", + () => + Effect.scoped( + Effect.gen(function* () { + const b = yield* serveB(box); + const lan = `http://192.168.1.20:${new URL(b.url).port}`; + const a = yield* makeA(laptop, undefined, layerRouteHostToLoopback("192.168.1.20")); + + // The address `t3 pair` prints for a server on a LAN. + const linked = yield* a.links.link({ + url: lan, + pairingCode: (yield* b.auth.issuePairingCredential()).credential, + access: "auto", + }); + expect(linked.urls).toEqual([lan]); + yield* probe(a); + expect((yield* Ref.get(b.bearers)).length).toBeGreaterThan(0); + + // Linked through an address that encrypts, the token never falls back + // to the LAN one, whether the address was typed or the machine picked. + const typed = yield* a.links.link({ + url: b.url, + alternateUrls: [lan], + pairingCode: (yield* b.auth.issuePairingCredential()).credential, + access: "auto", + }); + expect(typed.urls).toEqual([b.url]); + const picked = yield* a.links.link({ + url: lan, + alternateUrls: [b.url], + pairingCode: (yield* b.auth.issuePairingCredential()).credential, + access: "auto", + expectedEnvironmentId: box.environmentId, + }); + expect(picked.urls).toEqual([b.url]); + expect((yield* a.links.resolve(box.environmentId)).url).toBe(b.url); + }), + ).pipe(Effect.provide(NodeHttpServer.layerTest)), +); + it.effect( "linking a picked machine skips an address that answers as another, and never signs in there", () => @@ -551,7 +606,7 @@ it.effect("linking a picked machine that answers nowhere names it and links noth const failed = yield* a.links .link({ url: impostor.url, - alternateUrls: ["http://192.168.1.20:3773"], + alternateUrls: ["http://203.0.113.7:3773"], pairingCode: "unused", access: "auto", expectedEnvironmentId: box.environmentId, @@ -560,7 +615,7 @@ it.effect("linking a picked machine that answers nowhere names it and links noth .pipe(Effect.flip); expect(failed.reason).toBe("unreachable"); expect(failed.message).toBe( - `This environment could not reach Box at ${impostor.url}, http://192.168.1.20:3773.`, + `This environment could not reach Box at ${impostor.url}, http://203.0.113.7:3773.`, ); expect(yield* a.links.list).toEqual([]); expect(yield* linkedSessions(impostor)).toEqual([]); @@ -568,7 +623,7 @@ it.effect("linking a picked machine that answers nowhere names it and links noth // Every address refused: the message says why. const refused = yield* a.links .link({ - url: "http://192.168.1.20:3773", + url: "http://203.0.113.7:3773", pairingCode: "unused", access: "auto", expectedEnvironmentId: box.environmentId, diff --git a/apps/server/src/peer/PeerLinks.testkit.ts b/apps/server/src/peer/PeerLinks.testkit.ts index 9bdc47298d57..674e57403b45 100644 --- a/apps/server/src/peer/PeerLinks.testkit.ts +++ b/apps/server/src/peer/PeerLinks.testkit.ts @@ -152,14 +152,17 @@ export type ServedPeer = Effect.Success>; /** * The environment that links: its own database and secret store, reaching - * peers over plain HTTP. Provide it to anything built on its links. + * peers over plain HTTP. Provide it to anything built on its links. `machine` + * replaces what this machine provides, such as its network. */ export const layerLinkingEnvironment = ( descriptor: ExecutionEnvironmentDescriptor, secrets: typeof ServerSecretStore.layer = ServerSecretStore.layer, + machine: Layer.Layer = Layer.empty, ) => PeerMcpClient.layer.pipe( Layer.provideMerge(PeerLinks.layer), + Layer.provide(machine), Layer.provideMerge(ServerSettings.layerTest({ linkedEnvironmentsEnabled: true })), Layer.provideMerge(Sqlite.layerMemory), Layer.provide(Layer.mergeAll(secrets, FetchHttpClient.layer)), diff --git a/apps/server/src/peer/PeerLinks.ts b/apps/server/src/peer/PeerLinks.ts index 4d83befd743f..029ac0a28f03 100644 --- a/apps/server/src/peer/PeerLinks.ts +++ b/apps/server/src/peer/PeerLinks.ts @@ -29,7 +29,11 @@ import * as FetchHttpClient from "effect/http/FetchHttpClient"; import * as HttpClient from "effect/http/HttpClient"; import * as HttpApi from "effect/http-api/HttpApi"; import * as HttpApiClient from "effect/http-api/HttpApiClient"; -import { isLocalLoopbackHost, isTailnetHost } from "@t3tools/shared/hostClassification"; +import { + isLocalLoopbackHost, + isPrivateNetworkHost, + isTailnetHost, +} from "@t3tools/shared/hostClassification"; import * as ServerSecretStore from "../auth/ServerSecretStore.ts"; import * as ServerEnvironment from "../environment/ServerEnvironment.ts"; @@ -132,10 +136,16 @@ const failStorage = (cause: unknown) => ), ); +/** Whether credentials sent to `url` cross the network unencrypted. */ +const sendsInClear = (url: string | URL) => { + const { protocol, hostname } = new URL(url); + return protocol === "http:" && !isLocalLoopbackHost(hostname) && !isTailnetHost(hostname); +}; + /** * The base URL a peer is reached at, normalised to its origin. The pairing - * code and then the link's token travel to it, so plain http is accepted only - * where the network already encrypts: this machine, or a Tailscale address. + * code and then the link's token travel to it, so plain http off this machine + * and the tailnet is accepted only on a private network, as servers pair there. */ const peerOrigin = (url: string) => { const parsed = URL.parse(url); @@ -147,21 +157,25 @@ const peerOrigin = (url: string) => { }), ); } - if ( - parsed.protocol === "http:" && - !isLocalLoopbackHost(parsed.hostname) && - !isTailnetHost(parsed.hostname) - ) { + if (sendsInClear(parsed) && !isPrivateNetworkHost(parsed.hostname)) { return Effect.fail( new PeerLinkError({ reason: "unreachable", - message: `${url} is plain http, which would send the link's credentials unencrypted. Use its https address, or its Tailscale address.`, + message: `${url} is plain http outside a private network, which would send the link's credentials unencrypted. Use its https address, its Tailscale address, or its IP address on your local network.`, }), ); } return Effect.succeed(parsed.origin); }; +/** + * The origins a link made over `primary` keeps. As with a paired client's + * token, a link's token goes over plain http only when the link was made over + * it, so one made over https, loopback or the tailnet never travels in clear. + */ +const keptOrigins = (primary: string, origins: ReadonlyArray) => + sendsInClear(primary) ? origins : origins.filter((origin) => !sendsInClear(origin)); + /** Whether a peer holds a linked agent to its limits and keeps its work within its link. */ const linkLimitsHold = (peer: { readonly capabilities: ExecutionEnvironmentCapabilities }) => peer.capabilities.mcpModeLimitHeader === true && peer.capabilities.linkFence === true; @@ -349,8 +363,9 @@ const make = Effect.gen(function* () { /** * The addresses that answer as `environmentId`, in the order given, with - * what the first one answered. Addresses this environment would not send - * credentials to are skipped; when every one is, the failure says why. + * the one to link through and what it answered. Addresses this environment + * would not send credentials to are skipped; when every one is, the failure + * says why. */ const answeringAs = Effect.fn("PeerLinks.answeringAs")(function* ( urls: ReadonlyArray, @@ -373,7 +388,8 @@ const make = Effect.gen(function* () { ? [{ origin: result.success.origin, descriptor: result.success.descriptor.value }] : [], ); - const first = matching[0]; + // Plain http is the fallback when no address that encrypts answers. + const first = matching.find((found) => !sendsInClear(found.origin)) ?? matching[0]; if (first === undefined) { const refusals = checked.flatMap((result) => Result.isFailure(result) ? [result.failure.message] : [], @@ -387,7 +403,7 @@ const make = Effect.gen(function* () { }); } // Each address is kept once, even when two spellings share an origin. - const origins = [...new Set(matching.map((found) => found.origin))]; + const origins = keptOrigins(first.origin, [...new Set(matching.map((found) => found.origin))]); return { primary: first.origin, peer: first.descriptor, origins }; }); @@ -402,7 +418,7 @@ const make = Effect.gen(function* () { message: `Nothing at ${primary} answered as a T3 Code environment.`, }); } - return { primary, peer: descriptor.value, origins }; + return { primary, peer: descriptor.value, origins: keptOrigins(primary, origins) }; }); const link: PeerLinks["Service"]["link"] = Effect.fn("PeerLinks.link")(function* (input) { diff --git a/docs/user/remote-access.md b/docs/user/remote-access.md index 259f58c00e57..a840fda9c72e 100644 --- a/docs/user/remote-access.md +++ b/docs/user/remote-access.md @@ -354,6 +354,10 @@ and the access, then approve. outside agent. Revoke it there to end it. **Forget** on this machine only removes it here. - Links last 30 days. Link again with a new pairing code to renew one. +- On a LAN or other private network, a link can use the machine's plain + `http://` address, as pairing does. A machine picked from the list is linked + over its https, Tailscale or T3 Connect address instead whenever one answers. + Plain http to a public address is refused. An agent can also hand a task to a linked machine with `delegate_task`: it runs there as an ordinary thread, in the project with the same repository (or the From 93297c55dce64ce2d95c2b859a789d9867af96da Mon Sep 17 00:00:00 2001 From: Michael Welnick <11799228+bijeebuss@users.noreply.github.com> Date: Mon, 2 Nov 2026 16:27:09 -0700 Subject: [PATCH 2/4] fix(server): refuse plain http to peer hostnames A name such as `docs` or `box.local` passed the private-network check without being resolved, and a search domain or unicast DNS can resolve it to a public address. Plain http is now accepted only to a private IPv4 address, using the check the LAN listener and advertised endpoints use. Written with Claude Opus 5.5 (claude-opus-5-5) via Claude Code in T3 Code. Co-Authored-By: Claude Opus 5.5 --- apps/server/src/peer/PeerLinks.test.ts | 10 +++++++++- apps/server/src/peer/PeerLinks.ts | 14 ++++++-------- docs/user/remote-access.md | 6 +++--- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/apps/server/src/peer/PeerLinks.test.ts b/apps/server/src/peer/PeerLinks.test.ts index 43a238de00ac..3a45c6998141 100644 --- a/apps/server/src/peer/PeerLinks.test.ts +++ b/apps/server/src/peer/PeerLinks.test.ts @@ -482,7 +482,7 @@ it.effect("tells the agent to link again once the peer revokes the link or it ex ); it.effect( - "refuses to link itself, plain http off a private network, or a peer that cannot hold a linked agent to its limits", + "refuses to link itself, plain http that could leave the private network, or a peer that cannot hold a linked agent to its limits", () => Effect.scoped( Effect.gen(function* () { @@ -520,6 +520,14 @@ it.effect( }) .pipe(Effect.flip); expect(exposedAlternate.message).toContain("plain http"); + // So could a name, whatever it looks like: a search domain or unicast + // DNS can resolve it to a public address. + for (const url of ["http://box:3773", "http://box.local:3773"]) { + const named = yield* a.links + .link({ url, pairingCode: pairing.credential, access: "auto" }) + .pipe(Effect.flip); + expect(named.message).toContain("plain http"); + } yield* Ref.set(b.descriptor, laptop); const self = yield* a.links diff --git a/apps/server/src/peer/PeerLinks.ts b/apps/server/src/peer/PeerLinks.ts index 029ac0a28f03..d34934136094 100644 --- a/apps/server/src/peer/PeerLinks.ts +++ b/apps/server/src/peer/PeerLinks.ts @@ -29,15 +29,12 @@ import * as FetchHttpClient from "effect/http/FetchHttpClient"; import * as HttpClient from "effect/http/HttpClient"; import * as HttpApi from "effect/http-api/HttpApi"; import * as HttpApiClient from "effect/http-api/HttpApiClient"; -import { - isLocalLoopbackHost, - isPrivateNetworkHost, - isTailnetHost, -} from "@t3tools/shared/hostClassification"; +import { isLocalLoopbackHost, isTailnetHost } from "@t3tools/shared/hostClassification"; import * as ServerSecretStore from "../auth/ServerSecretStore.ts"; import * as ServerEnvironment from "../environment/ServerEnvironment.ts"; import * as ServerSettings from "../serverSettings.ts"; +import { isPrivateNetworkAddress } from "../startupAccess.ts"; const PeerHttpApi = HttpApi.make(EnvironmentHttpApi.identifier) .add(EnvironmentHttpApi.groups.metadata) @@ -145,7 +142,8 @@ const sendsInClear = (url: string | URL) => { /** * The base URL a peer is reached at, normalised to its origin. The pairing * code and then the link's token travel to it, so plain http off this machine - * and the tailnet is accepted only on a private network, as servers pair there. + * and the tailnet is accepted only to a private IP, as a LAN server pairs + * over. A name is refused: DNS could resolve it to a public address. */ const peerOrigin = (url: string) => { const parsed = URL.parse(url); @@ -157,11 +155,11 @@ const peerOrigin = (url: string) => { }), ); } - if (sendsInClear(parsed) && !isPrivateNetworkHost(parsed.hostname)) { + if (sendsInClear(parsed) && !isPrivateNetworkAddress(parsed.hostname)) { return Effect.fail( new PeerLinkError({ reason: "unreachable", - message: `${url} is plain http outside a private network, which would send the link's credentials unencrypted. Use its https address, its Tailscale address, or its IP address on your local network.`, + message: `${url} is plain http to an address that is not a private IP, so the link's credentials could travel unencrypted across the internet. Use its https address, its Tailscale address, or its IP address on your local network.`, }), ); } diff --git a/docs/user/remote-access.md b/docs/user/remote-access.md index a840fda9c72e..f46600838dba 100644 --- a/docs/user/remote-access.md +++ b/docs/user/remote-access.md @@ -355,9 +355,9 @@ and the access, then approve. removes it here. - Links last 30 days. Link again with a new pairing code to renew one. - On a LAN or other private network, a link can use the machine's plain - `http://` address, as pairing does. A machine picked from the list is linked - over its https, Tailscale or T3 Connect address instead whenever one answers. - Plain http to a public address is refused. + `http://` IP address, as pairing does. A machine picked from the list is + linked over its https, Tailscale or T3 Connect address instead whenever one + answers. Plain http to a public address or to a hostname is refused. An agent can also hand a task to a linked machine with `delegate_task`: it runs there as an ordinary thread, in the project with the same repository (or the From ef3f23ea023a191c2670671870d9e184b76db696 Mon Sep 17 00:00:00 2001 From: Michael Welnick <11799228+bijeebuss@users.noreply.github.com> Date: Tue, 3 Nov 2026 09:04:04 -0700 Subject: [PATCH 3/4] docs: note that localhost and Tailscale names still link over plain http The bullet said plain http to any hostname is refused, but localhost and Tailscale (.ts.net) names are still accepted as before. Written with Claude Opus 5.5 (claude-opus-5-5) via Claude Code in T3 Code. Co-Authored-By: Claude Opus 5.5 --- docs/user/remote-access.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/user/remote-access.md b/docs/user/remote-access.md index f46600838dba..4aed24f9d948 100644 --- a/docs/user/remote-access.md +++ b/docs/user/remote-access.md @@ -357,7 +357,8 @@ and the access, then approve. - On a LAN or other private network, a link can use the machine's plain `http://` IP address, as pairing does. A machine picked from the list is linked over its https, Tailscale or T3 Connect address instead whenever one - answers. Plain http to a public address or to a hostname is refused. + answers. Plain http to a public address or to a hostname is refused, apart + from `localhost` and Tailscale (`.ts.net`) names. An agent can also hand a task to a linked machine with `delegate_task`: it runs there as an ordinary thread, in the project with the same repository (or the From b62f3208c4c428f5c9d79661c56b5d328a3ed537 Mon Sep 17 00:00:00 2001 From: Michael Welnick <11799228+bijeebuss@users.noreply.github.com> Date: Mon, 23 Nov 2026 16:19:42 +0000 Subject: [PATCH 4/4] fix(server): plain http links only to private LAN ranges The plain-http rule reused the server's isPrivateNetworkAddress, which also admits the 100.64.0.0/10 shared space carrier-grade NAT uses, 198.18.0.0/15 and 0.0.0.0/8, where plain http can cross networks the user doesn't control. Upstream's own link rule doesn't take 100.64.0.0/10 as Tailscale either. Now a link goes over plain http only to an RFC 1918 address (10/8, 172.16/12, 192.168/16), and the refusal names those ranges. Carrier-grade NAT and the benchmarking range are refused like a public address, and numeric Tailscale addresses stay with #26475. Written with Claude Opus 5.5 (claude-opus-5-5) via Claude Code in T3 Code. Co-Authored-By: Claude Opus 5.5 --- apps/server/src/peer/PeerLinks.test.ts | 12 +++++++++--- apps/server/src/peer/PeerLinks.ts | 27 +++++++++++++++++++++----- docs/user/remote-access.md | 10 +++++----- 3 files changed, 36 insertions(+), 13 deletions(-) diff --git a/apps/server/src/peer/PeerLinks.test.ts b/apps/server/src/peer/PeerLinks.test.ts index 24a893aa5e61..e07a50966f0e 100644 --- a/apps/server/src/peer/PeerLinks.test.ts +++ b/apps/server/src/peer/PeerLinks.test.ts @@ -754,8 +754,14 @@ it.effect( .pipe(Effect.flip); expect(exposedAlternate.message).toContain("plain http"); // So could a name, whatever it looks like: a search domain or unicast - // DNS can resolve it to a public address. - for (const url of ["http://box:3773", "http://box.local:3773"]) { + // DNS can resolve it to a public address. And carrier-grade NAT's shared + // space and the benchmarking range aren't a LAN either. + for (const url of [ + "http://box:3773", + "http://box.local:3773", + "http://100.100.1.2:3773", + "http://198.18.0.5:3773", + ]) { const named = yield* a.links .link({ url, pairingCode: pairing.credential, access: "auto" }) .pipe(Effect.flip); @@ -884,7 +890,7 @@ it.effect("linking a picked machine that answers nowhere names it and links noth expect(failed.reason).toBe("unreachable"); expect(failed.answeredAs).toBe("Impostor"); expect(failed.message).toBe( - `This environment could not reach Box: ${new URL(impostor.url).origin} answered as another environment, Impostor. http://203.0.113.7:3773 is plain http to an address that is not a private IP, so the link's credentials could travel unencrypted across the internet. Use its https address, its Tailscale address, or its IP address on your local network.`, + `This environment could not reach Box: ${new URL(impostor.url).origin} answered as another environment, Impostor. http://203.0.113.7:3773 is plain http to an address outside the private LAN ranges (10.x, 172.16-31.x, 192.168.x), so the link's credentials could travel unencrypted across networks you don't control. Use its https address, its Tailscale name (.ts.net), or its address on your LAN.`, ); expect(yield* a.links.list).toEqual([]); expect(yield* linkedSessions(impostor)).toEqual([]); diff --git a/apps/server/src/peer/PeerLinks.ts b/apps/server/src/peer/PeerLinks.ts index 6aef69d0a23c..655335f96fb7 100644 --- a/apps/server/src/peer/PeerLinks.ts +++ b/apps/server/src/peer/PeerLinks.ts @@ -39,7 +39,6 @@ import { isLocalLoopbackHost, isTailnetHost } from "@t3tools/shared/hostClassifi import * as ServerSecretStore from "../auth/ServerSecretStore.ts"; import * as ServerEnvironment from "../environment/ServerEnvironment.ts"; import * as ServerSettings from "../serverSettings.ts"; -import { isPrivateNetworkAddress } from "../startupAccess.ts"; const PeerHttpApi = HttpApi.make(EnvironmentHttpApi.identifier) .add(EnvironmentHttpApi.groups.metadata) @@ -166,11 +165,29 @@ const sendsInClear = (url: string | URL) => { return protocol === "http:" && !isLocalLoopbackHost(hostname) && !isTailnetHost(hostname); }; +const IPV4_ADDRESS = /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/; + +/** + * An RFC 1918 address, as a home or office LAN hands out. Not the shared + * 100.64.0.0/10 space carrier-grade NAT uses, nor test ranges: plain http to + * those can cross networks the user doesn't control. + */ +const isLanAddress = (host: string) => { + const octets = IPV4_ADDRESS.exec(host)?.slice(1).map(Number); + if (octets === undefined || octets.some((octet) => octet > 255)) return false; + const [first, second] = octets as [number, number]; + return ( + first === 10 || + (first === 172 && second >= 16 && second <= 31) || + (first === 192 && second === 168) + ); +}; + /** * The base URL a peer is reached at, normalised to its origin. The pairing * code and then the link's token travel to it, so plain http off this machine - * and the tailnet is accepted only to a private IP, as a LAN server pairs - * over. A name is refused: DNS could resolve it to a public address. + * and the tailnet is accepted only to a LAN address. A name is refused: DNS + * could resolve it to a public address. */ const peerOrigin = (url: string) => { const parsed = URL.parse(url); @@ -183,11 +200,11 @@ const peerOrigin = (url: string) => { }), ); } - if (sendsInClear(parsed) && !isPrivateNetworkAddress(parsed.hostname)) { + if (sendsInClear(parsed) && !isLanAddress(parsed.hostname)) { return Effect.fail( new PeerLinkError({ reason: "unreachable", - message: `${parsed.origin} is plain http to an address that is not a private IP, so the link's credentials could travel unencrypted across the internet. Use its https address, its Tailscale address, or its IP address on your local network.`, + message: `${parsed.origin} is plain http to an address outside the private LAN ranges (10.x, 172.16-31.x, 192.168.x), so the link's credentials could travel unencrypted across networks you don't control. Use its https address, its Tailscale name (.ts.net), or its address on your LAN.`, }), ); } diff --git a/docs/user/remote-access.md b/docs/user/remote-access.md index 7484a3feb492..3242205734b0 100644 --- a/docs/user/remote-access.md +++ b/docs/user/remote-access.md @@ -469,11 +469,11 @@ an address you trust: the code is sent there. - A link stays valid while agents use it. One unused for 30 days expires, as does one to a machine on an older T3 Code after 30 days; link again with a new pairing code. -- On a LAN or other private network, a link can use the machine's plain - `http://` IP address, as pairing does. A machine picked from the list is - linked over its https, Tailscale or T3 Connect address instead whenever one - answers. Plain http to a public address or to a hostname is refused, apart - from `localhost` and Tailscale (`.ts.net`) names. +- On a LAN, a link can use the machine's plain `http://` IP address when it is + in a private range (`10.x`, `172.16–31.x` or `192.168.x`). A machine picked + from the list is linked over its https, Tailscale or T3 Connect address + instead whenever one answers. Plain http to any other address or to a + hostname is refused, apart from `localhost` and Tailscale (`.ts.net`) names. An agent can also hand a task to a linked machine with `delegate_task`: it runs there as an ordinary thread, in the project with the same repository (or the