Skip to content

Commit 93297c5

Browse files
bijeebussclaude
andcommitted
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 <[email protected]>
1 parent f0ea660 commit 93297c5

3 files changed

Lines changed: 18 additions & 12 deletions

File tree

‎apps/server/src/peer/PeerLinks.test.ts‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ it.effect("tells the agent to link again once the peer revokes the link or it ex
482482
);
483483

484484
it.effect(
485-
"refuses to link itself, plain http off a private network, or a peer that cannot hold a linked agent to its limits",
485+
"refuses to link itself, plain http that could leave the private network, or a peer that cannot hold a linked agent to its limits",
486486
() =>
487487
Effect.scoped(
488488
Effect.gen(function* () {
@@ -520,6 +520,14 @@ it.effect(
520520
})
521521
.pipe(Effect.flip);
522522
expect(exposedAlternate.message).toContain("plain http");
523+
// So could a name, whatever it looks like: a search domain or unicast
524+
// DNS can resolve it to a public address.
525+
for (const url of ["http://box:3773", "http://box.local:3773"]) {
526+
const named = yield* a.links
527+
.link({ url, pairingCode: pairing.credential, access: "auto" })
528+
.pipe(Effect.flip);
529+
expect(named.message).toContain("plain http");
530+
}
523531

524532
yield* Ref.set(b.descriptor, laptop);
525533
const self = yield* a.links

‎apps/server/src/peer/PeerLinks.ts‎

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,12 @@ import * as FetchHttpClient from "effect/http/FetchHttpClient";
2929
import * as HttpClient from "effect/http/HttpClient";
3030
import * as HttpApi from "effect/http-api/HttpApi";
3131
import * as HttpApiClient from "effect/http-api/HttpApiClient";
32-
import {
33-
isLocalLoopbackHost,
34-
isPrivateNetworkHost,
35-
isTailnetHost,
36-
} from "@t3tools/shared/hostClassification";
32+
import { isLocalLoopbackHost, isTailnetHost } from "@t3tools/shared/hostClassification";
3733

3834
import * as ServerSecretStore from "../auth/ServerSecretStore.ts";
3935
import * as ServerEnvironment from "../environment/ServerEnvironment.ts";
4036
import * as ServerSettings from "../serverSettings.ts";
37+
import { isPrivateNetworkAddress } from "../startupAccess.ts";
4138

4239
const PeerHttpApi = HttpApi.make(EnvironmentHttpApi.identifier)
4340
.add(EnvironmentHttpApi.groups.metadata)
@@ -145,7 +142,8 @@ const sendsInClear = (url: string | URL) => {
145142
/**
146143
* The base URL a peer is reached at, normalised to its origin. The pairing
147144
* code and then the link's token travel to it, so plain http off this machine
148-
* and the tailnet is accepted only on a private network, as servers pair there.
145+
* and the tailnet is accepted only to a private IP, as a LAN server pairs
146+
* over. A name is refused: DNS could resolve it to a public address.
149147
*/
150148
const peerOrigin = (url: string) => {
151149
const parsed = URL.parse(url);
@@ -157,11 +155,11 @@ const peerOrigin = (url: string) => {
157155
}),
158156
);
159157
}
160-
if (sendsInClear(parsed) && !isPrivateNetworkHost(parsed.hostname)) {
158+
if (sendsInClear(parsed) && !isPrivateNetworkAddress(parsed.hostname)) {
161159
return Effect.fail(
162160
new PeerLinkError({
163161
reason: "unreachable",
164-
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.`,
162+
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.`,
165163
}),
166164
);
167165
}

‎docs/user/remote-access.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -355,9 +355,9 @@ and the access, then approve.
355355
removes it here.
356356
- Links last 30 days. Link again with a new pairing code to renew one.
357357
- On a LAN or other private network, a link can use the machine's plain
358-
`http://` address, as pairing does. A machine picked from the list is linked
359-
over its https, Tailscale or T3 Connect address instead whenever one answers.
360-
Plain http to a public address is refused.
358+
`http://` IP address, as pairing does. A machine picked from the list is
359+
linked over its https, Tailscale or T3 Connect address instead whenever one
360+
answers. Plain http to a public address or to a hostname is refused.
361361

362362
An agent can also hand a task to a linked machine with `delegate_task`: it runs
363363
there as an ordinary thread, in the project with the same repository (or the

0 commit comments

Comments
 (0)