fix(desktop): oauth popups open from the browser preview #8435
Mergedwalid-baharwal(GitHub profile, opens in a new tab)merged 5 commits into
main fromrefs/pull/8435/headmerged by juliusmarminge View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:M
- apps/desktop/src/preview/Manager.ts line 1770Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -1704,4 +1760,5 @@17041760 wc.on("audio-state-changed", audioStateChanged);17051761 wc.ipc.on(HUMAN_INPUT_CHANNEL, humanInput);17061762 wc.ipc.on(MOUSE_NAVIGATE_CHANNEL, mouseNavigate);1707- wc.setWindowOpenHandler(({ url }) => {1763+ wc.setWindowOpenHandler((details) => {1764+ if (previewWindowOpenAction(details) === "popup") {apps/desktop/src/preview/Manager.ts line 490Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -436,0 +471,21 @@471+ nodeIntegration: false,472+ nodeIntegrationInSubFrames: false,473+ },474+};475+476+/**477+ * Decides what a preview page's `window.open` should do.478+ *479+ * `"popup"` opens a real window, which scripted popups need: denying them makes480+ * `window.open()` return `null` (OAuth SDKs report that as a blocked popup), and481+ * navigating the preview tab instead destroys the opener the popup has to482+ * `postMessage` its result back to.483+ *484+ * `target="_blank"` links arrive as a tab disposition and keep loading in the485+ * preview tab, which is what people expect from a link inside a preview.486+ */487+export const previewWindowOpenAction = (details: {488+ readonly url: string;489+ readonly disposition: Electron.HandlerDetails["disposition"];490+}): "popup" | "navigate" =>491+ details.disposition === "new-window" && isPopupUrl(details.url) ? "popup" : "navigate";
- apps/web/src/browser/HostedBrowserWebview.tsx lines 261 to 264OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -259,3 +258,7 @@259258 <webview260259 key={webviewGeneration}261260 ref={setWebviewRef}261+ // Must be an attribute on the element itself: Electron reads it when the262+ // guest attaches, so setting it from the ref callback lands too late and263+ // the guest attaches with popups disabled.264+ allowpopups="true"
- @@ -436,0 +453,21 @@453+ } catch {454+ return false;455+ }456+};457+458+/**459+ * Preferences for a popup a preview page opens.460+ *461+ * A popup is not a webview attach, so the `will-attach-webview` hardening in462+ * `DesktopWindow` never sees it, and an unoverridden child would inherit the463+ * guest's relaxed posture: the picker preload needs `contextIsolation: false`464+ * to share `globalThis` with the previewed page, and no OAuth provider should465+ * get that. The window keeps the opener and the guest session either way.466+ */467+const POPUP_WINDOW_OPTIONS = {468+ webPreferences: {469+ contextIsolation: true,470+ nodeIntegration: false,471+ sandbox: true,472+ },473+} satisfies Electron.BrowserWindowConstructorOptions;
juliusmarminge merged this0e2905e
juliusmarminge closed this
Sign in to join this conversation.





Important
Review skipped#
Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID:
e56baf0c-bdec-4082-8fa9-d71789606066You can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
Comment `@coderabbitai help` to get the list of available commands.