Skip to content

Commit a01a9dc

Browse files
committed
JS: add crypto.pseudoRandomBytes as source in InsecureRandomness.ql
1 parent a4b3b1e commit a01a9dc

File tree

4 files changed

+11
-1
lines changed

4 files changed

+11
-1
lines changed

change-notes/1.20/analysis-javascript.md

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
| **Query** | **Expected impact** | **Change** |
2121
|--------------------------------------------|------------------------------|------------------------------------------------------------------------------|
2222
| Client-side cross-site scripting | More results | This rule now recognizes WinJS functions that are vulnerable to HTML injection. |
23+
| Insecure randomness | More results | This rule now flags insecure uses of `crypto.pseudoRandomBytes`. |
2324
| Unused variable, import, function or class | Fewer false-positive results | This rule now flags fewer variables that are implictly used by JSX elements. |
2425

2526
## Changes to QL libraries

javascript/ql/src/semmle/javascript/security/dataflow/InsecureRandomness.qll

+4-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ module InsecureRandomness {
6868
* A simple random number generator that is not cryptographically secure.
6969
*/
7070
class DefaultSource extends Source, DataFlow::ValueNode {
71-
override CallExpr astNode;
71+
override InvokeExpr astNode;
7272

7373
DefaultSource() {
7474
exists(DataFlow::ModuleImportNode mod, string name | mod.getPath() = name |
@@ -98,6 +98,9 @@ module InsecureRandomness {
9898
or
9999
// (new require('chance')).<name>()
100100
this = DataFlow::moduleImport("chance").getAnInstantiation().getAMemberInvocation(_)
101+
or
102+
// require('crypto').pseudoRandomBytes()
103+
this = DataFlow::moduleMember("crypto", "pseudoRandomBytes").getAnInvocation()
101104
}
102105
}
103106

javascript/ql/test/library-tests/Security/CWE-338/InsecureRandomnessSource.expected

+2
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@
66
| tst.js:15:1:15:12 | randomSeed() |
77
| tst.js:18:1:18:14 | uniqueRandom() |
88
| tst.js:22:1:22:12 | chance.XYZ() |
9+
| tst.js:25:1:25:29 | crypto. ... es(100) |
10+
| tst.js:26:1:26:33 | new cry ... es(100) |

javascript/ql/test/library-tests/Security/CWE-338/tst.js

+4
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,7 @@ uniqueRandom();
2020
var Chance = require('chance'),
2121
chance = new Chance();
2222
chance.XYZ();
23+
24+
let crypto = require('crypto');
25+
crypto.pseudoRandomBytes(100);
26+
new crypto.pseudoRandomBytes(100);

0 commit comments

Comments
 (0)