Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
import { Button } from "../ui/button";
import { Textarea } from "../ui/textarea";
import {
isLoopbackHostname,
type ServerClientSessionRecord,
type ServerPairingLinkRecord,
} from "~/environments/primary";
Expand Down Expand Up @@ -208,9 +207,9 @@ const PairingLinkListRow = memo(function PairingLinkListRow({
endpointPairingUrl ??
(credential && endpointUrl != null && endpointUrl !== ""
? (hostedPairingUrl ?? resolveDesktopPairingUrl(endpointUrl, credential))
: !servedByEnvironment || isLoopbackHostname(window.location.hostname)
? null
: currentOriginPairingUrl);
: servedByEnvironment
? currentOriginPairingUrl
: null);
const [failedCopyValue, setFailedCopyValue] = useState<string | null>(null);
const revealValue = failedCopyValue ?? shareablePairingUrl ?? credential ?? "";
const isRevealValueUrl = revealValue !== credential;
Expand Down
13 changes: 13 additions & 0 deletions apps/web/src/components/settings/ConnectionsSettings.logic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
isServerNetworkAccessible,
parseManualDesktopSshTarget,
resolveAccessEnvironmentId,
resolveCurrentOriginPairingUrl,
resolveTailscaleServeBaseUrl,
selectQrEndpointOption,
togglePairingScopeSelection,
Expand Down Expand Up @@ -53,6 +54,18 @@ describe("parseManualDesktopSshTarget", () => {
});
});

describe("resolveCurrentOriginPairingUrl", () => {
it.each([
["t3code://app/settings/connections", null],
["http://127.0.0.1:3774/settings", null],
["http://localhost:5173/", null],
["https://host.example.ts.net/settings", "https://host.example.ts.net/pair#token=abc"],
["http://192.168.1.20:3773/", "http://192.168.1.20:3773/pair#token=abc"],
])("from %s", (href, expected) => {
expect(resolveCurrentOriginPairingUrl("abc", href)).toBe(expected);
});
});

describe("resolveTailscaleServeBaseUrl", () => {
it.each([
["https://host.tail.ts.net:441/", 443, "https://host.tail.ts.net"],
Expand Down
12 changes: 10 additions & 2 deletions apps/web/src/components/settings/ConnectionsSettings.logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { getPairingTokenFromUrl, setPairingTokenOnUrl } from "@t3tools/shared/re
import { readHostedPairingRequest } from "../../hostedPairing";
import { m, type MessageResolver } from "../../i18n/messages";
import {
isLoopbackHostname,
type ServerClientSessionRecord,
type ServerPairingLinkRecord,
} from "~/environments/primary";
Expand Down Expand Up @@ -448,8 +449,15 @@ export function resolveAdvertisedEndpointPairingUrl(
return resolveDesktopPairingUrl(endpoint.httpBaseUrl, credential);
}

export function resolveCurrentOriginPairingUrl(credential: string): string {
const url = new URL("/pair", window.location.href);
export function resolveCurrentOriginPairingUrl(
credential: string,
currentHref: string = window.location.href,
): string | null {
const url = new URL("/pair", currentHref);
// The packaged desktop window loads from t3code://app, which no other device can open.
if ((url.protocol !== "http:" && url.protocol !== "https:") || isLoopbackHostname(url.hostname)) {
return null;
}
return setPairingTokenOnUrl(url, credential).toString();
}

Expand Down
Loading