From 135c8c34ece0fa1fa04bad6e99af4bca5f788343 Mon Sep 17 00:00:00 2001 From: "trop[bot]" <37223003+trop[bot]@users.noreply.github.com> Date: Tue, 13 Sep 2022 08:14:46 -0700 Subject: [PATCH] fix: ensure history navigations are sandboxed-iframe-aware (#35623) Co-authored-by: Jeremy Spiegel --- .../browser/api/electron_api_web_contents.cc | 5 ---- shell/browser/api/electron_api_web_contents.h | 1 - spec-main/chromium-spec.ts | 28 +++++++++++++++++++ 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/shell/browser/api/electron_api_web_contents.cc b/shell/browser/api/electron_api_web_contents.cc index 7415e0c5d00f9..030ccee6f0f7e 100644 --- a/shell/browser/api/electron_api_web_contents.cc +++ b/shell/browser/api/electron_api_web_contents.cc @@ -1380,11 +1380,6 @@ bool WebContents::HandleContextMenu(content::RenderFrameHost& render_frame_host, return true; } -bool WebContents::OnGoToEntryOffset(int offset) { - GoToOffset(offset); - return false; -} - void WebContents::FindReply(content::WebContents* web_contents, int request_id, int number_of_matches, diff --git a/shell/browser/api/electron_api_web_contents.h b/shell/browser/api/electron_api_web_contents.h index 7ccc525f56096..45b4846d2f9b4 100644 --- a/shell/browser/api/electron_api_web_contents.h +++ b/shell/browser/api/electron_api_web_contents.h @@ -534,7 +534,6 @@ class WebContents : public ExclusiveAccessContext, content::RenderWidgetHost* render_widget_host) override; bool HandleContextMenu(content::RenderFrameHost& render_frame_host, const content::ContextMenuParams& params) override; - bool OnGoToEntryOffset(int offset) override; void FindReply(content::WebContents* web_contents, int request_id, int number_of_matches, diff --git a/spec-main/chromium-spec.ts b/spec-main/chromium-spec.ts index cf241bccbc719..957fab8b67ccf 100644 --- a/spec-main/chromium-spec.ts +++ b/spec-main/chromium-spec.ts @@ -1571,6 +1571,34 @@ describe('chromium features', () => { expect((w.webContents as any).length()).to.equal(2); }); }); + + describe('window.history.back', () => { + it('should not allow sandboxed iframe to modify main frame state', async () => { + const w = new BrowserWindow({ show: false }); + w.loadURL('data:text/html,'); + await Promise.all([ + emittedOnce(w.webContents, 'navigation-entry-committed'), + emittedOnce(w.webContents, 'did-frame-navigate'), + emittedOnce(w.webContents, 'did-navigate') + ]); + + w.webContents.executeJavaScript('window.history.pushState(1, "")'); + await Promise.all([ + emittedOnce(w.webContents, 'navigation-entry-committed'), + emittedOnce(w.webContents, 'did-navigate-in-page') + ]); + + (w.webContents as any).once('navigation-entry-committed', () => { + expect.fail('Unexpected navigation-entry-committed'); + }); + w.webContents.once('did-navigate-in-page', () => { + expect.fail('Unexpected did-navigate-in-page'); + }); + await w.webContents.mainFrame.frames[0].executeJavaScript('window.history.back()'); + expect(await w.webContents.executeJavaScript('window.history.state')).to.equal(1); + expect((w.webContents as any).getActiveIndex()).to.equal(1); + }); + }); }); describe('chrome://media-internals', () => {