Skip to content

fix: ensure history navigations are sandboxed-iframe-aware - #35420

Merged
zcbenz merged 1 commit into
electron:mainfrom
jeremyspiegel:sandboxed-iframe
Sep 9, 2022
Merged

zcbenz merged 1 commit into
electron:mainfrom
jeremyspiegel:sandboxed-iframe

Conversation

@jeremyspiegel

Copy link
Copy Markdown
Contributor

Description of Change

This fixes #35391

When a sandboxed iframe calls history.go(), the renderer calls into the browser at RenderFrameHostImpl::GoToEntryAtOffset:

  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);
    }
  }

The call to delegate_->IsAllowedToGoToEntryAtOffset(offset) goes to WebContentsImpl::IsAllowedToGoToEntryAtOffset:

bool WebContentsImpl::IsAllowedToGoToEntryAtOffset(int32_t offset) {
  // TODO(https://crbug.com/1170277): This should probably be renamed to
  // WebContentsDelegate::IsAllowedToGoToEntryAtOffset or
  // ShouldGoToEntryAtOffset
  return !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:

bool WebContents::OnGoToEntryOffset(int offset) {
  GoToOffset(offset);
  return false;
}

This change removes the override of OnGoToEntryOffset in electron::api::WebContents (the default implementation of WebContentsDelegate::OnGoToEntryOffset is just return true).

The override was added by @deepak1556 in #3875 to fix #3734. I think that the calling Chrome code may have changed since then, since it was so long ago (2015) and because of the comment in WebContentsImpl::IsAllowedToGoToEntryAtOffset about needing to rename WebContentsDelegate::OnGoToEntryOffset to WebContentsDelegate::IsAllowedToGoToEntryAtOffset or ShouldGoToEntryAtOffset.

Checklist

Release Notes

Notes: Fixed issue with history.back() in sandboxed iframes affecting parent browsing context.

@electron-cation electron-cation Bot added the new-pr 🌱 PR opened recently label Aug 24, 2022

@deepak1556 deepak1556 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this issue!

Electron had the override before for an older process architecture where Renderer process would always restart expect for history navigations. But we have since then aligned our process architecture to that of Chromium and this hack is not required.

@deepak1556 deepak1556 added target/19-x-y target/21-x-y PR should also be added to the "21-x-y" branch. semver/patch backwards-compatible bug fixes labels Aug 24, 2022
@jeremyspiegel

Copy link
Copy Markdown
Contributor Author

Great, thank you for the reviews @deepak1556 and @codebytere!

@electron-cation electron-cation Bot removed the new-pr 🌱 PR opened recently label Aug 25, 2022
@zcbenz

zcbenz commented Aug 29, 2022

Copy link
Copy Markdown
Contributor

@jeremyspiegel Can you rebase this PR on latest main? It should be able to fix the CI failure.

@zcbenz
zcbenz force-pushed the sandboxed-iframe branch 2 times, most recently from ba36670 to f7fa823 Compare September 1, 2022 07:58
@jeremyspiegel

Copy link
Copy Markdown
Contributor Author

@zcbenz I've rebased on latest main and the checks are passing now.

@zcbenz
zcbenz merged commit 730d918 into electron:main Sep 9, 2022
@release-clerk

release-clerk Bot commented Sep 9, 2022

Copy link
Copy Markdown

Release Notes Persisted

Fixed issue with history.back() in sandboxed iframes affecting parent browsing context.

@trop

trop Bot commented Sep 9, 2022

Copy link
Copy Markdown
Contributor

I have automatically backported this PR to "19-x-y", please check out #35621

@trop trop Bot added the in-flight/19-x-y label Sep 9, 2022
@trop

trop Bot commented Sep 9, 2022

Copy link
Copy Markdown
Contributor

I have automatically backported this PR to "20-x-y", please check out #35622

@trop

trop Bot commented Sep 9, 2022

Copy link
Copy Markdown
Contributor

I have automatically backported this PR to "21-x-y", please check out #35623

@trop trop Bot added merged/19-x-y merged/21-x-y PR was merged to the "21-x-y" branch. and removed target/21-x-y PR should also be added to the "21-x-y" branch. in-flight/19-x-y labels Sep 9, 2022
@jeremyspiegel
jeremyspiegel deleted the sandboxed-iframe branch October 12, 2022 00:08
khalwa pushed a commit to solarwindscloud/electron that referenced this pull request Feb 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merged/21-x-y PR was merged to the "21-x-y" branch. semver/patch backwards-compatible bug fixes

Projects

None yet

4 participants