Skip to content

JS: Add ElectronShellOpenExternalSink class for Electron framework security #4546

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 3 commits into from
Dec 3, 2020
Merged

JS: Add ElectronShellOpenExternalSink class for Electron framework security #4546

merged 3 commits into from
Dec 3, 2020

Conversation

toufik-airane
Copy link
Contributor

@toufik-airane toufik-airane commented Oct 23, 2020

Add ElectronShellOpenExternalSink class to detect untrusted input interpreted by openExternal function call from electron module in Electron framework for Node.js.

Based on the Electron Security checklist:
https://www.electronjs.org/docs/tutorial/security#14-do-not-use-openexternal-with-untrusted-content

Add ElectronShellOpenExternalSink class to detect untrusted input
interpreted by `openExternal` function call in `electron` module.

Based on the #14 Electron Security checklist:
https://www.electronjs.org/docs/tutorial/security#14-do-not-use-openexternal-with-untrusted-content
@toufik-airane toufik-airane requested a review from a team as a code owner October 23, 2020 13:44
@github-actions github-actions bot added the JS label Oct 23, 2020
@toufik-airane
Copy link
Contributor Author

Here is an example to test the query.

  1. create a file named InsecureOpenExternal.js
const { shell } = require('electron');
const args = process.argv.slice(2)
const url = args[0]

//BAD: `url` rely on untrusted input
shell.openExternal(url)
  1. run the next command
npm i -g electron
electron InsecureOpenExternal.js https://google.co

@asgerf asgerf self-assigned this Oct 23, 2020
@asgerf
Copy link
Contributor

asgerf commented Oct 23, 2020

Hi @toufik-airane 👋

Thanks for the contribution! I was a bit perplexed when you linked to PR #14, which also added some Electron support, but I'm guessing that was a coincidence.

I think it would be better suited for the ClientSideUrlRedirect query, because the attacker must be able to control the URL scheme.

As it stands we'll get FPs from code like:

shell.openExternal('https://google.com?q=' + tainted_value)

This is similar to code execution via the javascript: protocol. We understand code injection is more severe than a mere redirect, but due to the importance of controlling the prefix of the input string, we use the same query to flag both cases.

Move the class ElectronShellOpenExternalSink to
ClientSideUrlRedirect.qll. It's been to be a more appropriate location.
@toufik-airane
Copy link
Contributor Author

toufik-airane commented Oct 23, 2020

Dear @asgerf,

My bad, the link to PR #14 was a mistake! 😱
I've updated the class location to ClientSideUrlRedirect. 👍

However, I'm not sure that will succeed to detect the issue. Indeed, when I scan my example with the javascript/ql/src/Security/CWE-601/ClientSideUrlRedirect.ql it doesn't trigger.
I feel that I'm missing something to make it works.

@asgerf
Copy link
Contributor

asgerf commented Oct 23, 2020

Thanks! I'll help add some tests on Monday. Most of the JavaScript queries don't consider command-line arguments to be a source of untrusted input, so that's probably why your example wasn't flagged out of the box.

@asgerf
Copy link
Contributor

asgerf commented Oct 28, 2020

I've opened a PR against your fork with a test case.

Copy link
Contributor

@asgerf asgerf left a comment

Choose a reason for hiding this comment

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

Well, better to merge the PR like this than leave it hanging indefinitely. I'll add the test in another PR.

Thanks for the contribution @toufik-airane!

@asgerf asgerf merged commit 254072d into github:main Dec 3, 2020
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.

2 participants