Skip to content

Commit 2cedc81

Browse files
author
Esben Sparre Andreasen
committed
JS: polish js/enabling-electron-renderer-node-integration meta info
1 parent 89f2dbf commit 2cedc81

File tree

6 files changed

+49
-43
lines changed

6 files changed

+49
-43
lines changed

change-notes/1.19/analysis-javascript.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
| **Query** | **Tags** | **Purpose** |
1414
|-----------------------------------------------|------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
15+
| Enabling Node.js integration for Electron web content renderers (`js/enabling-electron-renderer-node-integration`) | security, frameworks/electron, external/cwe/cwe-094 | Highlights Electron web content renderer preferences with Node.js integration enabled, indicating a violation of [CWE-94](https://cwe.mitre.org/data/definitions/94.html). Results are not shown on LGTM by default. |
1516
| Stored cross-site scripting (`js/stored-xss`) | security, external/cwe/cwe-079, external/cwe/cwe-116 | Highlights uncontrolled stored values flowing into HTML content, indicating a violation of [CWE-079](https://cwe.mitre.org/data/definitions/79.html). Results shown on LGTM by default. |
1617

1718
## Changes to existing queries

javascript/config/suites/javascript/security

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
+ semmlecode-javascript-queries/DOM/TargetBlank.ql: /Security/CWE/CWE-200
2+
+ semmlecode-javascript-queries/Electron/EnablingNodeIntegration.ql: /Security/CWE/CWE-094
23
+ semmlecode-javascript-queries/Security/CWE-022/TaintedPath.ql: /Security/CWE/CWE-022
34
+ semmlecode-javascript-queries/Security/CWE-078/CommandInjection.ql: /Security/CWE/CWE-078
45
+ semmlecode-javascript-queries/Security/CWE-079/ReflectedXss.ql: /Security/CWE/CWE-079

javascript/ql/src/Electron/EnablingNodeIntegration.qhelp

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,39 +5,48 @@
55

66
<overview>
77
<p>
8-
Enabling Node.js integration in web content renderers (<code>BrowserWindow</code>, <code>BrowserView</code> and <code>webview</code>) could result in
9-
remote native code execution attacks when rendering malicious JavaScript code from untrusted remote web site or
10-
code that is injected via a cross site scripting vulnerability into a trusted remote web site. Note that
11-
the <code>nodeIntegration</code> property is enabled by default in Electron and needs to be set to <code>false</code> explicitly.
12-
</p>
8+
9+
Enabling Node.js integration in Electron web content renderers
10+
(<code>BrowserWindow</code>, <code>BrowserView</code> and
11+
<code>webview</code>) can result in remote native code execution
12+
attacks.
13+
14+
The attack is realized when the renderer uses content from an
15+
untrusted remote web site or a trusted site with a cross site
16+
scripting vulnerability.
17+
18+
</p>
1319
</overview>
1420

1521
<recommendation>
1622
<p>
17-
Node.js integration should be disabled when loading remote web sites. If not possible, always set nodeIntegration property
18-
to 'false' before loading remote web sites and only enable it for whitelisted sites.
19-
</p>
20-
</recommendation>
21-
22-
<example>
23-
<p>
24-
The following example shows insecure use of <code>BrowserWindow</code> with regards to <code>nodeIntegration</code>
25-
property:
23+
24+
Node.js integration should be disabled when loading remote web
25+
sites. Always set <code>nodeIntegration</code> preference
26+
to <code>false</code> before loading remote web sites, and only enable
27+
it for whitelisted sites.
28+
2629
</p>
27-
<sample src="examples/DefaultNodeIntegration.js"/>
2830

2931
<p>
30-
This is problematic, because default value of <code>nodeIntegration</code> is 'true'.
32+
33+
Note that the <code>nodeIntegration</code> property is enabled
34+
by default in Electron and needs to be set to <code>false</code>
35+
explicitly.
36+
3137
</p>
32-
33-
</example>
38+
</recommendation>
3439

35-
3640
<example>
41+
3742
<p>
38-
The following example shows insecure and secure uses of <code>BrowserWindow</code> and <code>BrowserView</code> when
39-
loading untrusted web sites:
43+
44+
The following examples shows insecure and secure uses of
45+
<code>BrowserWindow</code> and <code>BrowserView</code> when loading
46+
remote web sites:
47+
4048
</p>
49+
4150
<sample src="examples/EnablingNodeIntegration.js"/>
4251

4352
</example>

javascript/ql/src/Electron/EnablingNodeIntegration.ql

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
/**
2-
* @name Enabling `nodeIntegration` or `nodeIntegrationInWorker` for Electron web content
2+
* @name Enabling Node.js integration for Electron web content renderers
33
* @description Enabling `nodeIntegration` or `nodeIntegrationInWorker` can expose the application to remote code execution.
44
* @kind problem
55
* @problem.severity warning
6+
* @precision low
67
* @id js/enabling-electron-renderer-node-integration
78
* @tags security
89
* frameworks/electron
10+
* external/cwe/cwe-094
911
*/
1012

1113
import javascript

javascript/ql/src/Electron/examples/DefaultNodeIntegration.js

Lines changed: 0 additions & 2 deletions
This file was deleted.
Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,21 @@
1-
//BAD
2-
win_1 = new BrowserWindow({width: 800, height: 600, webPreferences: {nodeIntegration: true}});
3-
win_1.loadURL("https://untrusted-site.com");
1+
//BAD: `nodeIntegration` enabled by default
2+
var win_1 = new BrowserWindow();
3+
win_1.loadURL(remote_site);
44

5-
//GOOD
6-
win_2 = new BrowserWindow({width: 800, height: 600, webPreferences: {nodeIntegration: false}});
7-
win_2.loadURL("https://untrusted-site.com");
5+
//BAD: `nodeIntegration` enabled
6+
var win_2 = new BrowserWindow({webPreferences: {nodeIntegration: true}});
7+
win_2.loadURL(remote_site);
88

9-
//BAD
10-
win_3 = new BrowserWindow({
11-
webPreferences: {
12-
nodeIntegrationInWorker: true
13-
}
14-
});
9+
//GOOD: `nodeIntegration` disabled
10+
let win_3 = new BrowserWindow({webPreferences: {nodeIntegration: false}});
11+
win_3.loadURL(remote_site);
1512

16-
//BAD BrowserView
17-
win_4 = new BrowserWindow({width: 800, height: 600, webPreferences: {nodeIntegration: false}})
18-
view = new BrowserView({
13+
//BAD: `nodeIntegration` enabled in the view
14+
var win_4 = new BrowserWindow({webPreferences: {nodeIntegration: false}})
15+
var view_4 = new BrowserView({
1916
webPreferences: {
2017
nodeIntegration: true
2118
}
2219
});
23-
win.setBrowserView(view);
24-
view.setBounds({ x: 0, y: 0, width: 300, height: 300 });
25-
view.webContents.loadURL('https://untrusted-site.com');
26-
20+
win_4.setBrowserView(view_4);
21+
view_4.webContents.loadURL(remote_site);

0 commit comments

Comments
 (0)