From bae05b2e88e77c45e55c44c83c1622f4d3d3a735 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Tue, 28 Apr 2026 09:30:19 -0700 Subject: [PATCH] Handle malformed custom endpoints in pairing flow - Ignore invalid custom HTTPS endpoint URLs when building desktop exposure - Reset pairing submission state after backend errors and clarify retry guidance - Add coverage for malformed endpoint inputs --- apps/desktop/src/serverExposure.test.ts | 1 + apps/desktop/src/serverExposure.ts | 36 +++++++++++-------- .../components/auth/PairingRouteSurface.tsx | 3 +- 3 files changed, 25 insertions(+), 15 deletions(-) diff --git a/apps/desktop/src/serverExposure.test.ts b/apps/desktop/src/serverExposure.test.ts index 3c101628e0..d12375e0cb 100644 --- a/apps/desktop/src/serverExposure.test.ts +++ b/apps/desktop/src/serverExposure.test.ts @@ -104,6 +104,7 @@ describe("resolveDesktopCoreAdvertisedEndpoints", () => { customHttpsEndpointUrls: [ "https://desktop.example.ts.net", "http://desktop.example.test:3773", + "not-a-url", ], }), ).toEqual([ diff --git a/apps/desktop/src/serverExposure.ts b/apps/desktop/src/serverExposure.ts index 332f34cfee..035e2e155a 100644 --- a/apps/desktop/src/serverExposure.ts +++ b/apps/desktop/src/serverExposure.ts @@ -50,7 +50,11 @@ const isUsableLanIpv4Address = (address: string): boolean => !address.startsWith("127.") && !address.startsWith("169.254."); function isHttpsEndpointUrl(value: string): boolean { - return new URL(value).protocol === "https:"; + try { + return new URL(value).protocol === "https:"; + } catch { + return false; + } } export function resolveLanAdvertisedHost( @@ -160,19 +164,23 @@ export function resolveDesktopCoreAdvertisedEndpoints( } for (const customEndpointUrl of input.customHttpsEndpointUrls ?? []) { - endpoints.push( - createManualEndpoint({ - id: `manual:${customEndpointUrl}`, - label: "Custom HTTPS", - httpBaseUrl: customEndpointUrl, - reachability: "public", - ...(isHttpsEndpointUrl(customEndpointUrl) - ? ({ hostedHttpsCompatibility: "compatible" } as const) - : {}), - status: "unknown", - description: "User-configured HTTPS endpoint for this desktop backend.", - }), - ); + try { + endpoints.push( + createManualEndpoint({ + id: `manual:${customEndpointUrl}`, + label: "Custom HTTPS", + httpBaseUrl: customEndpointUrl, + reachability: "public", + ...(isHttpsEndpointUrl(customEndpointUrl) + ? ({ hostedHttpsCompatibility: "compatible" } as const) + : {}), + status: "unknown", + description: "User-configured HTTPS endpoint for this desktop backend.", + }), + ); + } catch { + // Ignore malformed user-configured endpoints without dropping valid endpoints. + } } return endpoints; diff --git a/apps/web/src/components/auth/PairingRouteSurface.tsx b/apps/web/src/components/auth/PairingRouteSurface.tsx index d301d6f410..3e5493771e 100644 --- a/apps/web/src/components/auth/PairingRouteSurface.tsx +++ b/apps/web/src/components/auth/PairingRouteSurface.tsx @@ -196,9 +196,10 @@ export function HostedPairingRouteSurface() { setStatus("paired"); setMessage(`${record.label} is saved in this browser.`); } catch (error) { + tokenSubmittedRef.current = false; setStatus("error"); setMessage( - `${errorMessageFromUnknown(error)} Request a new pairing link before trying again.`, + `${errorMessageFromUnknown(error)} If the backend accepted this one-time token, request a new pairing link before retrying.`, ); } }, []);