Skip to content

JavaScript: Add query for Node.js integration in Electron framework #167

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 10 commits into from
Sep 15, 2018

Conversation

bnxi
Copy link
Contributor

@bnxi bnxi commented Sep 6, 2018

This query finds instances of Node.js integration being enabled in WebPreferences object that could result in remote code execution when rendering untrusted web content.

@bnxi bnxi requested a review from a team as a code owner September 6, 2018 19:02
@ghost
Copy link

ghost commented Sep 6, 2018

CLA assistant check
All committers have signed the CLA.

@bnxi
Copy link
Contributor Author

bnxi commented Sep 6, 2018

The Jenkins links are not accessible from internet.

@jbj jbj added the JS label Sep 7, 2018
@jbj
Copy link
Contributor

jbj commented Sep 7, 2018

Sorry, we haven't found a good way to enable public access to our Jenkins output.

The QHelp-preview check is failing with the following error:

20:06:46 [2018-09-06 20:06:46] Validating qhelp file ql/javascript/ql/src/Electron/EnablingNodeIntegration.qhelp...
20:06:47 [2018-09-06 20:06:46] [ERROR] ql/javascript/ql/src/Electron/EnablingNodeIntegration.qhelp:37:72: element "webview" not allowed anywhere; expected the element end-tag, text or element "a", "b", "code", "em", "i", "img", "strong", "sub", "sup" or "tt"
20:06:47 [2018-09-06 20:06:46] [ERROR] ql/javascript/ql/src/Electron/EnablingNodeIntegration.qhelp:38:7: The element type "webview" must be terminated by the matching end-tag "</webview>".

It probably needs to be written &lt;webview&gt;, and maybe also add <code> around it for nicer formatting.

The Language-Tests/JavaScript check is failing on EnablingNodeIntegration.qlref with this diff:

22:35:01 --- expected
22:35:01 +++ actual
22:35:01 @@ -1,5 +1,5 @@
22:35:01 -| EnablingNodeIntegration.js:5:28:11:9 | {\\r\\n     ...       } | nodeIntegration property may have been enabled on this object that could result in RCE |
22:35:01 -| EnablingNodeIntegration.js:5:28:11:9 | {\\r\\n     ...       } | nodeIntegrationInWorker property may have been enabled on this object that could result in RCE |
22:35:01 -| EnablingNodeIntegration.js:15:22:20:9 | {\\r\\n     ...       } | nodeIntegration is enabled by default in WebPreferences object that could result in RCE |
22:35:01 -| EnablingNodeIntegration.js:23:13:27:9 | {\\r\\n     ...       } | nodeIntegration is enabled by default in WebPreferences object that could result in RCE |
22:35:01 +| EnablingNodeIntegration.js:5:28:11:9 | {\\n      ...       } | nodeIntegration property may have been enabled on this object that could result in RCE |
22:35:01 +| EnablingNodeIntegration.js:5:28:11:9 | {\\n      ...       } | nodeIntegrationInWorker property may have been enabled on this object that could result in RCE |
22:35:01 +| EnablingNodeIntegration.js:15:22:20:9 | {\\n      ...       } | nodeIntegration is enabled by default in WebPreferences object that could result in RCE |
22:35:01 +| EnablingNodeIntegration.js:23:13:27:9 | {\\n      ...       } | nodeIntegration is enabled by default in WebPreferences object that could result in RCE |
22:35:01  | EnablingNodeIntegration.js:49:71:49:93 | {nodeIn ... : true} | nodeIntegration property may have been enabled on this object that could result in RCE |

It looks like a Windows/Unix line endings problem. Try to convert all files into Unix line endings. Alternatively, hand-edit the EnablingNodeIntegration.expected file to remove the \\r.


<example>
<p>
The following example shows insecure and secure uses of </code>webview</code> tag:
Copy link
Contributor

@felicitymay felicitymay Sep 7, 2018

Choose a reason for hiding this comment

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

Thanks for the changes. It looks as if the Qhelp preview is just complaining about the typo in this line now.

</code>webview</code>

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks, will correct it after the code passes Language-Tests/JavaScript test

@jbj
Copy link
Contributor

jbj commented Sep 8, 2018

The diff in the Language-Tests/JavaScript error is now this:

