Skip to content

Commit cb0ea35

Browse files
committed
Improve docs
1 parent 0efca82 commit cb0ea35

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import java.io.FileInputStream;
2+
import java.util.Properties;
3+
import java.security.MessageDigest;
4+
5+
Properties props = Properties.load(new FileInputStream("settings.properties"));
6+
7+
// BAD: the `hashAlgorithm` variable in `settings.properties` is `MD5` which is
8+
// a weak hashing algorithm.
9+
MessageDigest.getInstance(props.getProperty("hashAlgorithm"));

java/ql/src/Security/CWE/CWE-328/WeakHashingProperty.qhelp

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,31 @@
22
"-//Semmle//qhelp//EN"
33
"qhelp.dtd">
44
<qhelp>
5-
<include src="../CWE-327/BrokenCryptoAlgorithm.qhelp" /></qhelp>
5+
<overview>
6+
<p>
7+
Using a weak hashing algorithm can result in attackers being able to
8+
determine the original input to a hash function or create a second input
9+
which will produce the same hash.
10+
</p>
11+
</overview>
12+
13+
<recommendation>
14+
<p>Ensure you are using a strong, modern hashing algorithm, such as SHA-256.</p>
15+
</recommendation>
16+
17+
<example>
18+
<p>In the following (BAD) example, the <code>MD5</code> hashing algorithm is used, specified in a <code>.properties</code> file.</p>
19+
20+
<sample src="settings.properties"/>
21+
22+
<sample src="WeakHashingProperty.java"/>
23+
24+
</example>
25+
26+
<references>
27+
<li>NIST, FIPS 140 Annex a: <a href="http://csrc.nist.gov/publications/fips/fips140-2/fips1402annexa.pdf">
28+
Approved Security Functions</a>.</li>
29+
<li>NIST, SP 800-131A: <a href="http://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-131Ar1.pdf">
30+
Transitions: Recommendation for Transitioning the Use of Cryptographic Algorithms and Key Lengths</a>.</li>
31+
</references>
32+
</qhelp>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
hashAlgorithm=MD5

0 commit comments

Comments
 (0)