v0.14 is out: a mobile auth pack for Swift/iOS and Android, catching insecure token storage, cleartext traffic, and OAuth in embedded WebViews. Read more →
MEDIUM AI PREVALENCE: MEDIUM auth.java.crypto.weak-hash

A broken hash algorithm (MD5 or SHA-1) is being instantiated via JCA MessageDigest.getInstance(...).

Why AI tools produce this: AI coding tools produce this regularly, typically when prompted for a shortcut or a quick fix.

Why this matters

MD5 and SHA-1 are cryptographically broken: practical collision attacks exist, so they must NOT be used for any security purpose: integrity checks, content/token fingerprints, digital signatures, HMAC keys, or deduplication that a trust decision depends on (CWE-328 / CWE-327).

Use SHA-256 or stronger (SHA-384, SHA-512, SHA-3): MessageDigest.getInstance("SHA-256"). Note: this rule covers the general weak-digest case; storing passwords needs a dedicated slow hasher (BCrypt/Argon2/PBKDF2), which is enforced separately.

VULNERABLE
vulnerable.java
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

class WeakHash {

    // Integrity fingerprint over file bytes with a broken digest.
    byte[] md5Checksum(byte[] data) throws NoSuchAlgorithmException {
        // ruleid: auth.java.crypto.weak-hash
        MessageDigest md = MessageDigest.getInstance("MD5");
        return md.digest(data);
    }

    // SHA-1 used to fingerprint a token / sign content — collision-prone.
    byte[] sha1TokenFingerprint(byte[] token) throws NoSuchAlgorithmException {
        // ruleid: auth.java.crypto.weak-hash
        MessageDigest md = MessageDigest.getInstance("SHA-1");
        return md.digest(token);
    }

    // The hyphenless "SHA1" alias is the same broken algorithm.
    byte[] sha1Alias(byte[] data) throws NoSuchAlgorithmException {
        // ruleid: auth.java.crypto.weak-hash
        MessageDigest md = MessageDigest.getInstance("SHA1");
        return md.digest(data);
    }
}
SAFE
safe.java
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

class SafeHash {

    // ok: auth.java.crypto.weak-hash -- SHA-256 is a strong digest
    byte[] sha256Checksum(byte[] data) throws NoSuchAlgorithmException {
        MessageDigest md = MessageDigest.getInstance("SHA-256");
        return md.digest(data);
    }

    // ok: auth.java.crypto.weak-hash -- SHA-512 is a strong digest
    byte[] sha512Fingerprint(byte[] data) throws NoSuchAlgorithmException {
        MessageDigest md = MessageDigest.getInstance("SHA-512");
        return md.digest(data);
    }
}

Suppressing this rule

If a finding is a genuine false positive, scope the suppression to the exact line and leave a reason, never disable the rule project-wide. Disable directives are line-scoped by design.

// oauthlint-disable-next-line auth.java.crypto.weak-hash -- <reason>

References

https://cwe.mitre.org/data/definitions/328.html ↗https://csrc.nist.gov/news/2022/nist-transitioning-away-from-sha-1-for-all-apps ↗