@devries-cameron20 / t3code-1 / commits / 82465ed26a
Fork 0

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

fix(tailscale): Tailscale HTTPS is advertised only when it reaches this T3 server (#34744)

Julius Marminge committed Nov 11, 2026 at 21:00 UTC 82465ed26a6c765e538a500d284ed54c30d3e725
5 files changed +53 -14
apps/server/src/environment/DirectEndpoints.test.ts
+17 -6
@@ -9,6 +9,7 @@ import * as Layer from "effect/Layer";
9 import * as Sink from "effect/Sink";
10 import * as Stream from "effect/Stream";
11 import * as HttpClient from "effect/http/HttpClient";
12 +import type * as HttpClientRequest from "effect/http/HttpClientRequest";
13 import * as HttpClientResponse from "effect/http/HttpClientResponse";
14 import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner";
15 import { describe, expect, it } from "vite-plus/test";
@@ -250,12 +251,24 @@ const layerTailscaleUp = Layer.succeed(
251 ),
252 );
253
254 +const T3_DESCRIPTOR_BODY = JSON.stringify({
255 + environmentId: "serve-test",
256 + label: "Serve test",
257 + platform: { os: "darwin", arch: "arm64" },
258 + serverVersion: "0.0.0-test",
259 + capabilities: { repositoryIdentity: true },
260 +});
261 +
262 +const serveProbeResponse = (request: HttpClientRequest.HttpClientRequest, status: number) =>
263 + HttpClientResponse.fromWeb(
264 + request,
265 + new Response(status === 200 ? T3_DESCRIPTOR_BODY : null, { status }),
266 + );
267 +
268 const layerServeProbe = (status: number) =>
269 Layer.succeed(
270 HttpClient.HttpClient,
256 - HttpClient.make((request) =>
257 - Effect.succeed(HttpClientResponse.fromWeb(request, new Response(null, { status }))),
258 - ),
271 + HttpClient.make((request) => Effect.succeed(serveProbeResponse(request, status))),
272 );
273
274 const layerServeConfig = (host = "127.0.0.1") =>
@@ -320,9 +333,7 @@ describe("DirectEndpoints Tailscale Serve", () => {
333 )
334 : Effect.void,
335 ),
323 - Effect.map((status) =>
324 - HttpClientResponse.fromWeb(request, new Response(null, { status })),
325 - ),
336 + Effect.map((status) => serveProbeResponse(request, status)),
337 ),
338 ),
339 ),
packages/tailscale/package.json
+1
@@ -13,6 +13,7 @@
13 "test": "vp test run --config ../../vite.config.ts --dir ."
14 },
15 "dependencies": {
16 + "@t3tools/contracts": "workspace:*",
17 "@t3tools/shared": "workspace:*",
18 "effect": "catalog:"
19 },
packages/tailscale/src/tailscale.test.ts
+23
@@ -7,6 +7,7 @@ import * as Fiber from "effect/Fiber";
7 import * as Layer from "effect/Layer";
8 import * as Sink from "effect/Sink";
9 import * as Stream from "effect/Stream";
10 +import { HttpClient, HttpClientResponse } from "effect/http";
11 import * as TestClock from "effect/testing/TestClock";
12 import { ChildProcessSpawner } from "effect/process";
13 import * as HostProcess from "@t3tools/shared/HostProcess";
@@ -17,6 +18,7 @@ import {
18 parseTailscaleServeRoutesTo,
19 parseTailscaleSshEnabled,
20 parseTailscaleStatus,
21 + probeTailscaleHttpsEndpoint,
22 readTailscaleSshEnabled,
23 readTailscaleStatus,
24 TailscaleCommandExitError,
@@ -99,6 +101,27 @@ function layerMockSpawner(
101 }
102
103 describe("tailscale", () => {
104 + it.effect("does not treat a non-T3 response on the HTTPS probe path as reachable", () =>
105 + Effect.gen(function* () {
106 + for (const [body, status] of [
107 + ["<!doctype html><title>Other application</title>", 200],
108 + [null, 204],
109 + ] as const) {
110 + const reachable = yield* probeTailscaleHttpsEndpoint({
111 + baseUrl: "https://desktop.example.ts.net",
112 + }).pipe(
113 + Effect.provideService(
114 + HttpClient.HttpClient,
115 + HttpClient.make((request) =>
116 + Effect.succeed(HttpClientResponse.fromWeb(request, new Response(body, { status }))),
117 + ),
118 + ),
119 + );
120 + assert.isFalse(reachable, `HTTP ${status} without a T3 descriptor`);
121 + }
122 + }),
123 + );
124 +
125 it("finds the Serve routes that forward to the bound address, and only those", () => {
126 const status = JSON.stringify({
127 TCP: {
packages/tailscale/src/tailscale.ts
+9 -8
@@ -1,3 +1,4 @@
1 +import { ExecutionEnvironmentDescriptor } from "@t3tools/contracts";
2 import * as HostProcess from "@t3tools/shared/HostProcess";
3 import { normalizeHostname } from "@t3tools/shared/hostClassification";
4 import * as Duration from "effect/Duration";
@@ -5,7 +6,7 @@ import * as Effect from "effect/Effect";
6 import * as Option from "effect/Option";
7 import * as Schema from "effect/Schema";
8 import * as Stream from "effect/Stream";
8 -import { HttpClient, HttpClientRequest } from "effect/http";
9 +import { HttpClient, HttpClientRequest, HttpClientResponse } from "effect/http";
10 import { ChildProcess, ChildProcessSpawner } from "effect/process";
11
12 export const DEFAULT_TAILSCALE_SERVE_PORT = 443;
@@ -658,16 +659,16 @@ export const readTailscaleServeRoutesTo = (target: {
659 export const probeTailscaleHttpsEndpoint = Effect.fn("tailscale.probeTailscaleHttpsEndpoint")(
660 function* (input: { readonly baseUrl: string; readonly timeout?: Duration.Input }) {
661 const client = yield* HttpClient.HttpClient;
661 - const response = yield* Effect.gen(function* () {
662 + const descriptor = yield* Effect.gen(function* () {
663 const url = new URL("/.well-known/t3/environment", input.baseUrl);
663 - const request = HttpClientRequest.get(url.toString());
664 - return yield* client.execute(request);
664 + const response = yield* client
665 + .execute(HttpClientRequest.get(url.toString()))
666 + .pipe(Effect.flatMap(HttpClientResponse.filterStatusOk));
667 + // A Serve mapping to another app also answers 2xx; only a T3 descriptor proves this server.
668 + return yield* HttpClientResponse.schemaBodyJson(ExecutionEnvironmentDescriptor)(response);
669 }).pipe(Effect.timeoutOption(input.timeout ?? TAILSCALE_PROBE_TIMEOUT));
670
667 - return Option.match(response, {
668 - onNone: () => false,
669 - onSome: (httpResponse) => httpResponse.status >= 200 && httpResponse.status < 300,
670 - });
671 + return Option.isSome(descriptor);
672 },
673 Effect.orElseSucceed(() => false),
674 );
pnpm-lock.yaml
+3
@@ -2461,6 +2461,9 @@ importers:
2461
2462 packages/tailscale:
2463 dependencies:
2464 + '@t3tools/contracts':
2465 + specifier: workspace:*
2466 + version: link:../contracts
2467 '@t3tools/shared':
2468 specifier: workspace:*
2469 version: link:../shared