8000 chore: disable the remote module in devtools / chrome extension background scripts by miniak · Pull Request #16866 · electron/electron · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

chore: disable the remote module in devtools / chrome extension background scripts #16866

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

Merged
merged 2 commits into from
Feb 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions atom/browser/api/atom_api_web_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1959,6 +1959,9 @@ v8::Local<v8::Value> WebContents::GetLastWebPreferences(
}

bool WebContents::IsRemoteModuleEnabled() const {
if (web_contents()->GetVisibleURL().SchemeIs("chrome-devtools")) {
return false;
}
if (auto* web_preferences = WebContentsPreferences::From(web_contents())) {
return web_preferences->IsRemoteModuleEnabled();
}
Expand Down
1 change: 1 addition & 0 deletions atom/browser/atom_browser_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,7 @@ void AtomBrowserClient::AppendExtraCommandLineSwitches(
if (web_contents->GetVisibleURL().SchemeIs("chrome-devtools")) {
command_line->AppendSwitch(service_manager::switches::kNoSandbox);
command_line->AppendSwitch(::switches::kNoZygote);
command_line->AppendSwitch(switches::kDisableRemoteModule);
}
auto* web_preferences = WebContentsPreferences::From(web_contents);
if (web_preferences)
Expand Down
1 change: 1 addition & 0 deletions atom/browser/web_contents_preferences.cc
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ WebContentsPreferences::WebContentsPreferences(
SetDefaultBoolIfUndefined(options::kWebviewTag, false);
SetDefaultBoolIfUndefined(options::kSandbox, false);
SetDefaultBoolIfUndefined(options::kNativeWindowOpen, false);
SetDefaultBoolIfUndefined(options::kEnableRemoteModule, true);
SetDefaultBoolIfUndefined(options::kContextIsolation, false);
SetDefaultBoolIfUndefined("javascript", true);
SetDefaultBoolIfUndefined("images", true);
Expand Down
15 changes: 1 addition & 14 deletions lib/browser/api/web-contents.js
10000
Original file line number Diff line number Diff line change
Expand Up @@ -365,17 +365,6 @@ const addReturnValueToEvent = (event) => {
})
}

const safeProtocols = new Set([
'chrome-devtools:',
'chrome-extension:'
])

const isWebContentsTrusted = function (contents) {
const pageURL = contents._getURL()
const { protocol } = url.parse(pageURL)
return safeProtocols.has(protocol)
}

// Add JavaScript wrappers for WebContents class.
WebContents.prototype._init = function () {
// The navigation controller.
Expand Down Expand Up @@ -435,9 +424,7 @@ WebContents.prototype._init = function () {

for (const eventName of forwardedEvents) {
this.on(eventName, (event, ...args) => {
if (!isWebContentsTrusted(event.sender)) {
app.emit(eventName, event, this, ...args)
}
app.emit(eventName, event, this, ...args)
})
}

Expand Down
3 changes: 2 additions & 1 deletion lib/browser/chrome-extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ const startBackgroundPages = function (manifest) {
const contents = webContents.create({
partition: 'persist:__chrome_extension',
isBackgroundPage: true,
commandLineSwitches: ['--background-page']
commandLineSwitches: ['--background-page'],
enableRemoteModule: false
})
backgroundPages[manifest.extensionId] = { html: html, webContents: contents, name: name }
contents.loadURL(url.format({
Expand Down
14 changes: 12 additions & 2 deletions lib/browser/rpc-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,10 +264,20 @@ const callFunction = function (event, contextId, func, caller, args) {
}
}

const isRemoteModuleEnabledCache = new WeakMap()

const isRemoteModuleEnabled = function (con 8000 tents) {
if (!isRemoteModuleEnabledCache.has(contents)) {
isRemoteModuleEnabledCache.set(contents, contents._isRemoteModuleEnabled())
}

return isRemoteModuleEnabledCache.get(contents)
}

const handleRemoteCommand = function (channel, handler) {
ipcMainInternal.on(channel, (event, contextId, ...args) => {
let returnValue
if (!event.sender._isRemoteModuleEnabled()) {
if (!isRemoteModuleEnabled(event.sender)) {
event.returnValue = null
return
}
Expand Down Expand Up @@ -506,7 +516,7 @@ ipcMainInternal.on('ELECTRON_BROWSER_SANDBOX_LOAD', function (event) {

event.returnValue = {
preloadScripts: preloadPaths.map(path => getPreloadScript(path)),
isRemoteModuleEnabled: event.sender._isRemoteModuleEnabled(),
isRemoteModuleEnabled: isRemoteModuleEnabled(event.sender),
isWebViewTagEnabled: guestViewManager.isWebViewTagEnabled(event.sender),
process: {
arch: process.arch,
Expand Down
0