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
If you use a cryptographically weak pseudo-random number generator to generate security-sensitive values,
8
+
such as passwords, attackers can more easily predict those values.
9
+
</p>
10
+
<p>
11
+
Pseudo-random number generators generate a sequence of numbers that only approximates the properties
12
+
of random numbers. The sequence is not truly random because it is completely determined by a
13
+
relatively small set of initial values (the seed). If the random number generator is
14
+
cryptographically weak, then this sequence may be easily predictable through outside observations.
15
+
</p>
16
+
17
+
</overview>
18
+
<recommendation>
19
+
<p>
20
+
The <code>java.util.Random</code> random number generator is not cryptographically secure. Use a secure random number generator such as <code>java.security.SecureRandom</code> instead.
21
+
</p>
22
+
<p>
23
+
Use a cryptographically secure pseudo-random number generator if the output is to be used in a
24
+
security-sensitive context. As a general rule, a value should be considered "security-sensitive"
25
+
if predicting it would allow the attacker to perform an action that they would otherwise be unable
26
+
to perform. For example, if an attacker could predict the random password generated for a new user,
27
+
they would be able to log in as that new user.
28
+
</p>
29
+
</recommendation>
30
+
31
+
<example>
32
+
33
+
<p>
34
+
The following examples show different ways of generating a cookie with a random value.
35
+
</p>
36
+
37
+
<p>
38
+
In the first (BAD) case, we generate a fresh cookie by appending a random integer to the end of a static
39
+
string. The random number generator used (<code>Random</code>) is not cryptographically secure,
40
+
so it may be possible for an attacker to predict the generated cookie.
* Added the `java/insecure-randomness` query to detect uses of weakly random values which an attacker may be able to predict. Also added the `crypto-parameter` sink kind for sinks which represent the parameters and keys of cryptographic operations.
0 commit comments