Rule Definition
Many web applications and APIs do not properly protect sensitive data, such as financial, healthcare, and PII. Attackers may steal or modify such weakly protected data to conduct credit card fraud, identity theft, or other crimes. Sensitive data may be compromised without extra protection, such as encryption at rest or in transit, and requires special precautions when exchanged with the browser.
The use of a non-standard algorithm is dangerous because a determined attacker may be able to break the algorithm and compromise whatever data has been protected. Well-known techniques may exist to break the algorithm.
Remediation
Avoid using MD5 or SHA1 hashes as input to cryptographic functions or to store passwords. Node.js offers the following hashing algorithms: SHA224, SHA256, SHA384, and SHA512. Make sure you choose the most appropriate one, depending on your use case, security requirements and runtime constraints.
Violation Code Sample
const filename = process.argv[2];
import * as crypto from 'crypto';
import * as fs from 'fs';
const hash = crypto.createHash('md5');
const input = fs.createReadStream(filename);
input.on('readable', () => {
const data = input.read();
if (data)
hash.update(data);
else {
console.log(`${hash.digest('hex')} ${filename}`);
}
});
Fixed Code Sample
const filename = process.argv[2];
import * as crypto from 'crypto';
import * as fs from 'fs';
const hash = crypto.createHash('sha256');
const input = fs.createReadStream(filename);
input.on('readable', () => {
const data = input.read();
if (data)
hash.update(data);
else {
console.log(`${hash.digest('hex')} ${filename}`);
}
})
Reference
https://cwe.mitre.org/data/definitions/327.html
https://www.owasp.org/index.php/Top_10_2013-A6-Sensitive_Data_Exposure
https://www.owasp.org/index.php/Top_10-2017_A3-Sensitive_Data_Exposure
Related Technologies
Technical Criterion
PCI-DSS4-Requirement-4.2.1 - Strong cryptography and security protocols are implemented
About CAST Appmarq
CAST Appmarq is by far the biggest repository of data about real IT systems. It's built on thousands of analyzed applications, made of 35 different technologies, by over 300 business organizations across major verticals. It provides IT Leaders with factual key analytics to let them know if their applications are on track.