Skip to content

JS: js/shell-command-injection-from-environment#2092

Merged
semmle-qlci merged 2 commits intomasterfrom
unknown repository
Oct 22, 2019
Merged

JS: js/shell-command-injection-from-environment#2092
semmle-qlci merged 2 commits intomasterfrom
unknown repository

Conversation

@ghost
Copy link

@ghost ghost commented Oct 7, 2019

Adds a query for command line injections caused by the inclusion of unsanitized values from the execution environment, specifically file and directory names. Depending on the threat model, dynamically obtained path values should be regarded as being potentially malicious, in practice a TP from this query probably just means that a command line execution will fail when the user has spaces in his paths.

Misc. build/test scripts are particularly prone to TPs due to their missing handling of spaces in absolute paths, other results are practically safe as they quote the file names.

Additional sources of absolute paths and environment values that should be sanitized are welcome.

Results are plenty, but none seem worth a vulnerability report, the best result is exec('rm -rf ' + __dirname + '/screenshots', ..., which may remove too many files if there are spaces in the path of the currently executing file (inspires the qhelp).

Standalone performance is unsurprisingly comparable to js/command-line-injection. I have started a slightly more precise performance evaluation Performance when evaluated with the two other command-injection queries seems to be in line with a new taint query.

@ghost ghost added the JS label Oct 7, 2019
@ghost ghost self-requested a review as a code owner October 7, 2019 13:30
@erik-krogh
Copy link
Contributor

If you include process.execPath as a source, shouldn't you then also include reads from process.argv, process.execArgv (and possibly process_env?)

@ghost
Copy link
Author

ghost commented Oct 8, 2019

process.argv is covered by js/indirect-command-line-injection/https://lgtm.com/rules/1509670596145/, with a much higher FP rate in practice, I am sure it is the right choice to keep these two queries separate.

process.execArgv maybe belongs as a source in js/indirect-command-line-injection, but I think the FP rate will be abysmal.

The properties of process.env.X is an interesting (and obvious, doh) source, I have made a note about it here as I suspect it will lead to noisy false positives that require special casing on specific environment variable names.

@erik-krogh
Copy link
Contributor

LGTM. But someone else should also take a look.

(The build fails due to mixed tabs and spaces).

Copy link

@xiemaisi xiemaisi left a comment

Choose a reason for hiding this comment

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

Mostly LGTM, a number of minor suggestions and comments.

@xiemaisi xiemaisi requested a review from a team October 16, 2019 14:13
@ghost ghost requested a review from mchammer01 as a code owner October 17, 2019 06:57
@xiemaisi xiemaisi removed the request for review from a team October 17, 2019 08:24
xiemaisi
xiemaisi previously approved these changes Oct 17, 2019
Copy link
Contributor

@mchammer01 mchammer01 left a comment

Choose a reason for hiding this comment

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

@esben-semmle - first editorial review completed. One minor suggestion (and I agree with @xiemaisi's comments too). LGTM apart from that.
Have we lost the HTML previews?

@ghost
Copy link
Author

ghost commented Oct 17, 2019

All comments addressed.
I have rebased away the conflict, and squashed the review-fixups at the same time.

@ghost
Copy link
Author

ghost commented Oct 17, 2019

Have we lost the HTML previews?

No, it is there now. Maybe it was not produced because of the merge conflict (I did not check).

Copy link
Contributor

@mchammer01 mchammer01 left a comment

Choose a reason for hiding this comment

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

Hi @esben-semmle - thanks for the quick fixes. I checked the fixes on the preview and noticed a typo and a punctuation minor issue (sorry for not reporting them before) - see inline suggestions for more detail.

@ghost
Copy link
Author

ghost commented Oct 18, 2019

Thanks. I have applied the suggestions.

xiemaisi
xiemaisi previously approved these changes Oct 18, 2019
@xiemaisi
Copy link

This looks good to go; could you squash the fixups?

@ghost
Copy link
Author

ghost commented Oct 21, 2019

Done

@xiemaisi
Copy link

@mchammer01, could you re-approve this PR?

@mchammer01
Copy link
Contributor

done 😉

@semmle-qlci semmle-qlci merged commit 1c79ec5 into github:master Oct 22, 2019
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