Skip to content

Commit c22f9e2

Browse files
committed
fix(desktop): simplify popup scheme validation and cover denied protocols
1 parent 763568f commit c22f9e2

2 files changed

Lines changed: 14 additions & 18 deletions

File tree

‎apps/desktop/src/preview/Manager.test.ts‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,12 @@ describe("previewWindowOpenAction", () => {
8686
).toBe("popup");
8787
});
8888

89+
it("opens HTTP links in preview tabs", () => {
90+
for (const disposition of ["foreground-tab", "background-tab"] as const) {
91+
expect(PreviewManager.previewWindowOpenAction(details({ disposition }))).toBe("new-tab");
92+
}
93+
});
94+
8995
it("keeps a form POST with a body on the in-place path", () => {
9096
const postBody = { data: [], contentType: "application/x-www-form-urlencoded" };
9197
expect(
@@ -106,17 +112,19 @@ describe("previewWindowOpenAction", () => {
106112
});
107113

108114
it("denies local and inline schemes that no page could open in place itself", () => {
109-
// `loadURL` is a browser-initiated load, so `data:` would get past the check that
110-
// stops a page from opening it as a top-level document.
111115
for (const url of [
112-
"file:///etc/passwd",
113116
"data:text/html,<h1>hi</h1>",
117+
"DaTa:text/html,<h1>hi</h1>",
118+
"file:///etc/passwd",
114119
"javascript:alert(1)",
115120
"view-source:https://example.com",
116121
"chrome://gpu",
122+
"about:srcdoc",
123+
"devtools://devtools/bundled/inspector.html",
124+
"filesystem:https://example.com/temporary/page.html",
117125
"not a url",
118126
]) {
119-
for (const disposition of ["new-window", "foreground-tab"] as const) {
127+
for (const disposition of ["new-window", "foreground-tab", "background-tab"] as const) {
120128
expect(PreviewManager.previewWindowOpenAction(details({ url, disposition }))).toBe("deny");
121129
}
122130
}

‎apps/desktop/src/preview/Manager.ts‎

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -424,11 +424,7 @@ type OpenLinkListener = (event: DesktopPreviewOpenLinkEvent) => Effect.Effect<vo
424424
// about:blank inherits relaxed guest preferences; external editor schemes must reach the OS handler.
425425
const POPUP_PROTOCOLS = new Set(["http:", "https:"]);
426426

427-
/**
428-
* The in-place path runs `loadURL`, a browser-initiated load, so a `data:` popup skips the check
429-
* that stops a page from navigating its own top frame to `data:`. The other local schemes are
430-
* denied too, so this does not depend on how Chromium filters them before the handler runs.
431-
*/
427+
// Main-process loadURL bypasses Chromium's renderer-side restrictions on local and inline URLs.
432428
const IN_PLACE_DENIED_PROTOCOLS = new Set([
433429
"about:",
434430
"chrome:",
@@ -440,14 +436,6 @@ const IN_PLACE_DENIED_PROTOCOLS = new Set([
440436
"view-source:",
441437
]);
442438

443-
const urlProtocol = (rawUrl: string): string | undefined => {
444-
try {
445-
return new URL(rawUrl).protocol;
446-
} catch {
447-
return undefined;
448-
}
449-
};
450-
451439
/** Popups bypass will-attach-webview hardening and would inherit the picker's contextIsolation:false. */
452440
const POPUP_WINDOW_OPTIONS = {
453441
webPreferences: {
@@ -466,7 +454,7 @@ export const previewWindowOpenAction = (details: {
466454
readonly disposition: Electron.HandlerDetails["disposition"];
467455
readonly postBody?: Electron.PostBody;
468456
}): "popup" | "new-tab" | "navigate" | "deny" => {
469-
const protocol = urlProtocol(details.url);
457+
const protocol = URL.parse(details.url)?.protocol;
470458
// MSAL redirects on a denied blank popup; navigating the tab would destroy that fallback.
471459
if (protocol === undefined || IN_PLACE_DENIED_PROTOCOLS.has(protocol)) return "deny";
472460
if (!POPUP_PROTOCOLS.has(protocol)) return "navigate";

0 commit comments

Comments
 (0)