Skip to content

Commit 54bb9d1

Browse files
author
Max Schaefer
authored
Merge pull request #632 from asger-semmle/pseudo-random-bytes
JS: add crypto.pseudoRandomBytes as source in InsecureRandomness.ql
2 parents df42707 + 4fc27aa commit 54bb9d1

File tree

4 files changed

+11
-1
lines changed

4 files changed

+11
-1
lines changed

change-notes/1.20/analysis-javascript.md

Lines changed: 1 addition & 0 deletions
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 parameter | Fewer false-positive results | This rule no longer flags parameters with leading underscore. |
2425
| Unused variable, import, function or class | Fewer false-positive results | This rule now flags fewer variables that are implictly used by JSX elements, and no longer flags variables with leading underscore. |
2526

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

Lines changed: 4 additions & 1 deletion
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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 4 additions & 0 deletions
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)