Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: <webview> not working in scriptable popups #19198

Merged
merged 1 commit into from Jul 12, 2019

Conversation

miniak
Copy link
Contributor

@miniak miniak commented Jul 10, 2019

Description of Change

In this PR #15859 I've added a check to prevent <webview> related IPCs from being handled when webviewTag is not enabled for the given sender to increase security. It relies on getLastWebPreferences():

const isWebViewTagEnabled = function (contents) {
if (!isWebViewTagEnabledCache.has(contents)) {
const webPreferences = contents.getLastWebPreferences() || {}
isWebViewTagEnabledCache.set(contents, !!webPreferences.webviewTag)
}
return isWebViewTagEnabledCache.get(contents)
}

When a scriptable popup is created, Chromium creates the webContents and Electron migrates the webPreferences

if (options.Get("webContents", &web_contents) && !web_contents.IsEmpty()) {
// Set webPreferences from options if using an existing webContents.
// These preferences will be used when the webContent launches new
// render processes.
auto* existing_preferences =
WebContentsPreferences::From(web_contents->web_contents());
base::DictionaryValue web_preferences_dict;
if (mate::ConvertFromV8(isolate, web_preferences.GetHandle(),
&web_preferences_dict)) {
existing_preferences->Clear();
existing_preferences->Merge(web_preferences_dict);
}
} else {
// Creates the WebContents used by BrowserWindow.
web_contents = WebContents::Create(isolate, web_preferences);
}

The webPreferences are cloned to be returned by getLastWebPreferences() in the constructor of WebContentsPreferences. However Clear and Merge are called afterwards.

last_preference_ = preference_.Clone();

In case of cross-origin popup a new renderer process is created and the webPreferences are turned into command-line switches in WebContentsPreferences::AppendCommandLineSwitches(), which also clones them again (after the Merge).

// We are appending args to a webContents so let's save the current state
// of our preferences object so that during the lifetime of the WebContents
// we can fetch the options used to initally configure the WebContents
last_preference_ = preference_.Clone();

The problem is that in case of scriptable popup, the existing renderer process is reused. Therefore WebContentsPreferences::AppendCommandLineSwitches() is not called and the webPreferences are not cloned after the merge. Which means that getLastWebPreferences() returns incorrect values (with webviewTag disabled).

This PR fixes the <webview> issue by making sure that getLastWebPreferences() returns correct values by cloning the webPreferences after the merge.

Checklist

Release Notes

Notes: Fixed <webview> not working in scriptable popups when nativeWindowOpen is enabled.

@miniak miniak added the wip ⚒ label Jul 10, 2019
@miniak miniak self-assigned this Jul 10, 2019
@electron-cation electron-cation bot added the new-pr 🌱 PR opened in the last 24 hours label Jul 10, 2019
@miniak miniak requested a review from nornagon July 10, 2019 16:40
@miniak miniak removed the wip ⚒ label Jul 10, 2019
@miniak miniak requested a review from ckerr July 10, 2019 16:40
@miniak miniak marked this pull request as ready for review July 10, 2019 16:49
@miniak miniak requested a review from deepak1556 July 10, 2019 16:51
@miniak miniak force-pushed the miniak/fix-webview-in-scriptable-popup branch from ea5ed3c to f2b5cc9 Compare July 11, 2019 12:29
@miniak miniak force-pushed the miniak/fix-webview-in-scriptable-popup branch from f2b5cc9 to 8eea944 Compare July 11, 2019 12:34
@trop
Copy link
Contributor

trop bot commented Jul 11, 2019

A maintainer has manually backported this PR to "5-0-x", please check out #19206

@electron-cation electron-cation bot removed the new-pr 🌱 PR opened in the last 24 hours label Jul 11, 2019
Copy link
Member

@deepak1556 deepak1556 left a comment

Choose a reason for hiding this comment

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

Scary bug, nice find!

@codebytere codebytere merged commit 3529489 into master Jul 12, 2019
@release-clerk
Copy link

release-clerk bot commented Jul 12, 2019

Release Notes Persisted

Fixed <webview> not working in scriptable popups when nativeWindowOpen is enabled.

@codebytere codebytere deleted the miniak/fix-webview-in-scriptable-popup branch July 12, 2019 01:56
@trop
Copy link
Contributor

trop bot commented Jul 12, 2019

I have automatically backported this PR to "6-0-x", please check out #19218

@sofianguy sofianguy added this to Fixed in 5.0.7 in 5.0.x Jul 16, 2019
@sofianguy sofianguy added this to Fixed in 6.0.0-beta.14 in 6.1.x Jul 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
5.0.x
Fixed in 5.0.7
6.1.x
Fixed in 6.0.0-beta.14
Development

Successfully merging this pull request may close these issues.

None yet

4 participants