# VNX-759: Password hashed with a one-way hash and no salt

A password is passed straight into a fast general-purpose digest with no salt.

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

## Overview

VNX-759 maps to [CWE-759: Use of a One-Way Hash without a Salt](https://cwe.mitre.org/data/definitions/759.html). It reports a fast general-purpose digest whose input is a password (an argument named `password`, `passwd`, `pwd`, `$pass`, `getPassword()` and similar, or a variable assigned from one a few lines above) with no salt or pepper mixed into the same digest: Python `hashlib.*` and `h.update(password)`, Java `MessageDigest.digest/update`, `DigestUtils.*Hex` and Guava `Hashing.*().hashString`, PHP `md5()`, `sha1()`, `crc32()` and `hash('<alg>', ...)`, and Node `crypto.createHash(...).update(password)`.

It does not report salted digests, password KDFs (`pbkdf2_hmac`, `scrypt`, bcrypt, Argon2, `PBEKeySpec`, `password_hash`), HMAC, or digests of tokens, nonces, reset values and file contents.

A password passed straight into a fast digest call (`md5($pass)`, `hashlib.sha256(password.encode())`, `createHash('sha256').update(password)`) is reported by [VNX-CRYPTO-007](/sast/rules/vnx-crypto-007.md), whose fix is the same salted password KDF, so the line is reported once. This rule keeps what that rule does not read: a password reached through a variable assigned a few lines above, a request field, or a hasher fed on a later line.

## Why this matters

Without a salt, two users with the same password get the same hash, and a single precomputed (rainbow) table reverses every hash in a leaked table at once. Fast digests also let an attacker try billions of guesses per second.

## What gets flagged

```python
cred = request.form["new_password"]
user.password_digest = hashlib.sha256(cred.encode()).hexdigest()       # flagged
```

```java
MessageDigest md = MessageDigest.getInstance("SHA-256");
return md.digest(password.getBytes(StandardCharsets.UTF_8));            // flagged
```

```javascript
const h = crypto.createHash('sha256');
h.update(password);                                                     // flagged
```

Reported by VNX-CRYPTO-007 instead: `$pass = md5($pass);`, `hashlib.sha256(password.encode())`, `crypto.createHash('sha256').update(password)`.

## Remediation

1. Hash passwords with a password KDF that salts for you: bcrypt, scrypt, Argon2id or PBKDF2 with a high iteration count (`password_hash()` in PHP, `BCryptPasswordEncoder` in Spring).
2. Migrate existing hashes on the next successful login.

## References

- [CWE-759: Use of a One-Way Hash without a Salt](https://cwe.mitre.org/data/definitions/759.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-759
// nosec vnx-759
```

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