8000 fix: do not create node environment in child window if node integration is not enabled (4-0-x) by zcbenz · Pull Request #15190 · electron/electron · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix: do not create node environment in child window if node integration is not enabled (4-0-x) #15190

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 1 commit into from
Oct 16, 2018
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
2 changes: 2 additions & 0 deletions atom/browser/web_contents_preferences.cc
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,8 @@ void WebContentsPreferences::OverrideWebkitPrefs(
std::string encoding;
if (GetAsString(&preference_, "defaultEncoding", &encoding))
prefs->default_encoding = encoding;

prefs->node_integration = IsEnabled(options::kNodeIntegration);
}

} // namespace atom
10 changes: 10 additions & 0 deletions atom/renderer/atom_renderer_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "atom/renderer/atom_render_frame_observer.h"
#include "atom/renderer/web_worker_observer.h"
#include "base/command_line.h"
#include "content/public/common/web_preferences.h"
#include "content/public/renderer/render_frame.h"
#include "native_mate/dictionary.h"
#include "third_party/blink/public/web/web_document.h"
Expand Down Expand Up @@ -86,6 +87,15 @@ void AtomRendererClient::DidCreateScriptContext(
if (!render_frame->IsMainFrame() && !IsDevToolsExtension(render_frame))
return;

// Don't allow node integration if this is a child window and it does not have
// node integration enabled. Otherwise we would have memory leak in the child
// window since we don't clean up node environments.
//
// TODO(zcbenz): We shouldn't allow node integration even for the top frame.
if (!render_frame->GetWebkitPreferences().node_integration &&
render_frame->GetWebFrame()->Opener())
return;

injected_frames_.insert(render_frame);

// Prepare the node bindings.
Expand Down
9 changes: 9 additions & 0 deletions patches/common/chromium/.patches.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -491,3 +491,12 @@ patches:
dylib currently fails to resolve Squirrel.framework on OSX, we need to fix
this but it is not a blocker for releasing Electron. This patch removes
the hard fail on dylib resolve failure from dump_syms
-
author: zcbenz <zcbenz@gmail.com>
file: web_preferences.patch
description: |
Add a node_integration field to WebPreferences so we can determine whether
a frame has node integration in renderer process.

This is required by the nativeWindowOpen option, which put multiple main
frames in one renderer process.
26 changes: 26 additions & 0 deletions patches/common/chromium/web_preferences.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
diff --git a/content/public/common/common_param_traits_macros.h b/content/public/common/common_param_traits_macros.h
index 57f03dc..7c4409e 100644
--- a/content/public/common/common_param_traits_macros.h
+++ b/content/public/common/common_param_traits_macros.h
@@ -198,6 +198,7 @@ IPC_STRUCT_TRAITS_BEGIN(content::WebPreferences)
IPC_STRUCT_TRAITS_MEMBER(animation_policy)
IPC_STRUCT_TRAITS_MEMBER(user_gesture_required_for_presentation)
IPC_STRUCT_TRAITS_MEMBER(text_track_margin_percentage)
+ IPC_STRUCT_TRAITS_MEMBER(node_integration)
IPC_STRUCT_TRAITS_MEMBER(save_previous_document_resources)
IPC_STRUCT_TRAITS_MEMBER(text_autosizing_enabled)
IPC_STRUCT_TRAITS_MEMBER(double_tap_to_zoom_enabled)
diff --git a/content/public/common/web_preferences.h b/content/public/common/web_preferences.h
index 78cbf5f..b33ac28 100644
--- a/content/public/common/web_preferences.h
+++ b/content/public/common/web_preferences.h
@@ -222,6 +222,9 @@ struct CONTENT_EXPORT WebPreferences {
// Cues will not be placed in this margin area.
float text_track_margin_percentage;

+ // Electron: Whether the frame has node integration.
+ bool node_integration = false;
+
bool immersive_mode_enabled;

bool text_autosizing_enabled;
0