Cryptography rules
encryption-secure-mode
Section titled “encryption-secure-mode”Finds crypto.createCipheriv calls whose algorithm uses the CBC or ECB mode, or names a block cipher without a mode, also when a constant holds the algorithm.
On in the recommended and all configs.
ECB shows the patterns of the data. CBC without a message check lets attackers change or decrypt the data through padding errors.
What to do
Section titled “What to do”Use a mode that authenticates the data, such as GCM: aes-256-gcm.
Example
Section titled “Example”The call crypto.createCipheriv("aes-128-cbc", key, iv) reports insecure. Use crypto.createCipheriv("aes-128-gcm", key, iv).
hardcoded-secret-signatures
Section titled “hardcoded-secret-signatures”Finds a string written in the code that a call passes as a secret, such as the key of crypto.createHmac or jsonwebtoken.sign, the secret of express-session, or a database password, except short values and placeholders.
On in the recommended and all configs.
A secret in the code reaches everyone who can read the repository or the built files, so it protects nothing.
What to do
Section titled “What to do”Revoke the secret, and read its replacement from the environment or a secret store at run time.
Example
Section titled “Example”The call jwt.sign(claims, "s3cr3t") reports hardcoded. Use jwt.sign(claims, process.env.JWT_SECRET).
insecure-jwt-token
Section titled “insecure-jwt-token”Finds jsonwebtoken calls that sign a token with the none algorithm, verify a token with none among the algorithms, or verify a token with a null key and no algorithms option.
On in the recommended and all configs.
A token without a signature proves nothing, so anyone can forge it.
What to do
Section titled “What to do”Sign with a strong algorithm such as RS256 or HS256, and list only strong algorithms in the algorithms option of verify.
Example
Section titled “Example”The call jwt.sign(claims, key, { algorithm: "none" }) reports unsignedSign. Pass { algorithm: "RS256" }.
no-insecure-random
Section titled “no-insecure-random”Reports Math.random calls, including aliases and destructured references.
On in the recommended and all configs.
Predictable random values cannot protect tokens, identifiers, or other security decisions.
What to do
Section titled “What to do”Use crypto.getRandomValues, crypto.randomUUID, or the cryptographic random API of the runtime.
Example
Section titled “Example”const token = crypto.randomUUID(); uses cryptographic randomness for an identifier.
no-weak-cipher
Section titled “no-weak-cipher”Finds crypto.createCipheriv calls whose algorithm is Blowfish, DES, RC2, or RC4, also when a constant holds the algorithm.
On in the recommended and all configs.
Attackers can break these ciphers, so the data that they encrypt is not protected.
What to do
Section titled “What to do”Use AES with a mode that authenticates the data, such as aes-256-gcm.
Example
Section titled “Example”The call crypto.createCipheriv("des-ede3-cbc", key, iv) reports weak. Use crypto.createCipheriv("aes-256-gcm", key, iv).
no-weak-hashing
Section titled “no-weak-hashing”Finds crypto.createHash calls with MD5, SHA-1, RIPEMD, or another weak algorithm, and crypto.subtle.digest calls with SHA-1. A digest that the code only shortens with slice or substring passes, because a short digest serves as an identifier, not as a protection.
On in the recommended and all configs.
Attackers can find two inputs with the same weak hash, so the hash does not protect passwords, signatures, or file integrity.
What to do
Section titled “What to do”Use SHA-256 or a stronger hash. Store passwords with a password hash such as scrypt or Argon2.
Example
Section titled “Example”The call crypto.createHash("md5").update(password).digest("hex") reports weak. Use crypto.createHash("sha256").
no-weak-keys
Section titled “no-weak-keys”Finds generateKeyPair and generateKeyPairSync calls that make an RSA or DSA key with a modulus shorter than 2048 bits or a divisor shorter than 224 bits, or an elliptic curve key on a weak curve.
On in the recommended and all configs.
Attackers can break short keys and weak curves, so the signatures and the encryption that use them protect nothing.
What to do
Section titled “What to do”Use a modulus of at least 2048 bits, a divisor of at least 224 bits, and a curve such as prime256v1 or secp384r1.
Example
Section titled “Example”The call crypto.generateKeyPairSync("rsa", { modulusLength: 1024 }) reports shortKey. Pass { modulusLength: 2048 }.
review-blockchain-mnemonic
Section titled “review-blockchain-mnemonic”In a file that imports ethers, viem/accounts, or tronweb, finds fromPhrase, mnemonicToAccount, and fromMnemonic calls whose seed phrase is a string written in the code.
On in the recommended and all configs.
A seed phrase gives full control of a wallet, so everyone who reads the code can take its funds.
What to do
Section titled “What to do”Move the funds to a new wallet, and read the new seed phrase from a secret store at run time.
Example
Section titled “Example”The call Wallet.fromPhrase("test test test ...") reports mnemonic. Use Wallet.fromPhrase(process.env.WALLET_PHRASE).