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
Copy file name to clipboardExpand all lines: change-notes/1.25/analysis-javascript.md
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -37,6 +37,8 @@
37
37
| Unsafe expansion of self-closing HTML tag (`js/unsafe-html-expansion`) | security, external/cwe/cwe-079, external/cwe/cwe-116 | Highlights potential XSS vulnerabilities caused by unsafe expansion of self-closing HTML tags. |
38
38
| Unsafe shell command constructed from library input (`js/shell-command-constructed-from-input`) | correctness, security, external/cwe/cwe-078, external/cwe/cwe-088 | Highlights potential command injections due to a shell command being constructed from library inputs. Results are shown on LGTM by default. |
39
39
| Download of sensitive file through insecure connection (`js/insecure-download`) | security, external/cwe/cwe-829 | Highlights downloads of sensitive files through an unencrypted protocol. Results are shown on LGTM by default. |
40
+
| Exposure of private files (`js/exposure-of-private-files`) | security, external/cwe/cwe-200 | Highlights servers that serve private files. Results are shown on LGTM by default. |
41
+
| Creating biased random numbers from a cryptographically secure source (`js/biased-cryptographic-random`) | security, external/cwe/cwe-327 | Highlights mathematical operations on cryptographically secure numbers that can create biased results. Results are shown on LGTM by default. |
40
42
| Storage of sensitive information in build artifact (`js/build-artifact-leak`) | security, external/cwe/cwe-312 | Highlights storage of sensitive information in build artifacts. Results are shown on LGTM by default. |
41
43
| Improper code sanitization (`js/bad-code-sanitization`) | security, external/cwe/cwe-094, external/cwe/cwe-079, external/cwe/cwe-116 | Highlights string concatenation where code is constructed without proper sanitization. Results are shown on LGTM by default. |
Copy file name to clipboardExpand all lines: javascript/ql/src/Security/CWE-327/BadRandomness.qhelp
+39-10Lines changed: 39 additions & 10 deletions
Original file line number
Diff line number
Diff line change
@@ -4,33 +4,62 @@
4
4
<qhelp>
5
5
<overview>
6
6
<p>
7
-
Placeholder
7
+
Generating secure random numbers can be an important part of creating a
8
+
secure software system. This can be done using APIs that create
9
+
cryptographically secure random numbers.
10
+
</p>
11
+
<p>
12
+
However, using some mathematical operations on these cryptographically
13
+
secure random numbers can create biased results, where some outcomes
14
+
are more likely than others.
15
+
Such biased results can make it easier for an attacker to guess the random
16
+
numbers, and thereby break the security of the software system.
8
17
</p>
9
-
10
18
</overview>
11
19
<recommendation>
12
-
13
20
<p>
14
-
Placeholder.
21
+
Be very careful not to introduce bias when performing mathematical operations
22
+
on cryptographically secure random numbers.
23
+
</p>
24
+
<p>
25
+
If possible, avoid performing mathematical operations on cryptographically secure
26
+
random numbers at all, and use a preexisting library instead.
15
27
</p>
16
-
17
28
</recommendation>
18
29
<example>
19
-
20
30
<p>
21
-
Placeholder
31
+
The example below uses the modulo operator to create an array of 10 random digits
32
+
using random bytes as the source for randomness.
22
33
</p>
34
+
<samplesrc="examples/bad-random.js" />
35
+
<p>
36
+
The random byte is a uniformly random value between 0 and 255, and thus the result
37
+
from using the modulo operator is slightly more likely to be between 0 and 5 than
38
+
between 6 and 9.
39
+
</p>
40
+
<p>
41
+
The issue has been fixed in the code below by using a library that correctly generates
42
+
cryptographically secure random values.
43
+
</p>
44
+
<samplesrc="examples/bad-random-fixed.js" />
45
+
<p>
46
+
Alternatively, the issue can be fixed by fixing the math in the original code.
47
+
In the code below the random byte is discarded if the value is greater than or equal to 250.
48
+
Thus the modulo operator is used on a uniformly random number between 0 and 249, which
49
+
results in a uniformly random digit between 0 and 9.
50
+
</p>
51
+
<samplesrc="examples/bad-random-fixed2.js" />
23
52
24
53
</example>
25
54
55
+
26
56
<references>
27
-
<li>NIST, FIPS 140 Annex a: <ahref="http://csrc.nist.gov/publications/fips/fips140-2/fips1402annexa.pdf"> Approved Security Functions</a>.</li>
28
-
<li>NIST, SP 800-131A: <ahref="http://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-131Ar1.pdf"> Transitions: Recommendation for Transitioning the Use of Cryptographic Algorithms and Key Lengths</a>.</li>
0 commit comments