Skip to content

Commit a589061

Browse files
committed
JS: add type-tracking to the fs-module and model the original-fs
1 parent 5a3a1c4 commit a589061

File tree

5 files changed

+273
-8
lines changed

5 files changed

+273
-8
lines changed

change-notes/1.24/analysis-javascript.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
| Expression has no effect (`js/useless-expression`) | Fewer false positive results | The query now recognizes block-level flow type annotations and ignores the first statement of a try block. |
5959
| Use of call stack introspection in strict mode (`js/strict-mode-call-stack-introspection`) | Fewer false positive results | The query no longer flags expression statements. |
6060
| Missing CSRF middleware (`js/missing-token-validation`) | Fewer false positive results | The query reports fewer duplicates and only flags handlers that explicitly access cookie data. |
61-
| Uncontrolled data used in path expression (`js/path-injection`) | More results | This query now recognizes additional ways dangerous paths can be constructed. |
61+
| Uncontrolled data used in path expression (`js/path-injection`) | More results | This query now recognizes additional ways dangerous paths can be constructed and used. |
6262
| Uncontrolled command line (`js/command-line-injection`) | More results | This query now recognizes additional ways of constructing arguments to `cmd.exe` and `/bin/sh`. |
6363

6464
## Changes to libraries

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

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -429,16 +429,27 @@ module NodeJSLib {
429429
}
430430

431431
/**
432-
* A member `member` from module `fs` or its drop-in replacements `graceful-fs` or `fs-extra`.
432+
* A member `member` from module `fs` or its drop-in replacements `graceful-fs`, `fs-extra`, `original-fs`.
433433
*/
434434
private DataFlow::SourceNode fsModuleMember(string member) {
435+
result = fsModule(DataFlow::TypeTracker::end()).getAPropertyRead(member)
436+
}
437+
438+
private DataFlow::SourceNode fsModule(DataFlow::TypeTracker t) {
435439
exists(string moduleName |
436440
moduleName = "fs" or
437441
moduleName = "graceful-fs" or
438-
moduleName = "fs-extra"
442+
moduleName = "fs-extra" or
443+
moduleName = "original-fs"
439444
|
440-
result = DataFlow::moduleMember(moduleName, member)
441-
)
445+
result = DataFlow::moduleImport(moduleName)
446+
or
447+
// extra support for flexible names
448+
result.asExpr().(Require).getArgument(0).mayHaveStringValue(moduleName)
449+
) and
450+
t.start()
451+
or
452+
exists(DataFlow::TypeTracker t2 | result = fsModule(t2).track(t2, t))
442453
}
443454

444455
/**
Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
| normalizedPaths.js:208:38:208:63 | // OK - ... anyway | Spurious alert |
2-
| other-fs-libraries.js:14:34:14:42 | // NOT OK | Missing alert |
3-
| other-fs-libraries.js:16:41:16:49 | // NOT OK | Missing alert |
4-
| other-fs-libraries.js:17:42:17:50 | // NOT OK | Missing alert |
52
| tainted-string-steps.js:25:43:25:74 | // NOT ... flagged | Missing alert |
63
| tainted-string-steps.js:26:49:26:74 | // OK - ... flagged | Spurious alert |
74
| tainted-string-steps.js:28:39:28:70 | // NOT ... flagged | Missing alert |

0 commit comments

Comments
 (0)