Skip to content

Commit

Permalink
chore: warn when nodeIntegration's default is relied on (#16004)
Browse files Browse the repository at this point in the history
  • Loading branch information
nornagon authored and Cheng Zhao committed Dec 11, 2018
1 parent e8d4a07 commit 913a433
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 0 deletions.
3 changes: 3 additions & 0 deletions atom/browser/web_contents_preferences.cc
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ WebContentsPreferences::WebContentsPreferences(

instances_.push_back(this);

preference_.SetKey(options::kNodeIntegrationWasExplicitlyEnabled,
base::Value(IsEnabled(options::kNodeIntegration)));

// Set WebPreferences defaults onto the JS object
SetDefaultBoolIfUndefined(options::kPlugins, false);
SetDefaultBoolIfUndefined(options::kExperimentalFeatures, false);
Expand Down
7 changes: 7 additions & 0 deletions atom/common/options_switches.cc
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,13 @@ const char kPreloadURL[] = "preloadURL";
// Enable the node integration.
const char kNodeIntegration[] = "nodeIntegration";

// Whether node integration was explicitly enabled.
// This is to support the change from default-enabled to default-disabled in
// Electron 5 (with a warning message in 4). This option and its usages
// can be removed in Electron 5.
const char kNodeIntegrationWasExplicitlyEnabled[] =
"nodeIntegrationWasExplicitlyEnabled";

// Enable the remote module
const char kEnableRemoteModule[] = "enableRemoteModule";

Expand Down
1 change: 1 addition & 0 deletions atom/common/options_switches.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ extern const char kZoomFactor[];
extern const char kPreloadScript[];
extern const char kPreloadURL[];
extern const char kNodeIntegration[];
extern const char kNodeIntegrationWasExplicitlyEnabled[];
extern const char kEnableRemoteModule[];
extern const char kContextIsolation[];
extern const char kGuestInstanceID[];
Expand Down
11 changes: 11 additions & 0 deletions lib/renderer/security-warnings.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,16 @@ const warnAboutAllowedPopups = function () {
}
}

const warnAboutNodeIntegrationDefault = function (webPreferences) {
if (webPreferences.nodeIntegration && !webPreferences.nodeIntegrationWasExplicitlyEnabled) {
const warning = `This window has node integration enabled by default. In ` +
`Electron 5.0.0, node integration will be disabled by default. To prepare ` +
`for this change, set {nodeIntegration: true} in the webPreferences for ` +
`this window.`
console.warn('%cElectron Deprecation Warning (nodeIntegration default change)', 'font-weight: bold;', warning)
}
}

// Currently missing since we can't easily programmatically check for it:
// #12WebViews: Verify the options and params of all `<webview>` tags

Expand All @@ -261,6 +271,7 @@ const logSecurityWarnings = function (webPreferences, nodeIntegration) {
warnAboutEnableBlinkFeatures(webPreferences)
warnAboutInsecureCSP()
warnAboutAllowedPopups()
warnAboutNodeIntegrationDefault(webPreferences)
}

const getWebPreferences = function () {
Expand Down

0 comments on commit 913a433

Please sign in to comment.