Skip to content

Commit 2a180c7

Browse files
only21milclaudemaria-rcks
authored
fix(desktop): compare custom renderer scheme and authority explicitly (#21445)
Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: maria-rcks <[email protected]>
1 parent f3bbd0f commit 2a180c7

2 files changed

Lines changed: 59 additions & 2 deletions

File tree

‎apps/desktop/src/window/DesktopWindow.test.ts‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,45 @@ describe("DesktopWindow", () => {
472472
);
473473
});
474474

475+
it("rejects renderer navigations whose origin only serializes as null", () => {
476+
for (const applicationUrl of ["t3code://app/", "t3code-dev://app/"]) {
477+
assert.isTrue(
478+
DesktopWindow.isSameOriginRendererNavigation({
479+
applicationUrl,
480+
navigationUrl: `${applicationUrl}threads?id=1#latest`,
481+
}),
482+
applicationUrl,
483+
);
484+
}
485+
for (const navigationUrl of [
486+
"t3code://other/",
487+
"t3code://app.example/",
488+
"t3code://app:8080/",
489+
"t3code://user@other/",
490+
"t3code:app",
491+
"t3code-dev://app/",
492+
"file:///etc/passwd",
493+
"data:text/html,<p>hi</p>",
494+
"javascript:alert(1)",
495+
"about:blank",
496+
"blob:t3code://app/0b5e2c4a",
497+
]) {
498+
assert.isFalse(
499+
DesktopWindow.isSameOriginRendererNavigation({
500+
applicationUrl: "t3code://app/",
501+
navigationUrl,
502+
}),
503+
navigationUrl,
504+
);
505+
}
506+
assert.isFalse(
507+
DesktopWindow.isSameOriginRendererNavigation({
508+
applicationUrl: "data:text/html,app",
509+
navigationUrl: "data:text/html,other",
510+
}),
511+
);
512+
});
513+
475514
it.effect(
476515
"opens and reopens the window without backend readiness when local execution is disabled",
477516
() =>
@@ -973,6 +1012,17 @@ describe("DesktopWindow", () => {
9731012
if (!willNavigate) {
9741013
return yield* Effect.die("will-navigate listener was not registered");
9751014
}
1015+
for (const [url, expectedPrevented] of [
1016+
["t3code-dev://app/threads?id=1#latest", false],
1017+
["t3code-dev://other/", true],
1018+
["t3code://app/", true],
1019+
] as const) {
1020+
const preventDefault = vi.fn();
1021+
willNavigate({ preventDefault }, url);
1022+
assert.equal(preventDefault.mock.calls.length, expectedPrevented ? 1 : 0, url);
1023+
}
1024+
assert.deepEqual(openedExternalUrls, []);
1025+
9761026
let prevented = false;
9771027
willNavigate(
9781028
{

‎apps/desktop/src/window/DesktopWindow.ts‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,12 +183,19 @@ function buildConnectingSplashDataUrl(shouldUseDarkColors: boolean): string {
183183
return `data:text/html;charset=utf-8,${encodeURIComponent(html)}`;
184184
}
185185

186-
function isSameOriginRendererNavigation(input: {
186+
export function isSameOriginRendererNavigation(input: {
187187
readonly applicationUrl: string;
188188
readonly navigationUrl: string;
189189
}): boolean {
190190
try {
191-
return new URL(input.applicationUrl).origin === new URL(input.navigationUrl).origin;
191+
const applicationUrl = new URL(input.applicationUrl);
192+
const navigationUrl = new URL(input.navigationUrl);
193+
// Node serializes custom-scheme origins as "null", even for different hosts and schemes.
194+
return (
195+
applicationUrl.host !== "" &&
196+
navigationUrl.protocol === applicationUrl.protocol &&
197+
navigationUrl.host === applicationUrl.host
198+
);
192199
} catch {
193200
return false;
194201
}

0 commit comments

Comments
 (0)