Description
Known collisions in MD5 and SHA-1 make them unsuitable for identifiers or integrity checks that require collision resistance. Passwords also need a hash that makes each guess expensive.
Potential impact
- Integrity-check bypass
- Increased risk of forged tokens or authentication data
- Weaker password storage
Remediation
- Use SHA-256, SHA-512 or SHA-3 for an identifier or integrity check that requires collision resistance. Isolate any legacy MD5 or SHA-1 code from security decisions.
- For passwords, use Argon2id, scrypt, PBKDF2, or bcrypt where an existing system requires it.
Examples
Before
swift
let digest = Insecure.MD5.hash(data: tokenData)
After
swift
import Foundation
import CryptoKit
func hashToken(_ tokenData: Data) -> SHA512.Digest {
return SHA512.hash(data: tokenData)
}
hashToken computes a SHA-512 identifier for a token. This use assumes the token was generated with enough entropy to resist guessing.