Skip to content

fix: window.open site instance should belong to same browsing instance - #15216

Merged
alexeykuzmin merged 10 commits into
electron:masterfrom
ppontes:ppontes/8100-use-proper-site-instance-candidate
Nov 12, 2018
Merged

alexeykuzmin merged 10 commits into
electron:masterfrom
ppontes:ppontes/8100-use-proper-site-instance-candidate

Conversation

@ppontes

@ppontes ppontes commented Oct 17, 2018 •

Copy link
Copy Markdown
Member

Description of Change

When a window is opened with window.open to navigate to a cross-site destination, the new site instance should belong to the browsing instance of the opener window in order not to break scripting relationships between windows.

fixes #8100.

Release Notes

Notes: Fixed a bug where window.opener of a window created with window.open from a sandboxed renderer was null.

@ppontes
ppontes requested a review from a team October 17, 2018 12:10
@welcome

welcome Bot commented Oct 17, 2018

Copy link
Copy Markdown

💖 Thanks for opening this pull request! 💖

We use semantic commit messages to streamline the release process. Before your pull request can be merged, you should update your pull request title to start with a semantic prefix.

Examples of commit messages with semantic prefixes:

  • fix: don't overwrite prevent_default if default wasn't prevented
  • feat: add app.isPackaged() method
  • docs: app.isDefaultProtocolClient is now available on Linux

Things that will help get your PR across the finish line:

  • Follow the JavaScript, C++, and Python coding style.
  • Run npm run lint locally to catch formatting errors earlier.
  • Document any user-facing changes you've made following the documentation styleguide.
  • Include tests when adding/changing behavior.
  • Include screenshots and animated GIFs whenever possible.

We get a lot of pull requests on this repo, so please be patient and we will get back to you as soon as we can.

@@ -196,6 +196,15 @@ class CONTENT_EXPORT ContentBrowserClient {
public:
virtual ~ContentBrowserClient() {}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Those trailing spaces matter.

@alexeykuzmin

alexeykuzmin commented Oct 17, 2018 •

Copy link
Copy Markdown
Contributor

@ppontes Can you please check why the tests fail? Those do not look like flakes.

@deepak1556

Copy link
Copy Markdown
Member

Adding some background on why its the current way for sandboxed renderers.

The actual site instance determination for the child web contents is made in content::WebContentsImpl::CreateNewWindow. The reason why its failing for cross origin is because the webcontents creation and loading happens in two different steps and the site instance is chosen incorrectly between these in electron,

even though we short circuit site instance decision to the content layer when its a sandboxed renderer, we force creating a new one when its cross origin AtomBrowserClient::<namespace>::IsSameWebSite. I think the check should be removed and delegate the decision to content layer for all origins in sandboxed mode.

/cc @zcbenz

@zcbenz

zcbenz commented Oct 18, 2018

Copy link
Copy Markdown
Contributor

even though we short circuit site instance decision to the content layer when its a sandboxed renderer, we force creating a new one when its cross origin AtomBrowserClient::<namespace>::IsSameWebSite. I think the check should be removed and delegate the decision to content layer for all origins in sandboxed mode.

Sounds good to me.

@alexeykuzmin

alexeykuzmin commented Oct 18, 2018 •

Copy link
Copy Markdown
Contributor

Only these two failed tests look related to the change:

  1. BrowserWindow module "webPreferences" option "sandbox" option can get printer list
  2. BrowserWindow module "webPreferences" option "sandbox" option should open windows in another domain with cross-scripting disabled

All others seem to be a side-effect of those ^ failures.
Also the first failing test seems to be a side-effect of the second =)
@ppontes please look at the second test ("... should open windows in another domain with cross-scripting disabled") first.

@ppontes

ppontes commented Oct 18, 2018

Copy link
Copy Markdown
Member Author

Thanks @alexeykuzmin. Checking the failing unit test.
@deepak1556, thanks for your explanation! Can you please check if I understood correctly your fix suggestion?

@deepak1556

Copy link
Copy Markdown
Member

@ppontes the fix looks good now, thanks! once the failing specs are fixed it should be good to go.

@alexeykuzmin

Copy link
Copy Markdown
Contributor

