File tree 2 files changed +5
-3
lines changed
javascript/ql/src/Security/CWE-338
2 files changed +5
-3
lines changed Original file line number Diff line number Diff line change 36
36
<p >
37
37
38
38
For JavaScript in the browser,
39
- <code >RandomSource .getRandomValues</code > provides a cryptographically
39
+ <code >crypto .getRandomValues</code > provides a cryptographically
40
40
secure pseudo-random number generator.
41
41
42
42
</p >
69
69
70
70
<references >
71
71
<li >Wikipedia: <a href =" http://en.wikipedia.org/wiki/Pseudorandom_number_generator" >Pseudo-random number generator</a >.</li >
72
- <li >Mozilla Developer Network: <a href =" https://developer.mozilla.org/en-US/docs/Web/API/RandomSource /getRandomValues" >RandomSource. getRandomValues</a >.</li >
72
+ <li >Mozilla Developer Network: <a href =" https://developer.mozilla.org/en-US/docs/Web/API/Crypto /getRandomValues" >Crypto: getRandomValues() </a >.</li >
73
73
<li >NodeJS: <a href =" https://nodejs.org/api/crypto.html#crypto_crypto_randombytes_size_callback" >crypto.randomBytes</a ></li >
74
74
</references >
75
75
</qhelp >
Original file line number Diff line number Diff line change @@ -2,5 +2,7 @@ function securePassword() {
2
2
// GOOD: the random suffix is cryptographically secure
3
3
var suffix = window . crypto . getRandomValues ( new Uint32Array ( 1 ) ) [ 0 ] ;
4
4
var password = "myPassword" + suffix ;
5
- return password ;
5
+
6
+ // GOOD: if a random value between 0 and 1 is desired
7
+ var secret = window . crypto . getRandomValues ( new Uint32Array ( 1 ) ) [ 0 ] * Math . pow ( 2 , - 32 ) ;
6
8
}
You can’t perform that action at this time.
0 commit comments