# VNX-327: Broken hash algorithm (MD5, SHA-1) protecting a password, token or signature

MD5 or SHA-1 is computed through a hash API on a security value.

| Field | Value |
|---|---|
| Rule ID | `VNX-327` |
| Severity | High |
| SARIF level | `error` |
| Kind | `sast` |
| Languages | Java, Kotlin, JavaScript / TypeScript, PHP, Python, Ruby |
| CWE | [CWE-327](https://cwe.mitre.org/data/definitions/327.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:H/AP:A/AL:A/IC:N/FC:LT/RP:N/RL:A/AV:I/AS:N/IN:A/SC:A/BI:H/DI:H/EX:H/EC:N/P:H` |
| Tags | `crypto` `weak-algorithm` `cwe-327` |
| Source | [`internal/sast/rules/vnx-327.rego`](https://github.com/Vulnesis/cli/blob/main/internal/sast/rules/vnx-327.rego) |

## Overview

VNX-327 maps to [CWE-327: Use of a Broken or Risky Cryptographic Algorithm](https://cwe.mitre.org/data/definitions/327.html). It reports a call into MD5 or SHA-1 when the value being hashed or produced is a security value: the call line, the three code lines above it or the next line (the next three for a Java/Kotlin `MessageDigest`, which is fed afterwards) name a password, secret, token, session id, cookie, signature, salt, nonce, CSRF value, API key, credential or reset value.

A password passed straight into the digest (`md5($pass)`, `hashlib.md5(password.encode())`, `createHash('md5').update(password)`, `DigestUtils.md5Hex(password)`, `Digest::MD5.hexdigest(password)`) is reported by [VNX-CRYPTO-007](/sast/rules/vnx-crypto-007.md), a password hashed with a fast hash, and not here, so the line is reported once with the password-hashing fix.

## Why this matters

Both algorithms are broken for collision resistance and are fast enough to brute-force billions of guesses a second, so a password hashed with them is recovered from a leaked database, and a token or signature derived from them can be forged or predicted.

## What gets flagged

```python
# FLAGGED
return hashlib.md5(f"{email}:{time.time()}".encode()).hexdigest()   # in make_reset_token
```

```javascript
// FLAGGED
const signature = CryptoJS.SHA1(secret + body).toString(CryptoJS.enc.Hex);
```

```java
// FLAGGED: the digest is fed a password below
MessageDigest md = MessageDigest.getInstance("MD5");
```

```php
// FLAGGED
$_SESSION['session_token'] = md5(uniqid());
```

```ruby
# FLAGGED
OpenSSL::Digest::SHA1.hexdigest("#{ACCESS_TOKEN_SALT}:#{id}")
```

## What is not flagged

- Digests with no security name nearby: cache keys, ETags, checksums, content addresses.
- Digests of a constant (`sha1(static::class)`, `__CLASS__`, a string literal).
- Python calls marked `usedforsecurity=False`, and HMAC-SHA1.
- Fields, enums and comments that only mention the algorithms, and test files.
- A password hashed directly (`$pass = md5($pass)`, `Digest::MD5.hexdigest(password)`): reported by [VNX-CRYPTO-007](/sast/rules/vnx-crypto-007.md).

Other MD5 and SHA-1 calls, including Go, are reported by [VNX-CRYPTO-001](/sast/rules/vnx-crypto-001.md) and [VNX-CRYPTO-002](/sast/rules/vnx-crypto-002.md).

## Remediation

1. Hash passwords with argon2id, bcrypt or scrypt.
2. Derive tokens from a CSPRNG (`secrets.token_urlsafe(32)`), and sign with HMAC-SHA256.
3. Use SHA-256 or stronger wherever a digest protects integrity.

## References

- [CWE-327: Use of a Broken or Risky Cryptographic Algorithm](https://cwe.mitre.org/data/definitions/327.html)
- [OWASP Password Storage Cheat Sheet](https://cheatsheetseries.owasp.org/cheatsheets/Password_Storage_Cheat_Sheet.html)

## 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-327
// nosec vnx-327
```

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