Harden pairing and SSH prompt flows
- Preserve Tailscale Serve port when toggling exposure - Prevent reused hosted pairing tokens and double SSH responses - Refine endpoint compatibility for HTTP custom URLs
This commit is contained in:
1 parent
fc49669529
commit
bff64a3f19
8 files changed
+466
-741
No files matched your search
@@ -105,6 +105,27 @@ describe("desktopSettings", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("preserves the configured Tailscale Serve port when no new port is requested", () => {
|
||||
expect(
|
||||
setDesktopTailscaleServePreference(
|
||||
{
|
||||
serverExposureMode: "local-only",
|
||||
tailscaleServeEnabled: false,
|
||||
tailscaleServePort: 8443,
|
||||
updateChannel: "latest",
|
||||
updateChannelConfiguredByUser: false,
|
||||
},
|
||||
{ enabled: true },
|
||||
),
|
||||
).toEqual({
|
||||
serverExposureMode: "local-only",
|
||||
tailscaleServeEnabled: true,
|
||||
tailscaleServePort: 8443,
|
||||
updateChannel: "latest",
|
||||
updateChannelConfiguredByUser: false,
|
||||
});
|
||||
});
|
||||
|
||||
it("persists the requested nightly update channel", () => {
|
||||
expect(
|
||||
setDesktopUpdateChannelPreference(
|
||||
|
||||
@@ -45,7 +45,10 @@ export function setDesktopTailscaleServePreference(
|
||||
settings: DesktopSettings,
|
||||
input: { readonly enabled: boolean; readonly port?: number },
|
||||
): DesktopSettings {
|
||||
const port = normalizeTailscaleServePort(input.port);
|
||||
const port =
|
||||
input.port === undefined
|
||||
? settings.tailscaleServePort
|
||||
: normalizeTailscaleServePort(input.port);
|
||||
return settings.tailscaleServeEnabled === input.enabled && settings.tailscaleServePort === port
|
||||
? settings
|
||||
: {
|
||||
|
||||
@@ -38,6 +38,7 @@ import { RotatingFileSink } from "@t3tools/shared/logging";
|
||||
import { parsePersistedServerObservabilitySettings } from "@t3tools/shared/serverSettings";
|
||||
import { DEFAULT_DESKTOP_BACKEND_PORT, resolveDesktopBackendPort } from "./backendPort.ts";
|
||||
import {
|
||||
type DesktopSettings,
|
||||
DEFAULT_DESKTOP_SETTINGS,
|
||||
readDesktopSettings,
|
||||
setDesktopServerExposurePreference,
|
||||
@@ -402,13 +403,14 @@ async function applyDesktopServerExposureMode(
|
||||
return getDesktopServerExposureState();
|
||||
}
|
||||
|
||||
async function applyDesktopTailscaleServeEnabled(input: {
|
||||
readonly enabled: boolean;
|
||||
readonly port?: number;
|
||||
}): Promise<DesktopServerExposureState> {
|
||||
desktopSettings = setDesktopTailscaleServePreference(desktopSettings, input);
|
||||
async function applyDesktopTailscaleServeEnabled(
|
||||
nextSettings: DesktopSettings,
|
||||
): Promise<DesktopServerExposureState> {
|
||||
desktopSettings = nextSettings;
|
||||
writeDesktopSettings(DESKTOP_SETTINGS_PATH, desktopSettings);
|
||||
relaunchDesktopApp(input.enabled ? "tailscale-serve-enabled" : "tailscale-serve-disabled");
|
||||
relaunchDesktopApp(
|
||||
desktopSettings.tailscaleServeEnabled ? "tailscale-serve-enabled" : "tailscale-serve-disabled",
|
||||
);
|
||||
return getDesktopServerExposureState();
|
||||
}
|
||||
|
||||
@@ -1751,10 +1753,7 @@ function registerIpcHandlers(): void {
|
||||
if (nextSettings === desktopSettings) {
|
||||
return getDesktopServerExposureState();
|
||||
}
|
||||
return applyDesktopTailscaleServeEnabled({
|
||||
enabled: input.enabled,
|
||||
port: nextSettings.tailscaleServePort,
|
||||
});
|
||||
return applyDesktopTailscaleServeEnabled(nextSettings);
|
||||
});
|
||||
|
||||
ipcMain.removeHandler(GET_ADVERTISED_ENDPOINTS_CHANNEL);
|
||||
|
||||
@@ -101,7 +101,10 @@ describe("resolveDesktopCoreAdvertisedEndpoints", () => {
|
||||
resolveDesktopCoreAdvertisedEndpoints({
|
||||
port: 3773,
|
||||
exposure,
|
||||
customHttpsEndpointUrls: ["https://desktop.example.ts.net"],
|
||||
customHttpsEndpointUrls: [
|
||||
"https://desktop.example.ts.net",
|
||||
"http://desktop.example.test:3773",
|
||||
],
|
||||
}),
|
||||
).toEqual([
|
||||
{
|
||||
@@ -165,6 +168,26 @@ describe("resolveDesktopCoreAdvertisedEndpoints", () => {
|
||||
status: "unknown",
|
||||
description: "User-configured HTTPS endpoint for this desktop backend.",
|
||||
},
|
||||
{
|
||||
id: "manual:http://desktop.example.test:3773",
|
||||
label: "Custom HTTPS",
|
||||
provider: {
|
||||
id: "manual",
|
||||
label: "Manual",
|
||||
kind: "manual",
|
||||
isAddon: false,
|
||||
},
|
||||
httpBaseUrl: "http://desktop.example.test:3773/",
|
||||
wsBaseUrl: "ws://desktop.example.test:3773/",
|
||||
reachability: "public",
|
||||
compatibility: {
|
||||
hostedHttpsApp: "mixed-content-blocked",
|
||||
desktopApp: "compatible",
|
||||
},
|
||||
source: "user",
|
||||
status: "unknown",
|
||||
description: "User-configured HTTPS endpoint for this desktop backend.",
|
||||
},
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -49,6 +49,10 @@ const normalizeOptionalHost = (value: string | undefined): string | undefined =>
|
||||
const isUsableLanIpv4Address = (address: string): boolean =>
|
||||
!address.startsWith("127.") && !address.startsWith("169.254.");
|
||||
|
||||
function isHttpsEndpointUrl(value: string): boolean {
|
||||
return new URL(value).protocol === "https:";
|
||||
}
|
||||
|
||||
export function resolveLanAdvertisedHost(
|
||||
networkInterfaces: NodeJS.Dict<NetworkInterfaceInfo[]>,
|
||||
explicitHost: string | undefined,
|
||||
@@ -162,7 +166,9 @@ export function resolveDesktopCoreAdvertisedEndpoints(
|
||||
label: "Custom HTTPS",
|
||||
httpBaseUrl: customEndpointUrl,
|
||||
reachability: "public",
|
||||
hostedHttpsCompatibility: "compatible",
|
||||
...(isHttpsEndpointUrl(customEndpointUrl)
|
||||
? ({ hostedHttpsCompatibility: "compatible" } as const)
|
||||
: {}),
|
||||
status: "unknown",
|
||||
description: "User-configured HTTPS endpoint for this desktop backend.",
|
||||
}),
|
||||
|
||||
@@ -166,6 +166,7 @@ export function HostedPairingRouteSurface() {
|
||||
const [status, setStatus] = useState<"pairing" | "paired" | "error">("pairing");
|
||||
const [message, setMessage] = useState("Connecting to this backend.");
|
||||
const submitAttemptedRef = useRef(false);
|
||||
const tokenSubmittedRef = useRef(false);
|
||||
|
||||
const submitHostedPairingRequest = useCallback(async () => {
|
||||
const request = hostedPairingRequestRef.current;
|
||||
@@ -176,8 +177,15 @@ export function HostedPairingRouteSurface() {
|
||||
return;
|
||||
}
|
||||
|
||||
if (tokenSubmittedRef.current) {
|
||||
setStatus("error");
|
||||
setMessage("This one-time pairing token was already submitted. Request a new pairing link.");
|
||||
return;
|
||||
}
|
||||
|
||||
setStatus("pairing");
|
||||
setMessage("Connecting to this backend.");
|
||||
tokenSubmittedRef.current = true;
|
||||
|
||||
try {
|
||||
const record = await addSavedEnvironment({
|
||||
@@ -189,7 +197,9 @@ export function HostedPairingRouteSurface() {
|
||||
setMessage(`${record.label} is saved in this browser.`);
|
||||
} catch (error) {
|
||||
setStatus("error");
|
||||
setMessage(errorMessageFromUnknown(error));
|
||||
setMessage(
|
||||
`${errorMessageFromUnknown(error)} Request a new pairing link before trying again.`,
|
||||
);
|
||||
}
|
||||
}, []);
|
||||
|
||||
@@ -240,13 +250,15 @@ export function HostedPairingRouteSurface() {
|
||||
) : null}
|
||||
|
||||
<div className="mt-6 flex flex-wrap gap-2">
|
||||
<Button
|
||||
disabled={status === "pairing"}
|
||||
size="sm"
|
||||
onClick={() => void submitHostedPairingRequest()}
|
||||
>
|
||||
{status === "pairing" ? "Pairing..." : "Try again"}
|
||||
</Button>
|
||||
{status === "pairing" ? (
|
||||
<Button disabled size="sm">
|
||||
Pairing...
|
||||
</Button>
|
||||
) : !tokenSubmittedRef.current ? (
|
||||
<Button size="sm" onClick={() => void submitHostedPairingRequest()}>
|
||||
Try again
|
||||
</Button>
|
||||
) : null}
|
||||
{status === "paired" ? (
|
||||
<Button size="sm" variant="outline" onClick={() => (window.location.href = "/")}>
|
||||
Open app
|
||||
|
||||
@@ -20,8 +20,10 @@ function describeSshTarget(request: DesktopSshPasswordPromptRequest): string {
|
||||
export function SshPasswordPromptDialog() {
|
||||
const [queue, setQueue] = useState<readonly DesktopSshPasswordPromptRequest[]>([]);
|
||||
const [password, setPassword] = useState("");
|
||||
const [isResponding, setIsResponding] = useState(false);
|
||||
const currentRequest = queue[0] ?? null;
|
||||
const inputRef = useRef<HTMLInputElement | null>(null);
|
||||
const isRespondingRef = useRef(false);
|
||||
|
||||
useEffect(() => {
|
||||
const bridge = window.desktopBridge;
|
||||
@@ -50,17 +52,24 @@ export function SshPasswordPromptDialog() {
|
||||
}, [currentRequest]);
|
||||
|
||||
const respond = async (nextPassword: string | null) => {
|
||||
if (!currentRequest) {
|
||||
if (!currentRequest || isRespondingRef.current) {
|
||||
return;
|
||||
}
|
||||
|
||||
const requestId = currentRequest.requestId;
|
||||
setQueue((currentQueue) => currentQueue.slice(1));
|
||||
setPassword("");
|
||||
isRespondingRef.current = true;
|
||||
setIsResponding(true);
|
||||
try {
|
||||
await window.desktopBridge?.resolveSshPasswordPrompt(requestId, nextPassword);
|
||||
} catch (error) {
|
||||
console.error("Failed to resolve SSH password prompt.", error);
|
||||
} finally {
|
||||
setQueue((currentQueue) =>
|
||||
currentQueue[0]?.requestId === requestId ? currentQueue.slice(1) : currentQueue,
|
||||
);
|
||||
setPassword("");
|
||||
isRespondingRef.current = false;
|
||||
setIsResponding(false);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -76,38 +85,51 @@ export function SshPasswordPromptDialog() {
|
||||
}}
|
||||
>
|
||||
<DialogPopup className="max-w-md" showCloseButton={false}>
|
||||
<DialogHeader>
|
||||
<DialogTitle>SSH Password Required</DialogTitle>
|
||||
<DialogDescription>
|
||||
T3 needs your SSH password to connect to{" "}
|
||||
{target ? <code>{target}</code> : "the remote host"}. The password is passed to the
|
||||
local SSH process for this connection attempt and is not saved by T3 Code.
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
<DialogPanel className="space-y-3" scrollFade={false}>
|
||||
<div className="space-y-2">
|
||||
<p className="text-sm font-medium text-foreground">{currentRequest?.prompt}</p>
|
||||
<Input
|
||||
ref={inputRef}
|
||||
autoComplete="current-password"
|
||||
name="ssh-password"
|
||||
type="password"
|
||||
value={password}
|
||||
onChange={(event) => setPassword(event.target.value)}
|
||||
/>
|
||||
</div>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
Use SSH keys to avoid repeated password prompts on new SSH sessions.
|
||||
</p>
|
||||
</DialogPanel>
|
||||
<DialogFooter>
|
||||
<Button variant="outline" onClick={() => void respond(null)}>
|
||||
Cancel
|
||||
</Button>
|
||||
<Button onClick={() => void respond(password)} type="button">
|
||||
Continue
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
<form
|
||||
onSubmit={(event) => {
|
||||
event.preventDefault();
|
||||
void respond(password);
|
||||
}}
|
||||
>
|
||||
<DialogHeader>
|
||||
<DialogTitle>SSH Password Required</DialogTitle>
|
||||
<DialogDescription>
|
||||
T3 needs your SSH password to connect to{" "}
|
||||
{target ? <code>{target}</code> : "the remote host"}. The password is passed to the
|
||||
local SSH process for this connection attempt and is not saved by T3 Code.
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
<DialogPanel className="space-y-3" scrollFade={false}>
|
||||
<div className="space-y-2">
|
||||
<p className="text-sm font-medium text-foreground">{currentRequest?.prompt}</p>
|
||||
<Input
|
||||
ref={inputRef}
|
||||
autoComplete="current-password"
|
||||
disabled={isResponding}
|
||||
name="ssh-password"
|
||||
type="password"
|
||||
value={password}
|
||||
onChange={(event) => setPassword(event.target.value)}
|
||||
/>
|
||||
</div>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
Use SSH keys to avoid repeated password prompts on new SSH sessions.
|
||||
</p>
|
||||
</DialogPanel>
|
||||
<DialogFooter>
|
||||
<Button
|
||||
disabled={isResponding}
|
||||
type="button"
|
||||
variant="outline"
|
||||
onClick={() => void respond(null)}
|
||||
>
|
||||
Cancel
|
||||
</Button>
|
||||
<Button disabled={isResponding} type="submit">
|
||||
Continue
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</form>
|
||||
</DialogPopup>
|
||||
</Dialog>
|
||||
);
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user