From 05406e7bde25017531bd822ea684c5018b229a5a Mon Sep 17 00:00:00 2001 From: Jeremy Rose Date: Mon, 11 Jul 2022 16:28:09 -0700 Subject: [PATCH] feat: sandbox preloads by default (#32869) --- shell/browser/web_contents_preferences.cc | 4 +--- spec-main/fixtures/apps/libuv-hang/main.js | 3 ++- spec/webview-spec.js | 4 ++++ 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/shell/browser/web_contents_preferences.cc b/shell/browser/web_contents_preferences.cc index d15e99c36d6d6..300bf05b8a1bf 100644 --- a/shell/browser/web_contents_preferences.cc +++ b/shell/browser/web_contents_preferences.cc @@ -316,9 +316,7 @@ bool WebContentsPreferences::IsSandboxed() const { if (sandbox_) return *sandbox_; bool sandbox_disabled_by_default = - node_integration_ || node_integration_in_worker_ || preload_path_ || - !SessionPreferences::GetValidPreloads(web_contents_->GetBrowserContext()) - .empty(); + node_integration_ || node_integration_in_worker_; return !sandbox_disabled_by_default; } diff --git a/spec-main/fixtures/apps/libuv-hang/main.js b/spec-main/fixtures/apps/libuv-hang/main.js index 4ca4ef15d9024..3c9b9d0b6f26a 100644 --- a/spec-main/fixtures/apps/libuv-hang/main.js +++ b/spec-main/fixtures/apps/libuv-hang/main.js @@ -5,7 +5,8 @@ async function createWindow () { const mainWindow = new BrowserWindow({ show: false, webPreferences: { - preload: path.join(__dirname, 'preload.js') + preload: path.join(__dirname, 'preload.js'), + sandbox: false } }); diff --git a/spec/webview-spec.js b/spec/webview-spec.js index ff0f9c7964d68..9f53a7603e49b 100644 --- a/spec/webview-spec.js +++ b/spec/webview-spec.js @@ -243,6 +243,7 @@ describe(' tag', function () { it('preload script can require modules that still use "process" and "Buffer" when nodeintegration is off', async () => { const message = await startLoadingWebViewAndWaitForMessage(webview, { preload: `${fixtures}/module/preload-node-off-wrapper.js`, + webpreferences: 'sandbox=no', src: `file://${fixtures}/api/blank.html` }); @@ -288,6 +289,7 @@ describe(' tag', function () { it('works without script tag in page', async () => { const message = await startLoadingWebViewAndWaitForMessage(webview, { preload: `${fixtures}/module/preload.js`, + webpreferences: 'sandbox=no', src: `file://${fixtures}pages/base-page.html` }); @@ -303,6 +305,7 @@ describe(' tag', function () { it('resolves relative URLs', async () => { const message = await startLoadingWebViewAndWaitForMessage(webview, { preload: '../fixtures/module/preload.js', + webpreferences: 'sandbox=no', src: `file://${fixtures}/pages/e.html` }); @@ -390,6 +393,7 @@ describe(' tag', function () { const message = await startLoadingWebViewAndWaitForMessage(webview, { disablewebsecurity: '', preload: `${fixtures}/module/preload.js`, + webpreferences: 'sandbox=no', src: `file://${fixtures}/pages/e.html` });