You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
| bad-random.js:3:11:3:61 | crypto. ... s(1)[0] | Using addition on a $@ produces biased results. | bad-random.js:3:11:3:31 | crypto. ... ytes(1) | cryptographically random number |
2
-
| bad-random.js:3:11:3:61 | crypto. ... s(1)[0] | Using addition on a $@ produces biased results. | bad-random.js:3:38:3:58 | crypto. ... ytes(1) | cryptographically random number |
3
-
| bad-random.js:4:11:4:61 | crypto. ... s(1)[0] | Using multiplication on a $@ produces biased results. | bad-random.js:4:11:4:31 | crypto. ... ytes(1) | cryptographically random number |
4
-
| bad-random.js:4:11:4:61 | crypto. ... s(1)[0] | Using multiplication on a $@ produces biased results. | bad-random.js:4:38:4:58 | crypto. ... ytes(1) | cryptographically random number |
5
-
| bad-random.js:9:28:9:43 | buffer[i] / 25.6 | Using division on a $@ produces biased results. | bad-random.js:6:16:6:40 | crypto. ... (bytes) | cryptographically random number |
6
-
| bad-random.js:11:17:11:31 | buffer[i] % 100 | Using modulo on a $@ produces biased results. | bad-random.js:6:16:6:40 | crypto. ... (bytes) | cryptographically random number |
7
-
| bad-random.js:14:11:14:63 | Number( ... (0, 3)) | Using string concatenation on a $@ produces biased results. | bad-random.js:14:25:14:45 | crypto. ... ytes(3) | cryptographically random number |
8
-
| bad-random.js:73:32:73:42 | byte / 25.6 | Using division on a $@ produces biased results. | bad-random.js:70:20:70:44 | crypto. ... (bytes) | cryptographically random number |
9
-
| bad-random.js:75:21:75:30 | byte % 100 | Using modulo on a $@ produces biased results. | bad-random.js:70:20:70:44 | crypto. ... (bytes) | cryptographically random number |
10
-
| bad-random.js:81:11:81:51 | secureR ... (10)[0] | Using addition on a $@ produces biased results. | bad-random.js:81:11:81:26 | secureRandom(10) | cryptographically random number |
11
-
| bad-random.js:81:11:81:51 | secureR ... (10)[0] | Using addition on a $@ produces biased results. | bad-random.js:81:33:81:48 | secureRandom(10) | cryptographically random number |
12
-
| bad-random.js:85:11:85:35 | goodRan ... Random2 | Using addition on a $@ produces biased results. | bad-random.js:83:23:83:38 | secureRandom(10) | cryptographically random number |
13
-
| bad-random.js:85:11:85:35 | goodRan ... Random2 | Using addition on a $@ produces biased results. | bad-random.js:84:23:84:38 | secureRandom(10) | cryptographically random number |
14
-
| bad-random.js:87:16:87:24 | bad + bad | Using addition on a $@ produces biased results. | bad-random.js:83:23:83:38 | secureRandom(10) | cryptographically random number |
15
-
| bad-random.js:87:16:87:24 | bad + bad | Using addition on a $@ produces biased results. | bad-random.js:84:23:84:38 | secureRandom(10) | cryptographically random number |
1
+
| bad-random.js:3:11:3:61 | crypto. ... s(1)[0] | Using addition on a $@ produces biased results. | bad-random.js:3:11:3:31 | crypto. ... ytes(1) | cryptographically secure random number |
2
+
| bad-random.js:3:11:3:61 | crypto. ... s(1)[0] | Using addition on a $@ produces biased results. | bad-random.js:3:38:3:58 | crypto. ... ytes(1) | cryptographically secure random number |
3
+
| bad-random.js:4:11:4:61 | crypto. ... s(1)[0] | Using multiplication on a $@ produces biased results. | bad-random.js:4:11:4:31 | crypto. ... ytes(1) | cryptographically secure random number |
4
+
| bad-random.js:4:11:4:61 | crypto. ... s(1)[0] | Using multiplication on a $@ produces biased results. | bad-random.js:4:38:4:58 | crypto. ... ytes(1) | cryptographically secure random number |
5
+
| bad-random.js:9:28:9:43 | buffer[i] / 25.6 | Using division and rounding the result on a $@ produces biased results. | bad-random.js:6:16:6:40 | crypto. ... (bytes) | cryptographically secure random number |
6
+
| bad-random.js:11:17:11:31 | buffer[i] % 100 | Using modulo on a $@ produces biased results. | bad-random.js:6:16:6:40 | crypto. ... (bytes) | cryptographically secure random number |
7
+
| bad-random.js:14:11:14:63 | Number( ... (0, 3)) | Using string concatenation on a $@ produces biased results. | bad-random.js:14:25:14:45 | crypto. ... ytes(3) | cryptographically secure random number |
8
+
| bad-random.js:73:32:73:42 | byte / 25.6 | Using division and rounding the result on a $@ produces biased results. | bad-random.js:70:20:70:44 | crypto. ... (bytes) | cryptographically secure random number |
9
+
| bad-random.js:75:21:75:30 | byte % 100 | Using modulo on a $@ produces biased results. | bad-random.js:70:20:70:44 | crypto. ... (bytes) | cryptographically secure random number |
10
+
| bad-random.js:81:11:81:51 | secureR ... (10)[0] | Using addition on a $@ produces biased results. | bad-random.js:81:11:81:26 | secureRandom(10) | cryptographically secure random number |
11
+
| bad-random.js:81:11:81:51 | secureR ... (10)[0] | Using addition on a $@ produces biased results. | bad-random.js:81:33:81:48 | secureRandom(10) | cryptographically secure random number |
12
+
| bad-random.js:85:11:85:35 | goodRan ... Random2 | Using addition on a $@ produces biased results. | bad-random.js:83:23:83:38 | secureRandom(10) | cryptographically secure random number |
13
+
| bad-random.js:85:11:85:35 | goodRan ... Random2 | Using addition on a $@ produces biased results. | bad-random.js:84:23:84:38 | secureRandom(10) | cryptographically secure random number |
14
+
| bad-random.js:87:16:87:24 | bad + bad | Using addition on a $@ produces biased results. | bad-random.js:83:23:83:38 | secureRandom(10) | cryptographically secure random number |
15
+
| bad-random.js:87:16:87:24 | bad + bad | Using addition on a $@ produces biased results. | bad-random.js:84:23:84:38 | secureRandom(10) | cryptographically secure random number |
16
+
| bad-random.js:90:29:90:54 | secureR ... / 25.6 | Using division and rounding the result on a $@ produces biased results. | bad-random.js:90:29:90:44 | secureRandom(10) | cryptographically secure random number |
17
+
| bad-random.js:96:29:96:58 | crypto. ... ] / 100 | Using division and rounding the result on a $@ produces biased results. | bad-random.js:96:29:96:49 | crypto. ... ytes(1) | cryptographically secure random number |
Copy file name to clipboardExpand all lines: javascript/ql/test/query-tests/Security/CWE-327/bad-random.js
+27-1Lines changed: 27 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -84,4 +84,30 @@ var goodRandom1 = 5 + secureRandom(10)[0];
84
84
vargoodRandom2=5+secureRandom(10)[0];
85
85
varbad=goodRandom1+goodRandom2;// NOT OK
86
86
87
-
vardontFlag=bad+bad;// OK - the operands have already been flagged - but flagged anyway due to us not detecting that [INCONSISTENCY].
87
+
vardontFlag=bad+bad;// OK - the operands have already been flagged - but flagged anyway due to us not detecting that [INCONSISTENCY].
88
+
89
+
vargood=secureRandom(10)[0]/0xff;// OK - result is not rounded.
90
+
vargood=Math.ceil(0.5-(secureRandom(10)[0]/25.6));// NOT OK - division generally introduces bias.
91
+
92
+
vargood=(crypto.randomBytes(1)[0]<<8)+crypto.randomBytes(3)[0];// OK - bit shifts are usually used to construct larger/smaller numbers,
93
+
94
+
vargood=Math.floor(max*(crypto.randomBytes(1)[0]/0xff));// OK - division by 0xff (255) gives a uniformly random number between 0 and 1.
95
+
96
+
varbad=Math.floor(max*(crypto.randomBytes(1)[0]/100));// NOT OK - division by 100 gives bias.
97
+
98
+
varcrb=crypto.randomBytes(4);
99
+
varcryptoRand=0x01000000*crb[0]+0x00010000*crb[1]+0x00000100*crb[2]+0x00000001*crb[3];// OK - producing a larger number from smaller numbers.
100
+
101
+
vargood=(secureRandom(10)[0]+"foo")+(secureRandom(10)[0]+"bar");// OK - string concat
102
+
103
+
vareight=8;
104
+
vargood=crypto.randomBytes(4)[0]%eight;// OK - modulo by power of 2.
105
+
106
+
vartwoHundredAndFiftyFive=0xff;
107
+
vargood=Math.floor(max*(crypto.randomBytes(1)[0]/twoHundredAndFiftyFive));// OK - division by 0xff (255) gives a uniformly random number between 0 and 1.
108
+
109
+
vara=crypto.randomBytes(10);
110
+
vargood=((a[i]&31)*0x1000000000000)+(a[i+1]*0x10000000000)+(a[i+2]*0x100000000)+(a[i+3]*0x1000000)+(a[i+4]<<16)+(a[i+5]<<8)+a[i+6];// OK - generating a large number from smaller bytes.
111
+
vargood=(a[i]*0x100000000)+a[i+6];// OK - generating a large number from smaller bytes.
112
+
vargood=(a[i+2]*0x10000000)+a[i+6];// OK - generating a large number from smaller bytes.
0 commit comments