SKY-D207 · Security in code
Weak MD5 hash
MD5 is an old hash function. Collisions (two inputs with the same hash) can be made on a laptop, and its speed makes guessing the input cheap. SKY-D207 reports code that computes an MD5 hash.
- Languages
- Python, TypeScript/JavaScript, Go, Java, Rust
- Quality gate
- counted toward the gate limits (full and diff scans). Low-risk MD5 findings that the terminal list leaves out are still in the JSON output and still count toward
max_security. - Finding type
- review
- Go engine ID
- SKY-G207, reported as SKY-D207
Why it matters
Password or token hashes stored as MD5 fall quickly to a cracking rig if the table leaks, and an MD5 signature or fingerprint can be matched by a forged file. The fix is usually a one-line change of algorithm.
What Skylos flags
import hashlib def store_password(db, username: str, password: str) -> None: digest = hashlib.md5(password.encode()).hexdigest() db.execute( "UPDATE users SET password_hash = ? WHERE username = ?", (digest, username), )What Skylos leaves alone
import hashlib def etag_for(body: bytes) -> str: return hashlib.md5(body, usedforsecurity=False).hexdigest()Why Skylos leaves it alone
usedforsecurity=False states that the hash is a cache key, not a security check, and FIPS builds of Python enforce that. Skylos skips any hashlib.md5() call that passes the literal False there.
More languages
TypeScript
Flagged
import crypto from "node:crypto"; export function storeResetToken(db: Db, userId: string, resetToken: string) { const tokenHash = crypto.createHash("md5").update(resetToken).digest("hex"); return db.resetTokens.insert({ userId, tokenHash });}Not flagged
import crypto from "node:crypto"; export function storeResetToken(db: Db, userId: string, resetToken: string) { const tokenHash = crypto.createHash("sha256").update(resetToken).digest("hex"); return db.resetTokens.insert({ userId, tokenHash });}Why Skylos leaves it alone
Only the literal algorithm names "md5" and "sha1" are reported. SHA-256 over a random reset token is a sound way to store it.
Java
Flagged
package com.example; import java.security.MessageDigest; public class TokenHashes { public static byte[] hash(String token) throws Exception { MessageDigest md = MessageDigest.getInstance("MD5"); return md.digest(token.getBytes("UTF-8")); }}Not flagged
package com.example; import java.security.MessageDigest; public class TokenHashes { public static byte[] hash(String token) throws Exception { MessageDigest md = MessageDigest.getInstance("SHA-256"); return md.digest(token.getBytes("UTF-8")); }}Why Skylos leaves it alone
The algorithm string is SHA-256. Java is checked by the literal name passed to getInstance(), or by the constant a variable holds when it is passed to MessageDigest.getInstance().
How Skylos decides
- In Rust the input must be exposed SecretString contents or its bytes. Skylos resolves the MD5 API from the md5 crate or OpenSSL.
- Runs with
--danger. In Python it finds calls tohashlib.md5(), includingfrom hashlib import md5and other import aliases, andhashlib.new("md5", …)with a literal algorithm name. - Skips a Python call that passes
usedforsecurity=Falseas a literal. Test files are not skipped. - Looks at what is hashed: the data argument, values assigned to those names earlier in the same function, and
.update()arguments on the hash object. When none of these names looks like a credential, identity or certificate (words such aspassword,token,secret,api_key,user_id,session_id,cert), the finding is marked low-risk: it is left out of the terminal list unless you pass--all-advice, but stays in JSON and counts for the gate. Names containinghash,digest,url,pathorfilenever count as sensitive. When the data cannot be read from the call, the finding stays listed. - In TypeScript and JavaScript it reports
<object>.createHash("md5")with a literal string. The same low-risk mark applies when the hash is chained into.update(x)and the names inx(one step back through aconst) are not sensitive. - In Go every call to
md5.Newormd5.Sumfromcrypto/md5is reported (by the Go engine as SKY-G207, shown as SKY-D207), with no low-risk mark. - In Java it reports any
getInstance("MD5")call with that literal string, andMessageDigest.getInstance(name)whennameis a constant holdingMD5. A literal"DES"passed togetInstance()is reported here as well, as HIGH.
How to fix it
For passwords use a slow password hash with a random salt: scrypt from the standard library, or argon2/bcrypt from a package. For tokens, signatures and fingerprints use SHA-256 or stronger. Where MD5 is only a checksum or cache key, keep it and pass usedforsecurity=False.
import hashlibAdded: import os def store_password(db, username: str, password: str) -> None:Removed: digest = hashlib.md5(password.encode()).hexdigest()Added: salt = os.urandom(16)Added: digest = hashlib.scrypt(password.encode(), salt=salt, n=2**14, r=8, p=1) db.execute(Removed: "UPDATE users SET password_hash = ? WHERE username = ?",Removed: (digest, username),Added: "UPDATE users SET password_hash = ?, password_salt = ? WHERE username = ?",Added: (digest.hex(), salt.hex(), username), )When it can be wrong
- MD5 used as a checksum, ETag or cache key is reported. When the hashed names are not sensitive the finding is only hidden from the terminal list; it still counts for the gate. Add
usedforsecurity=Falsein Python to remove it. - Sensitivity is judged by names only: MD5 over a variable called
datathat holds a password is marked low-risk, and MD5 over auser_idused to pick an A/B bucket stays listed. - Go reports every
md5.New/md5.Sum, including theContent-MD5checksums some storage APIs require. - Missed: in TypeScript,
createHash("md5")imported by name fromnode:crypto(not called on an object) and an algorithm held in a variable.
Seeing a case that isn't listed here? Report the wrong result so the rule can be fixed. Don't paste company code: describe the shape of it.
How to silence it
Mark a reviewed line. For Python checksums,
usedforsecurity=Falseis the better fix because it also documents the intent.Python digest = hashlib.md5(blob).hexdigest() # skylos: ignore[SKY-D207] S3 Content-MD5Accept the findings you already have with
skylos baseline ., then scan with--baselineso only new ones are listed.[tool.skylos] ignore = ["SKY-D207"]turns the rule off for the whole project.