Skip to content

Commit 9189f23

Browse files
committed
add support for secure-random
1 parent 16ec405 commit 9189f23

3 files changed

Lines changed: 10 additions & 1 deletion

File tree

javascript/ql/src/Security/CWE-327/BadRandomness.ql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ private DataFlow::SourceNode randomBufferSource() {
2626
)
2727
or
2828
result = DataFlow::globalVarRef("crypto").getAMethodCall("getRandomValues")
29+
or
30+
result = DataFlow::moduleImport("secure-random").getACall()
31+
or
32+
result = DataFlow::moduleImport("secure-random").getAMethodCall(["randomArray", "randomUint8Array", "randomBuffer"])
2933
}
3034

3135
/**

javascript/ql/test/query-tests/Security/CWE-327/BadRandomness.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
| bad-random.js:14:11:14:63 | Number( ... (0, 3)) | Using string concatenation on cryptographically random numbers produces biased results. |
66
| bad-random.js:73:32:73:42 | byte / 25.6 | Using division on cryptographically random numbers produces biased results. |
77
| bad-random.js:75:21:75:30 | byte % 100 | Using modulo on cryptographically random numbers produces biased results. |
8+
| bad-random.js:81:11:81:51 | secureR ... (10)[0] | Using addition on cryptographically random numbers produces biased results. |

javascript/ql/test/query-tests/Security/CWE-327/bad-random.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,8 @@ function setSteps() {
7474
digits.push(byte % 8); // OK - 8 is a power of 2, so the result is unbiased.
7575
digits.push(byte % 100); // NOT OK
7676
}
77-
}
77+
}
78+
79+
const secureRandom = require("secure-random");
80+
81+
var bad = secureRandom(10)[0] + secureRandom(10)[0]; // NOT OK

0 commit comments

Comments
 (0)