mirror of
https://github.com/github/codeql.git
synced 2026-05-01 19:55:15 +02:00
Merge pull request #632 from asger-semmle/pseudo-random-bytes
JS: add crypto.pseudoRandomBytes as source in InsecureRandomness.ql
This commit is contained in:
@@ -68,7 +68,7 @@ module InsecureRandomness {
|
||||
* A simple random number generator that is not cryptographically secure.
|
||||
*/
|
||||
class DefaultSource extends Source, DataFlow::ValueNode {
|
||||
override CallExpr astNode;
|
||||
override InvokeExpr astNode;
|
||||
|
||||
DefaultSource() {
|
||||
exists(DataFlow::ModuleImportNode mod, string name | mod.getPath() = name |
|
||||
@@ -98,6 +98,9 @@ module InsecureRandomness {
|
||||
or
|
||||
// (new require('chance')).<name>()
|
||||
this = DataFlow::moduleImport("chance").getAnInstantiation().getAMemberInvocation(_)
|
||||
or
|
||||
// require('crypto').pseudoRandomBytes()
|
||||
this = DataFlow::moduleMember("crypto", "pseudoRandomBytes").getAnInvocation()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,3 +6,5 @@
|
||||
| tst.js:15:1:15:12 | randomSeed() |
|
||||
| tst.js:18:1:18:14 | uniqueRandom() |
|
||||
| tst.js:22:1:22:12 | chance.XYZ() |
|
||||
| tst.js:25:1:25:29 | crypto. ... es(100) |
|
||||
| tst.js:26:1:26:33 | new cry ... es(100) |
|
||||
|
||||
@@ -20,3 +20,7 @@ uniqueRandom();
|
||||
var Chance = require('chance'),
|
||||
chance = new Chance();
|
||||
chance.XYZ();
|
||||
|
||||
let crypto = require('crypto');
|
||||
crypto.pseudoRandomBytes(100);
|
||||
new crypto.pseudoRandomBytes(100);
|
||||
|
||||
Reference in New Issue
Block a user