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
This commit is contained in:
Julius Marminge committed 2026-04-28 09:30:19 -07:00
1 parent bff64a3f19
commit bae05b2e88
3 files changed
+25 -15

No files matched your search

+1
View File
@@ -104,6 +104,7 @@ describe("resolveDesktopCoreAdvertisedEndpoints", () => {
customHttpsEndpointUrls: [
"https://desktop.example.ts.net",
"http://desktop.example.test:3773",
"not-a-url",
],
}),
).toEqual([
+22 -14
View File
@@ -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;
@@ -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.`,
);
}
}, []);