From db415e83aeb6a1c479d1b54eed8a785dc77cbd64 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Sat, 7 Nov 2026 09:34:40 +0000 Subject: [PATCH 1/3] test(server): reproduce #32422 remote link-proof refusal message A paired client reaching the server from another machine, or through a proxy that adds forwarded-authority headers, is refused a link proof with "Invalid managed endpoint origin.", which tells the user nothing about why or what to do. These tests expect the refusal (still a 400) to point the user at `t3 connect link` on the host. Malformed client-supplied origins keep the existing message. Co-Authored-By: Claude Opus 5.5 --- apps/server/src/cloud/http.test.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/apps/server/src/cloud/http.test.ts b/apps/server/src/cloud/http.test.ts index 2d3dee882dcd3..e4e5497618a96 100644 --- a/apps/server/src/cloud/http.test.ts +++ b/apps/server/src/cloud/http.test.ts @@ -218,7 +218,7 @@ describe("link proof over a non-loopback desktop transport", () => { const rejected = yield* post("/api/connect/link-proof", payload, headers); expect(rejected.status).toBe(400); expect(yield* responseJson(rejected)).toMatchObject({ - message: "Invalid managed endpoint origin.", + message: expect.stringContaining("t3 connect link"), }); const loopback = yield* post( "/api/connect/link-proof", @@ -235,23 +235,27 @@ describe("link proof over a non-loopback desktop transport", () => { name: "non-loopback tunnel origin", origin: { localHttpHost: "172.24.162.233", localHttpPort: 3773 }, headers: {}, + message: "Invalid managed endpoint origin.", }, { name: "mismatched port", origin: { localHttpHost: "127.0.0.1", localHttpPort: 3774 }, headers: {}, + message: "Invalid managed endpoint origin.", }, { name: "forwarded host", origin: proofRequest.origin, headers: { "x-forwarded-host": "127.0.0.1:3773" }, + message: expect.stringContaining("t3 connect link"), }, { name: "forwarded protocol", origin: proofRequest.origin, headers: { "x-forwarded-proto": "http" }, + message: expect.stringContaining("t3 connect link"), }, - ])("rejects $name even for desktop bootstrap", ({ origin, headers }) => + ])("rejects $name even for desktop bootstrap", ({ origin, headers, message }) => Effect.gen(function* () { const { post, exchange } = yield* linkProofClient; const token = yield* exchange(DESKTOP_BOOTSTRAP_TOKEN); @@ -261,9 +265,7 @@ describe("link proof over a non-loopback desktop transport", () => { { ...headers, authorization: `Bearer ${token}` }, ); expect(response.status).toBe(400); - expect(yield* responseJson(response)).toMatchObject({ - message: "Invalid managed endpoint origin.", - }); + expect(yield* responseJson(response)).toMatchObject({ message }); }), ); From e20dcf87ab38a8fc0d541829069c03587d658f61 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Sat, 7 Nov 2026 09:38:30 +0000 Subject: [PATCH 2/3] fix(server): explain how to turn on T3 Connect from another machine A link-proof request that reaches the server from another machine (through a proxy that adds forwarded-authority headers, or over a non-loopback host without the desktop-bootstrap principal) was refused with "Invalid managed endpoint origin.", which tells the user nothing. The refusal stays exactly as strict; it now raises a "remote" CloudLinkOriginInvalidError whose message tells the user to run `t3 connect link` on the host. Malformed origins keep the old message. The request-host loopback check moves from isAllowedEndpointOrigin into linkProof so the two refusals are distinguishable. Co-Authored-By: Claude Opus 5.5 --- apps/server/src/cloud/CloudLink.ts | 34 +++++++++++++++-------------- apps/server/src/cloud/linkChecks.ts | 19 +++++++--------- 2 files changed, 26 insertions(+), 27 deletions(-) diff --git a/apps/server/src/cloud/CloudLink.ts b/apps/server/src/cloud/CloudLink.ts index 37ac9d9b743c1..55eccf05a1522 100644 --- a/apps/server/src/cloud/CloudLink.ts +++ b/apps/server/src/cloud/CloudLink.ts @@ -111,6 +111,7 @@ import { hasExactScope, hasForwardedAuthorityHeaders, isAllowedEndpointOrigin, + isLoopbackRequestUrl, isSupportedLinkProviderKind, linkProofScopes, managedEndpointRuntimeConfigsMatch, @@ -137,6 +138,12 @@ const RELAY_CONFIG_FIELD_MESSAGES = { cloudUserId: "Cloud user id is required.", cloudMintPublicKey: "Cloud mint public key must be a valid Ed25519 public key.", } as const; +const ORIGIN_INVALID_MESSAGES = { + endpoint: "Invalid managed endpoint origin.", + local: "Could not resolve local environment origin.", + remote: + "T3 Connect can only be turned on from the machine running this environment. Run `t3 connect link` on that machine.", +} as const; export class CloudLinkRelayConfigInvalidError extends Schema.TaggedError()( "CloudLinkRelayConfigInvalidError", @@ -157,12 +164,10 @@ export class CloudLinkRelayConfigInvalidError extends Schema.TaggedError()( "CloudLinkOriginInvalidError", - { origin: Schema.Literals(["endpoint", "local"]) }, + { origin: Schema.Literals(["endpoint", "local", "remote"]) }, ) { override get message(): string { - return this.origin === "endpoint" - ? "Invalid managed endpoint origin." - : "Could not resolve local environment origin."; + return ORIGIN_INVALID_MESSAGES[this.origin]; } } @@ -579,15 +584,10 @@ const make = Effect.gen(function* () { const makeCloudLinkProof = Effect.fn("environment.cloud.makeLinkProof")(function* ( request: RelayLinkProofRequest, requestUrl: string, - allowNonLoopbackRequestHost = false, ) { if ( !isSupportedLinkProviderKind(request) || - !isAllowedEndpointOrigin({ - origin: request.origin, - requestUrl, - allowNonLoopbackRequestHost, - }) + !isAllowedEndpointOrigin({ origin: request.origin, requestUrl }) ) { return yield* new CloudLinkOriginInvalidError({ origin: "endpoint" }); } @@ -628,16 +628,18 @@ const make = Effect.gen(function* () { const linkProof = Effect.fn("environment.cloud.linkProof")( function* (request: RelayLinkProofRequest, httpRequest: HttpServerRequest.HttpServerRequest) { const requestUrl = requestAbsoluteUrl(httpRequest); - if (requestUrl === null || hasForwardedAuthorityHeaders(httpRequest)) { + if (requestUrl === null) { return yield* new CloudLinkOriginInvalidError({ origin: "endpoint" }); } const principal = yield* EnvironmentAuthenticatedPrincipal; // WSL desktop requests use the distro IP; only the server-issued bootstrap subject qualifies. - return yield* makeCloudLinkProof( - request, - requestUrl, - principal.subject === "desktop-bootstrap", - ); + if ( + hasForwardedAuthorityHeaders(httpRequest) || + (principal.subject !== "desktop-bootstrap" && !isLoopbackRequestUrl(requestUrl)) + ) { + return yield* new CloudLinkOriginInvalidError({ origin: "remote" }); + } + return yield* makeCloudLinkProof(request, requestUrl); }, Effect.catchIf(ServerSecretStore.isSecretStoreError, internalError("generate-link-proof")), ); diff --git a/apps/server/src/cloud/linkChecks.ts b/apps/server/src/cloud/linkChecks.ts index af26c659b4d98..57e3147b0a07a 100644 --- a/apps/server/src/cloud/linkChecks.ts +++ b/apps/server/src/cloud/linkChecks.ts @@ -79,21 +79,18 @@ export function parseManagedEndpointLocalOrigin(localOrigin: string) { }; } +export function isLoopbackRequestUrl(requestUrl: string): boolean { + return isLoopbackHostname(new URL(requestUrl).hostname); +} + export function isAllowedEndpointOrigin(input: { readonly origin: RelayManagedEndpointOrigin; readonly requestUrl: string; - readonly allowNonLoopbackRequestHost?: boolean; }): boolean { - if (!isLoopbackHostname(input.origin.localHttpHost)) { - return false; - } - - const url = new URL(input.requestUrl); - if (!input.allowNonLoopbackRequestHost && !isLoopbackHostname(url.hostname)) { - return false; - } - - return input.origin.localHttpPort === endpointRequestPort(url); + return ( + isLoopbackHostname(input.origin.localHttpHost) && + input.origin.localHttpPort === endpointRequestPort(new URL(input.requestUrl)) + ); } export function isSupportedLinkProviderKind(request: RelayLinkProofRequest): boolean { From 84707afb90402afb39e2d27a5f34a6c517b498e8 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Sat, 7 Nov 2026 09:47:42 +0000 Subject: [PATCH 3/3] fix(server): point the remote link refusal at Sharing & access too Co-Authored-By: Claude Opus 5.5 --- apps/server/src/cloud/CloudLink.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/server/src/cloud/CloudLink.ts b/apps/server/src/cloud/CloudLink.ts index 55eccf05a1522..cb4c404188737 100644 --- a/apps/server/src/cloud/CloudLink.ts +++ b/apps/server/src/cloud/CloudLink.ts @@ -142,7 +142,7 @@ const ORIGIN_INVALID_MESSAGES = { endpoint: "Invalid managed endpoint origin.", local: "Could not resolve local environment origin.", remote: - "T3 Connect can only be turned on from the machine running this environment. Run `t3 connect link` on that machine.", + "T3 Connect can only be turned on from the machine running this environment. On that machine, use Settings → Sharing & access or run `t3 connect link`.", } as const; export class CloudLinkRelayConfigInvalidError extends Schema.TaggedError()(