Skip to content

Commit 243dea7

Browse files
authored
Merge pull request github#3269 from erik-krogh/Promisify
Approved by esbena
2 parents 9008084 + cffa911 commit 243dea7

File tree

7 files changed

+270
-3
lines changed

7 files changed

+270
-3
lines changed

change-notes/1.24/analysis-javascript.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686
| Useless regular-expression character escape (`js/useless-regexp-character-escape`) | Fewer false positive results | This query now distinguishes escapes in strings and regular expression literals. |
8787
| Identical operands (`js/redundant-operation`) | Fewer results | This query now recognizes cases where the operands change a value using ++/-- expressions. |
8888
| Superfluous trailing arguments (`js/superfluous-trailing-arguments`) | Fewer results | This query now recognizes cases where a function uses the `Function.arguments` value to process a variable number of parameters. |
89-
| Incomplete URL scheme check (`js/incomplete-url-scheme-check`) | More results | This query now recognizes more variations of URL scheme checks. |
89+
| Incomplete URL scheme check (`js/incomplete-url-scheme-check`) | More results | This query now recognizes additional variations of URL scheme checks. |
9090

9191
## Changes to libraries
9292

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Improvements to JavaScript analysis
2+
3+
## General improvements
4+
5+
6+
## New queries
7+
8+
| **Query** | **Tags** | **Purpose** |
9+
|---------------------------------------------------------------------------------|-------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
10+
11+
12+
## Changes to existing queries
13+
14+
| **Query** | **Expected impact** | **Change** |
15+
|--------------------------------|------------------------------|---------------------------------------------------------------------------|
16+
| Uncontrolled data used in path expression (`js/path-injection`) | More results | This query now recognizes additional file system calls. |
17+
| Uncontrolled command line (`js/command-line-injection`) | More results | This query now recognizes additional command execution calls. |
18+
19+
## Changes to libraries
20+
21+
22+

javascript/ql/src/semmle/javascript/frameworks/NodeJSLib.qll

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ module NodeJSLib {
459459
private class NodeJSFileSystemAccess extends FileSystemAccess, DataFlow::CallNode {
460460
string methodName;
461461

462-
NodeJSFileSystemAccess() { this = fsModuleMember(methodName).getACall() }
462+
NodeJSFileSystemAccess() { this = maybePromisified(fsModuleMember(methodName)).getACall() }
463463

464464
/**
465465
* Gets the name of the called method.
@@ -586,14 +586,27 @@ module NodeJSLib {
586586
}
587587
}
588588

589+
/**
590+
* Gets a possibly promisified (using `util.promisify`) version of the input `callback`.
591+
*/
592+
private DataFlow::SourceNode maybePromisified(DataFlow::SourceNode callback) {
593+
result = callback
594+
or
595+
exists(DataFlow::CallNode promisify |
596+
promisify = DataFlow::moduleMember("util", "promisify").getACall()
597+
|
598+
result = promisify and promisify.getArgument(0).getALocalSource() = callback
599+
)
600+
}
601+
589602
/**
590603
* A call to a method from module `child_process`.
591604
*/
592605
private class ChildProcessMethodCall extends SystemCommandExecution, DataFlow::CallNode {
593606
string methodName;
594607

595608
ChildProcessMethodCall() {
596-
this = DataFlow::moduleMember("child_process", methodName).getACall()
609+
this = maybePromisified(DataFlow::moduleMember("child_process", methodName)).getACall()
597610
}
598611

599612
private DataFlow::Node getACommandArgument(boolean shell) {

0 commit comments

Comments
 (0)