@ppontes
I rewrote that not_very_elegant failing test. Should be easier to debug/fix.

@alexeykuzmin

Copy link
Copy Markdown
Contributor

@tarruda why do we expect a window.opener to be null for a child window with a different origin?

ipcMain.once('child-loaded', function (event, openerIsNull, html) {
assert(openerIsNull)

@tarruda

tarruda commented Oct 19, 2018 •

Copy link
Copy Markdown
Contributor

@tarruda why do we expect a window.opener to be null for a child window with a different origin?

Not 100% sure, but I think it is related to the web security model which says by default pages from different origin can't share data.

TBH I don't really know. I guess that when I first wrote the code, this is the behavior I observed. If the tests are failing now then they probably should be adjusted.

@tarruda
tarruda self-requested a review October 19, 2018 10:22

@tarruda tarruda left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@alexeykuzmin

Copy link
Copy Markdown
Contributor

@ppontes Can you add a test to test precisely what is described in #8100?

@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.

Awesome, LGTM 👍

@alexeykuzmin

Copy link
Copy Markdown
Contributor

@ppontes If you're not going to make any more changes, please remove the [WIP] prefix from the PR's title.

@alexeykuzmin alexeykuzmin left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@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.

After discussion with @ppontes offline, I was notified that this solution breaks affinity in sandboxed mode, there are no specs for it at the moment. @ppontes is working on a fix and the PR should be good to merge after that.

@ppontes ppontes changed the title [WIP] fix: window.open site instance should belong to same browsing instance fix: window.open site instance should belong to same browsing instance Nov 10, 2018
@ppontes
ppontes requested review from a team November 11, 2018 11:44
@ppontes ppontes changed the title fix: window.open site instance should belong to same browsing instance [WIP] fix: window.open site instance should belong to same browsing instance Nov 11, 2018
…vigating.

When navigating to a new address, consider using Chromium's determined site instance
for the new page as it should belong to an existing browsing instance when the
navigation was triggered by window.open().

fixes 8100.
@ppontes ppontes changed the title [WIP] fix: window.open site instance should belong to same browsing instance fix: window.open site instance should belong to same browsing instance Nov 11, 2018
@ppontes

ppontes commented Nov 12, 2018

Copy link
Copy Markdown
Member Author

@deepak1556 can you please check the affinity fix and tests?
@alexeykuzmin updated release notes and removed wip. there seems to be a flake UT blocking the PR.

@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.

LGTM 👍

@alexeykuzmin alexeykuzmin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nice!

@ppontes

ppontes commented Nov 12, 2018

Copy link
Copy Markdown
Member Author

@electron/docs and @electron/notifications, can you please check this PR? Thanks!

@alexeykuzmin

alexeykuzmin commented Nov 12, 2018 •

Copy link
Copy Markdown
Contributor

@ppontes The trop bot is acting weird, can you please create a manual backport to the 4-0-x branch when this PR is merged? Just a new PR targeting that branch with a cherry-pick of a merge commit of this PR.

@alexeykuzmin
alexeykuzmin merged commit 8f35198 into electron:master Nov 12, 2018
@release-clerk

release-clerk Bot commented Nov 12, 2018

Copy link
Copy Markdown

Release Notes Persisted

Fixed a bug where window.opener of a window created with window.open from a sandboxed renderer was null.

@welcome

welcome Bot commented Nov 12, 2018

Copy link
Copy Markdown

Congrats on merging your first pull request! 🎉🎉🎉

@Gvozd

Gvozd commented Nov 12, 2018

Copy link
Copy Markdown

Is it possible to backport to 3.0.x?

@alexeykuzmin

Copy link
Copy Markdown
Contributor

@Gvozd We are going to. But I don't want to make any promises.

@ppontes
ppontes deleted the ppontes/8100-use-proper-site-instance-candidate branch November 19, 2018 10:15
alexeykuzmin pushed a commit that referenced this pull request Nov 20, 2018
@ppontes
ppontes restored the ppontes/8100-use-proper-site-instance-candidate branch November 22, 2018 10:46
bcpete pushed a commit to bcpete/electron that referenced this pull request Apr 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

In sandbox mode, window.opener doesn't work when children are from different domain

8 participants