You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug]: sandboxed iframe can modify history of parent browsing context #35391
and click the link to page2.html. Then click the Go Back button that is shown in the iframe on Page 2 and notice that the window is navigated back to page1.html.
Edit: That change (#28839) removed params.should_clear_history_list = true; in WebContents::LoadURL which made it seem like the issue was introduced there, but that's only because my test relied on setting up a history by calling mainWindow.loadURL twice. I modified my repro gist to use a link from page 1 to page 2 and with that code I see the issue going back as far as Electron 10.
if (delegate_->IsAllowedToGoToEntryAtOffset(offset)) {
if (IsSandboxed(network::mojom::WebSandboxFlags::kTopNavigation)) {
// Keep track of whether this is a session history from a sandboxed iframe// with top level navigation disallowed.
frame_tree_->controller().GoToOffsetInSandboxedFrame(
offset, GetFrameTreeNodeId());
} else {
frame_tree_->controller().GoToOffsetFromRenderer(offset);
}
}
boolWebContentsImpl::IsAllowedToGoToEntryAtOffset(int32_t offset) {
// TODO(https://crbug.com/1170277): This should probably be renamed to// WebContentsDelegate::IsAllowedToGoToEntryAtOffset or// ShouldGoToEntryAtOffsetreturn !delegate_ || delegate_->OnGoToEntryOffset(offset);
}
And Electron's implementation of delegate_->OnGoToEntryOffset(offset) in electron::api::WebContents::OnGoToEntryOffset handles the navigation itself, rather than allowing RenderFrameHostImpl::GoToEntryAtOffset's default behavior of navigating in the frame instead of the parent context:
I tried removing the override of OnGoToEntryOffset in electron::api::WebContents (the default implementation of WebContentsDelegate::OnGoToEntryOffset is just return true), and that fixed the issue for me.
Activity
jeremyspiegel commentedon Aug 20, 2022
I did some tests on older Electron versions and it appears this was introduced in between Electron 14.0.0-nightly.20210427 and 14.0.0-nightly.20210430, maybe related to this change: #28839?Edit: That change (#28839) removed
params.should_clear_history_list = true;inWebContents::LoadURLwhich made it seem like the issue was introduced there, but that's only because my test relied on setting up a history by callingmainWindow.loadURLtwice. I modified my repro gist to use a link from page 1 to page 2 and with that code I see the issue going back as far as Electron 10.jeremyspiegel commentedon Aug 23, 2022
I believe I've figured out the issue.
When the sandboxed iframe calls
history.back(), the renderer calls into the browser at RenderFrameHostImpl::GoToEntryAtOffset:The call to
delegate_->IsAllowedToGoToEntryAtOffset(offset)goes to WebContentsImpl::IsAllowedToGoToEntryAtOffset:And Electron's implementation of
delegate_->OnGoToEntryOffset(offset)in electron::api::WebContents::OnGoToEntryOffset handles the navigation itself, rather than allowingRenderFrameHostImpl::GoToEntryAtOffset's default behavior of navigating in the frame instead of the parent context:I tried removing the override of
OnGoToEntryOffsetinelectron::api::WebContents(the default implementation ofWebContentsDelegate::OnGoToEntryOffsetis justreturn true), and that fixed the issue for me.