01:46:41  --- expected
01:46:41  +++ actual
01:46:41  @@ -1,5 +1,5 @@
01:46:41  -| EnablingNodeIntegration.js:5:28:11:9 | {\\n     ...       } | nodeIntegration property may have been enabled on this object that could result in RCE |
01:46:41  -| EnablingNodeIntegration.js:5:28:11:9 | {\\n     ...       } | nodeIntegrationInWorker property may have been enabled on this object that could result in RCE |
01:46:41  -| EnablingNodeIntegration.js:15:22:20:9 | {\\n     ...       } | nodeIntegration is enabled by default in WebPreferences object that could result in RCE |
01:46:41  -| EnablingNodeIntegration.js:23:13:27:9 | {\\n     ...       } | nodeIntegration is enabled by default in WebPreferences object that could result in RCE |
01:46:41  +| EnablingNodeIntegration.js:5:28:11:9 | {\\n      ...       } | nodeIntegration property may have been enabled on this object that could result in RCE |
01:46:41  +| EnablingNodeIntegration.js:5:28:11:9 | {\\n      ...       } | nodeIntegrationInWorker property may have been enabled on this object that could result in RCE |
01:46:41  +| EnablingNodeIntegration.js:15:22:20:9 | {\\n      ...       } | nodeIntegration is enabled by default in WebPreferences object that could result in RCE |
01:46:41  +| EnablingNodeIntegration.js:23:13:27:9 | {\\n      ...       } | nodeIntegration is enabled by default in WebPreferences object that could result in RCE |
01:46:41   | EnablingNodeIntegration.js:49:71:49:93 | {nodeIn ... : true} | nodeIntegration property may have been enabled on this object that could result in RCE |

It looks like the expected file has one too few spaces before the ... in the first four lines. This error is hopefully reproducible for you locally with odasa qltest.

@ghost ghost self-assigned this Sep 11, 2018
Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

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

@bnxi Thank you for the submission.

I have some stylistic changes that I think you should incorporate, see https://github.com/esben-semmle/ql/commits/NodeIntegration.

Note that I have removed the @precision attribute, since I do not think we want this query by default on LGTM.com yet. You can still enable the query manually in lgtm.yml or by using a custom query pack.

I note that the examples/WebViewNodeIntegration.html file contains a BAD example that is not flagged by the analysis.
We usually only have examples of problems that the analysis can flag. Did you mean to include support for that example as well?

@bnxi
Copy link
Contributor Author

bnxi commented Sep 11, 2018

@esben-semmle thanks for the suggestions and improvements. I had included webview example file as an extra piece of information and it was not intended to be detected by this query. I have removed the example file and reference to it from qlhelp file as well.

@bnxi
Copy link
Contributor Author

bnxi commented Sep 12, 2018

@esben-semmle seems to be EOL issue again, please feel free to abandon this PR and add this query in the next release if you find it useful. I'd like to propose the following queries as well:

  1. Warning to enable context isolation when 'preload' property was present in WebPrefrences: https://electronjs.org/docs/tutorial/security#3-enable-context-isolation-for-remote-content
  2. Do not use enableBlinkFeatures: https://electronjs.org/docs/tutorial/security#10-do-not-use-enableblinkfeatures

Thanks

@ghost
Copy link

ghost commented Sep 13, 2018

@bnxi Thank you for the changes.

One minor nit: can you revert ecd08d4, please? The leading dots are not necessary, and the commit message does not match the change.

seems to be EOL issue again

Not this time. The failure was caused by a temporary internal issue.

please feel free to abandon this PR and add this query in the next release

No need to abandon, you are merging against master, so the feature will land in the next release (1.19) automatically.
The feature freeze for 1.18 was on August 31, when the master branch was forked to rc/1.18.
If you want the feature in 1.18, I need to merge it as a hotfix against rc/1.18.

I'd like to propose the following queries as well: ...

Noted, we will aim for inclusion in 1.19.

@semmle-qlci semmle-qlci merged commit 782e91b into github:master Sep 15, 2018
@ghost
Copy link

ghost commented Sep 15, 2018

Thank you @bnxi , your contribution has been merged.
We will experiment with the query and the two suggested queries, and hopefully make them all a part of the standard LGTM.com query suite soon.

@bnxi bnxi deleted the NodeIntegration branch September 17, 2018 16:52
aibaars added a commit that referenced this pull request Oct 14, 2021
Implement FLines metrics queries
smowton pushed a commit to smowton/codeql that referenced this pull request Jan 17, 2022
…ecl-stmt

Remove and replace @anonymousclassdeclstmt with @localtypedeclstmt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants