Skip to content

Commit 67870a7

Browse files
committed
fix: newly spawned untrusted windows shouldnt have electon api injection at all
1 parent f242f39 commit 67870a7

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

src-electron/ipc-security.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const _trustedWebContents = new Set();
2020
* - Dev stage: trustedElectronDomains + all localhost URLs
2121
* - Other stages: only trustedElectronDomains
2222
*/
23-
function _isTrustedOrigin(url) {
23+
function isTrustedOrigin(url) {
2424
if (!url) return false;
2525

2626
// Check against trustedElectronDomains
@@ -51,7 +51,7 @@ function _isTrustedOrigin(url) {
5151
*/
5252
function updateTrustStatus(webContents) {
5353
const url = webContents.getURL();
54-
if (_isTrustedOrigin(url)) {
54+
if (isTrustedOrigin(url)) {
5555
_trustedWebContents.add(webContents.id);
5656
} else {
5757
_trustedWebContents.delete(webContents.id);
@@ -84,6 +84,7 @@ function assertTrusted(event) {
8484
}
8585

8686
module.exports = {
87+
isTrustedOrigin,
8788
updateTrustStatus,
8889
cleanupTrust,
8990
assertTrusted

src-electron/main-window-ipc.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const { ipcMain, BrowserWindow, shell, clipboard } = require('electron');
22
const path = require('path');
33
const { spawn } = require('child_process');
44
const { cleanupWindowTrust } = require('./main-cred-ipc');
5-
const { updateTrustStatus, cleanupTrust, assertTrusted } = require('./ipc-security');
5+
const { isTrustedOrigin, updateTrustStatus, cleanupTrust, assertTrusted } = require('./ipc-security');
66

77
const PHOENIX_WINDOW_PREFIX = 'phcode-';
88
const PHOENIX_EXTENSION_WINDOW_PREFIX = 'extn-';
@@ -91,8 +91,8 @@ function registerWindowIpcHandlers() {
9191
sandbox: true
9292
};
9393

94-
// Only inject preload for Phoenix windows, not extensions
95-
if (!isExtension) {
94+
// Only inject preload for Phoenix windows with trusted URLs, not extensions
95+
if (!isExtension && isTrustedOrigin(url)) {
9696
webPreferences.preload = path.join(__dirname, 'preload.js');
9797
}
9898

0 commit comments

Comments
 (0)