Skip to content

fix: window.open not overriding parent's webPreferences#32057

Merged
zcbenz merged 2 commits intomainfrom
child-window-prefs
Dec 6, 2021
Merged

fix: window.open not overriding parent's webPreferences#32057
zcbenz merged 2 commits intomainfrom
child-window-prefs

Conversation

@zcbenz
Copy link
Copy Markdown
Contributor

@zcbenz zcbenz commented Nov 29, 2021

Description of Change

This PR fixes an issue that, child window opened with window.open can not override its web preferences inherited from the parent window, close #31949, close #31959.

Please check the comments in electron_render_frame_observer.cc for the background of the problem.

Fix PR also fixes an issue introduced by #31031 that, the feature string in window.open was treated as windowOpenOverriddenOptions which would override the securityWebPreferences. This problem was hidden by the above bug 31949 because the web preferences could not be overridden, but with the bug fixed 31031 would then allow features string to override security options.

There are also changes to tests as some of them rely on the bug to work.

Release Notes

Notes: Fix window.open not overriding parent's webPreferences.

@zcbenz zcbenz added security 🔒 semver/patch backwards-compatible bug fixes target/13-x-y labels Nov 29, 2021
@zcbenz zcbenz requested a review from a team as a code owner November 29, 2021 23:51
@electron-cation electron-cation bot added the new-pr 🌱 PR opened recently label Nov 29, 2021
// Do a delayed Node.js initialization for child window.
// Check DidInstallConditionalFeatures below for the background.
auto* web_frame = render_frame_->GetWebFrame();
if (has_delayed_node_initialization_ && web_frame->Opener() &&
Copy link
Copy Markdown
Member

@deepak1556 deepak1556 Nov 30, 2021

Choose a reason for hiding this comment

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

When browser side navigation is triggered, won't there be another call to ElectronRenderFrameObserver::DidInstallConditionalFeatures from https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/bindings/core/v8/local_window_proxy.cc;l=216-220 which will then initialize based on the correct preferences, is this second redirection via ElectronRenderFrameObserver::DidClearWindowObject needed ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

For child window opened by window.open, the DidInstallConditionalFeatures is only called once, and DidClearWindowObject is instead called multiple times.

It seems that Chromium immediately creates an empty DOM window when window.open is called, and then does an in-place initialization later when the actual navigation happens, it does not create a new DOM window for the navigation.

I think this behavior is kind of reasonable, since the window object returned by window.open is immediately accessible to users even before the actual navigation starts.

@electron-cation electron-cation bot removed the new-pr 🌱 PR opened recently label Nov 30, 2021
@zcbenz zcbenz force-pushed the child-window-prefs branch from bc16577 to 7ed393a Compare December 1, 2021 08:41
@zcbenz
Copy link
Copy Markdown
Contributor Author

zcbenz commented Dec 1, 2021

I have updated the PR with another approach that does not need to patch Chromium.

I also found a Chromium issue that has some information on how window.open works.
https://bugs.chromium.org/p/chromium/issues/detail?id=1215096

@zcbenz
Copy link
Copy Markdown
Contributor Author

zcbenz commented Dec 1, 2021

I'm also removing the "nativeWindowOpen: false" option from renderer tests, which was required because some tests fail for the native window.open code path.

@zcbenz zcbenz force-pushed the child-window-prefs branch from 5d1439c to 5220d0b Compare December 2, 2021 01:09
@miniak miniak mentioned this pull request Dec 2, 2021
5 tasks
@zcbenz zcbenz merged commit 35ac7fb into main Dec 6, 2021
@zcbenz zcbenz deleted the child-window-prefs branch December 6, 2021 03:54
@release-clerk
Copy link
Copy Markdown

release-clerk bot commented Dec 6, 2021

Release Notes Persisted

Fix window.open not overriding parent's webPreferences.

@trop
Copy link
Copy Markdown
Contributor

trop bot commented Dec 6, 2021

I was unable to backport this PR to "13-x-y" cleanly;
you will need to perform this backport manually.

@trop
Copy link
Copy Markdown
Contributor

trop bot commented Dec 6, 2021

I was unable to backport this PR to "14-x-y" cleanly;
you will need to perform this backport manually.

@trop trop bot removed the target/13-x-y label Dec 6, 2021
@trop
Copy link
Copy Markdown
Contributor

trop bot commented Dec 6, 2021

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

@trop
Copy link
Copy Markdown
Contributor

trop bot commented Dec 6, 2021

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

@trop
Copy link
Copy Markdown
Contributor

trop bot commented Dec 6, 2021

@zcbenz has manually backported this PR to "15-x-y", please check out #32109

t57ser pushed a commit to t57ser/electron that referenced this pull request Jan 25, 2022
* fix: window.open not overriding parent's webPreferences

* test: remove "nativeWindowOpen: false" from renderer tests
zcbenz added a commit that referenced this pull request Feb 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

security 🔒 semver/patch backwards-compatible bug fixes

Projects

None yet

4 participants