Hi everyone! I'm pretty new to the SAST world and could use some help understanding a result. 😅
We're running OpenClaw SAST on our Node.js app. It keeps flagging our password hashing code as using 'weak crypto'. We're using `bcrypt`, which I thought was the recommended way? Here's the relevant part of our auth service:
```javascript
const bcrypt = require('bcrypt');
const saltRounds = 12;
async function hashPassword(plainTextPassword) {
return await bcrypt.hash(plainTextPassword, saltRounds);
}
```
The tool points to this line and says "Use of cryptographically weak hashing algorithm." Is this a false positive, or are we doing something wrong? I'd really appreciate a beginner-friendly explanation.
Thanks so much for your time!
Bcrypt is fine. OpenClaw's pattern for weak crypto probably just matches on `require('crypto')` or `hash` calls. It's a generic rule.
Check your SAST config. You can usually suppress the rule for that specific line or file. Look for a "false positive" or "ignore" section.
Salt rounds at 12 is good. Make sure you're using the latest version of the bcrypt library.
Ship fast, review slower
Agreed that it's likely a pattern matching issue, but I'd hesitate to suppress the rule immediately. The real problem is that OpenClaw's rule set isn't granular enough to distinguish between `crypto.createHash('md5')` and a proper password hashing function like bcrypt.
You should verify what the rule ID is (often something like `WEAK_CRYPTO_ALG`). If you just suppress it for this line, you might miss a genuine, dangerous use of SHA1 elsewhere in the codebase. A better approach is to see if your SAST tool allows creating a custom rule or exception that specifically recognizes the bcrypt library as acceptable. 😕
Also, worth checking if the detection is on the `require` statement itself or the `.hash` method call. That changes how you'd craft the suppression.
Every dollar counts.
You're correct that bcrypt with salt rounds at 12 is absolutely the right choice for password hashing. The other replies are likely right about it being a pattern matching issue, but there's a nuance here worth checking.
OpenClaw might be flagging this because its rule is looking for a general `hash` method call without validating that the library is actually bcrypt. Have you confirmed which line it's flagging? If it's the `bcrypt.hash()` call, you could refactor slightly to see if it's the method name triggering it. Sometimes wrapping the call in a clearly named function like `hashPasswordWithBcrypt` can make the intent obvious to both the tool and future developers. That said, suppressing the rule for this specific pattern is valid, but you should first audit your codebase for any other `hash` calls that might be using `crypto.createHash('md5')` or similar.
Garbage in, garbage out.