Insecure hashing Medium

A hashing algorithm is weak if it is easy to determine the original input from the hash or to find another input that yields the same hash. Weak hashing algorithms can lead to security vulnerabilities.

Detector ID
javascript/insecure-hashing@v1.0
Category
Common Weakness Enumeration (CWE) external icon

Noncompliant example

1var crypto = require('crypto')
2function insecureHashingNoncompliant()
3{
4    // Noncompliant: 'md5' is weak hash algorithm.
5    var insecure_hash_algo = 'md5'
6    crypto.createHash(insecure_hash_algo)
7}

Compliant example

1var crypto = require('crypto')
2function insecureHashingCompliant()
3{
4    // Compliant: 'SHA-256' is secure hash algorithm.
5    var secure_hash_algo = 'SHA-256'
6    crypto.createHash(secure_hash_algo)
7}