# VNX-929: Broken hash algorithm (MD5, MD2, MD4, SHA-1) in Java or Kotlin

CWE-929 is an OWASP Top Ten 2013 category with no code shape of its own.

| Field | Value |
|---|---|
| Rule ID | `VNX-929` |
| Severity | Medium |
| SARIF level | `warning` |
| Kind | `sast` |
| Languages | Java, Kotlin |
| CWE | [CWE-929](https://cwe.mitre.org/data/definitions/929.html) |
| CAPEC | [CAPEC-66](https://capec.mitre.org/data/definitions/66.html) |
| ATT&CK | [T1190](https://attack.mitre.org/techniques/T1190/) |
| CWSS vector | `CWSS:1.0/TI:M/AP:RU/AL:S/IC:N/FC:LT/RP:RU/RL:S/AV:L/AS:N/IN:A/SC:A/BI:M/DI:H/EX:M/EC:N/P:C` |
| Tags | `weak-hash-mobile` `crypto` `cwe-929` |
| Source | [`internal/sast/rules/vnx-929.rego`](https://github.com/Vulnesis/cli/blob/main/internal/sast/rules/vnx-929.rego) |

## Overview

CWE-929 is an OWASP Top Ten 2013 category with no code shape of its own; this rule reports the concrete Java/Kotlin signal it was generated for, a collision-broken digest: MessageDigest.getInstance("MD5"/"MD2"/"MD4"/"SHA-1"/"SHA1"/"SHA"), the same name passed through a String constant assigned in the same file, Apache commons-codec DigestUtils.md5/md5Hex/sha1/sha1Hex/sha/shaHex/md2 (and getMd5Digest/getSha1Digest), and Guava Hashing.md5()/Hashing.sha1(). Not reported: SHA-2 and SHA-3 digests, algorithm names in comments and strings, and digests whose surrounding code names a non-security purpose (an ETag, checksum, CRC, cache key, fingerprint, de-duplication or the RFC 6455 WebSocket accept key). In a `.java` file this rule reports only MD2 and MD4. An MD5 or SHA-1 digest in Java is reported by [VNX-CRYPTO-001](/sast/rules/vnx-crypto-001.md) (MD5) and [VNX-CRYPTO-002](/sast/rules/vnx-crypto-002.md) (SHA-1), or by [VNX-327](/sast/rules/vnx-327.md) when it protects a password or token, so the same line is not reported twice. Kotlin, which those rules do not read, keeps all four algorithms here.

## Why this matters

MD5 and SHA-1 collisions can be produced cheaply, and both are fast enough to brute-force passwords at billions of guesses a second. A token, signature or password hash built on them gives far less protection than it appears to.

## What gets flagged

```
// Java
MessageDigest md2 = MessageDigest.getInstance("MD2");
MessageDigest md4 = MessageDigest.getInstance("MD4");
// Kotlin
val md = MessageDigest.getInstance("MD5")
fun token(user: String) = DigestUtils.sha1Hex(user + System.nanoTime())
```

## What is not flagged

```
// Java MD5 and SHA-1: reported by VNX-CRYPTO-001, VNX-CRYPTO-002 or VNX-327
MessageDigest md5 = MessageDigest.getInstance("MD5");
MessageDigest md = MessageDigest.getInstance("SHA-256");
// ETag for a static asset, not a security use
String etag = DigestUtils.md5Hex(body);
```

## Remediation

1. Use SHA-256 or SHA-3 for integrity and signatures.
2. Use a password KDF (Argon2, bcrypt, scrypt or PBKDF2) for passwords.
3. Where MD5 or SHA-1 is required for a non-security purpose, name it (an ETag or checksum variable) so the intent is clear.
4. For a confirmed false positive, add a `vulnetix-ignore: VNX-929` comment on the line.

## References

- [CWE-929](https://cwe.mitre.org/data/definitions/929.html)
- [NIST policy on hash functions](https://csrc.nist.gov/projects/hash-functions/nist-policy-on-hash-functions)

## Suppressing this rule

Put a `nosec` comment on the line, or on line 1 to cover the whole file. Use the comment marker of the file's language (`#`, `//`, `--` or `;`):

```text
# nosec vnx-929
// nosec vnx-929
```

Or record an ignore rule: `vulnetix ignore add --rule vnx-929 --reason "..."`. See [Suppressing findings](/sast/guides/suppressing-findings.md).
