Skip to content

Commit 0d51d5b

Browse files
fix(server): a server published through Tailscale Serve no longer reports itself as local-only (#35543)
1 parent 5b64e52 commit 0d51d5b

3 files changed

Lines changed: 31 additions & 2 deletions

File tree

‎apps/web/src/components/settings/ConnectionsSettings.logic.test.ts‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { type DesktopWslState, EnvironmentId } from "@t3tools/contracts";
22
import { describe, expect, it, vi } from "vite-plus/test";
33
import {
44
applyWslEnableSelection,
5+
isServerNetworkAccessible,
56
resolveAccessEnvironmentId,
67
resolveTailscaleServeBaseUrl,
78
selectQrEndpointOption,
@@ -201,3 +202,16 @@ describe("resolveAccessEnvironmentId", () => {
201202
);
202203
});
203204
});
205+
206+
describe("isServerNetworkAccessible", () => {
207+
const served = [{ kind: "tailnet", httpBaseUrl: "https://host.example.ts.net:8443/" }] as const;
208+
it.each([
209+
{ authPolicy: "remote-reachable", directEndpoints: undefined, expected: true },
210+
{ authPolicy: "loopback-browser", directEndpoints: undefined, expected: false },
211+
{ authPolicy: "loopback-browser", directEndpoints: [], expected: false },
212+
{ authPolicy: "loopback-browser", directEndpoints: served, expected: true },
213+
{ authPolicy: null, directEndpoints: served, expected: false },
214+
] as const)("$authPolicy with $directEndpoints.length endpoints", (row) => {
215+
expect(isServerNetworkAccessible(row)).toBe(row.expected);
216+
});
217+
});

‎apps/web/src/components/settings/ConnectionsSettings.logic.ts‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import {
2020
type DesktopUpdateState,
2121
type DesktopWslState,
2222
type EnvironmentId,
23+
type ServerAuthPolicy,
24+
type ServerDirectEndpoint,
2325
} from "@t3tools/contracts";
2426
import {
2527
getDesktopUpdateDownloadedVersion,
@@ -369,6 +371,15 @@ export function selectPairingEndpoint(
369371
);
370372
}
371373

374+
/** A loopback server advertises a direct endpoint only once its Tailscale Serve URL answers. */
375+
export function isServerNetworkAccessible(input: {
376+
readonly authPolicy: ServerAuthPolicy | null;
377+
readonly directEndpoints: ReadonlyArray<ServerDirectEndpoint> | undefined;
378+
}): boolean {
379+
if (input.authPolicy === "remote-reachable") return true;
380+
return input.authPolicy === "loopback-browser" && (input.directEndpoints?.length ?? 0) > 0;
381+
}
382+
372383
export function isTailscaleHttpsEndpoint(endpoint: AdvertisedEndpoint): boolean {
373384
return endpoint.id.startsWith("tailscale-magicdns:");
374385
}

‎apps/web/src/components/settings/ConnectionsSettings.tsx‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ import {
122122
toDesktopPairingLinkRecord,
123123
toDesktopClientSessionRecord,
124124
selectPairingEndpoint,
125+
isServerNetworkAccessible,
125126
isTailscaleHttpsEndpoint,
126127
endpointDefaultPreferenceKey,
127128
} from "./ConnectionsSettings.logic";
@@ -439,7 +440,10 @@ function ConnectionsSettingsContent({
439440
})();
440441
const isLocalBackendNetworkAccessible = desktopBridge
441442
? desktopServerExposureState?.mode === "network-accessible"
442-
: currentAuthPolicy === "remote-reachable";
443+
: isServerNetworkAccessible({
444+
authPolicy: currentAuthPolicy,
445+
directEndpoints: accessEnvironment?.serverConfig?.directEndpoints,
446+
});
443447
const trimmedTailscaleServePortInput = tailscaleServePortInput.trim();
444448
const parsedTailscaleServePort = Number(trimmedTailscaleServePortInput);
445449
const isTailscaleServePortValid =
@@ -1098,7 +1102,7 @@ function ConnectionsSettingsContent({
10981102
description={
10991103
desktopBridge
11001104
? "This connection cannot view or change network exposure."
1101-
: currentAuthPolicy === "remote-reachable"
1105+
: isLocalBackendNetworkAccessible
11021106
? "Remote access is already configured. Change network exposure where the server starts."
11031107
: currentAuthPolicy === "loopback-browser"
11041108
? "Only this machine can connect. Restart with a non-loopback host for remote pairing."

0 commit comments

Comments
 (0)