Security skill · Find and fix
Cryptography misuse review.
Review application code for cryptography misuse such as weak or obsolete algorithms, fast hashes for passwords, hard-coded or reused keys and nonces, unauthenticated encryption modes, predictable random values, missing certificate validation, and home-made schemes, then replace them with vetted library defaults and verify with known-answer and negative tests. Use when auditing encryption, hashing, signing, token, or key-handling code.
Facts
- Category
- Find and fix
- License
- MIT
- Tags
- Code review
- Version
- 1.0.0
- Last updated
- 2026-12-02
- Folder
crypto-misuse-review/- MCP resource
skill://crypto-misuse-review/SKILL.md- Files
- SKILL.md
- LICENSE
- references/crypto-checks.md
Original Saasment content. Saasment is in early access; this skill does not require joining it.
Install via MCP or as files
Connect your client to https://www.saasment.com/api/mcp (see client setup) and call get_skill:
{
"name": "get_skill",
"arguments": {
"slug": "crypto-misuse-review"
}
}Or download the .zip and unpack it into your agent's skills directory:
Terminal, from your project root (user-level: ~/.cursor/skills)
mkdir -p .cursor/skills
curl -fsSL https://www.saasment.com/ai-security/skills/crypto-misuse-review/download.zip -o /tmp/crypto-misuse-review.zip
unzip -o /tmp/crypto-misuse-review.zip -d .cursor/skills
# result: .cursor/skills/crypto-misuse-review/SKILL.mdReview SKILL.md before enabling a skill. Skills are instructions your agent will follow.
SKILL.md
--- name: crypto-misuse-review description: Review application code for cryptography misuse such as weak or obsolete algorithms, fast hashes for passwords, hard-coded or reused keys and nonces, unauthenticated encryption modes, predictable random values, missing certificate validation, and home-made schemes, then replace them with vetted library defaults and verify with known-answer and negative tests. Use when auditing encryption, hashing, signing, token, or key-handling code. license: MIT metadata: author: Saasment version: "1.0.0" category: both tags: "code-review" --- # Cryptography misuse review (find and fix) License: MIT. Copyright (c) 2026 Saasment. Source: https://www.saasment.com/ai-security/skills/crypto-misuse-review Most cryptographic failures in applications are not broken math. They are broken usage: the wrong primitive for the job, a key committed to the repository, a nonce used twice, a signature that is computed but never checked, or a certificate check switched off "for testing". This skill finds those patterns and replaces them with high-level library calls. It does not ask you to design cryptography; if a scheme is custom, the fix is to replace it. ## When to use - You audit code that encrypts, hashes, signs, derives keys, generates tokens, or talks over TLS. - A pull request adds a crypto library, a new token format, or changes key storage. - A scanner flagged weak algorithms or hard-coded keys. ## Safe by default - Review only code and key material you own or are authorized to review. Never copy real keys into notes, prompts, or reports; record the location only. - Do not decrypt, crack, or brute-force data or hashes that belong to other people. Use synthetic test data and test keys. - If you find a real key or secret in code, treat it as exposed, rotate it, and follow `secrets-in-repo-scan-and-rotation`. - Do not write new cryptographic constructions. Use the platform's maintained library and its high-level interfaces. - Changing how data is encrypted or hashed can make existing data unreadable. Plan a migration with backups before deploying. ## Procedure 1. **Inventory uses.** Search for every use of encryption, hashing, signing, random generation, key derivation, and TLS settings. Record purpose, algorithm, library, key source, and what data it protects. Use the search patterns in `references/crypto-checks.md`. 2. **Match primitive to purpose.** Passwords need a slow password hash. Integrity of a message between parties needs a keyed MAC or signature. Confidentiality needs authenticated encryption. Identifiers and tokens need a secure random generator. A plain fast hash is only for non-secret checksums and content addressing. 3. **Check algorithms and parameters.** Flag MD5 and SHA-1 for security purposes, DES and 3DES, RC4, ECB mode, unauthenticated CBC or CTR without a MAC, RSA with the older PKCS1 v1.5 encryption padding for new designs, short RSA keys, and small or old elliptic curves. Prefer AES-GCM or ChaCha20-Poly1305, SHA-256 or stronger, and current NIST guidance for key sizes. 4. **Check keys and secrets.** Keys come from a secret manager or KMS, not source code or images; each purpose has its own key; keys are rotatable; encryption and signing keys are not the same; derived keys use a proper KDF, not a hash of a password. 5. **Check nonces and IVs.** Unique per message under the same key (random for large nonces, counter for sequences), never a constant or all zeros, never reused with GCM or stream ciphers. 6. **Check randomness.** Tokens, session identifiers, password reset codes, API keys, and salts use the operating system's secure random source through a vetted API, never `Math.random`, `rand()`, time, or a user-id-derived seed. 7. **Check verification paths.** Signatures and MACs are verified, with a constant-time comparison, before data is used; failures abort. JWT and webhook signature checks pin the algorithm. Padding or decryption errors do not reveal which step failed. 8. **Check TLS clients.** Certificate and hostname verification are on; no `InsecureSkipVerify`, `verify=False`, or trust-all managers; minimum protocol version is set; pinning, if used, has a rotation plan. 9. **Check password handling.** Argon2id, scrypt, bcrypt, or PBKDF2 with a documented work factor, a unique salt per password, a plan to rehash on login when parameters change, and no maximum length so low that it blocks passphrases. 10. **Fix.** Replace each finding with the library's high-level API, move keys out of code, add key rotation, and plan data migration. Add tests per fix. ## Verification - Confirm a weak-algorithm finding by showing the call and the data it protects. Confirm the fix by a test that round-trips data with the new scheme and a test that data produced by the old scheme is still read during the migration window. - Confirm authenticated encryption: flip one bit in a test ciphertext and assert decryption fails with an error, not garbage output. - Confirm nonce handling: encrypt the same plaintext twice with the same key and assert the ciphertexts differ. - Confirm signature checks: alter one byte of a signed test payload and assert verification fails; use a token signed with a wrong key and with a different algorithm header and assert both are rejected. - Confirm randomness by checking the generator in code and, in tests, that two generated tokens differ and have the expected length. - Confirm TLS verification: connect a test client to a local server with a self-signed certificate and assert the connection fails unless the test trusts that certificate explicitly. - Confirm no key remains in the repository: re-run secret scanning and search history for the removed value. ## Reporting Table: id, location, purpose, current algorithm or pattern, issue, replacement, migration needed, test. List keys that must be rotated and who owns them. ## References - OWASP Cryptographic Storage Cheat Sheet: https://cheatsheetseries.owasp.org/cheatsheets/Cryptographic_Storage_Cheat_Sheet.html - OWASP Password Storage Cheat Sheet: https://cheatsheetseries.owasp.org/cheatsheets/Password_Storage_Cheat_Sheet.html - NIST cryptographic standards and guidelines: https://csrc.nist.gov/projects/cryptographic-standards-and-guidelines - CWE-327 (broken or risky algorithm): https://cwe.mitre.org/data/definitions/327.html - Companion skills: `auth-session-review`, `secrets-in-repo-scan-and-rotation`, `secure-code-review-checklist`.
Helper files
LICENSE
MIT License Copyright (c) 2026 Saasment Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
references/crypto-checks.md
# Cryptography search patterns and choices
License: MIT. Copyright (c) 2026 Saasment.
Search leads only. Read each hit to learn what the code protects before calling it a finding.
## Search commands
```bash
# Obsolete or weak primitives
rg -n -i 'md5|sha-?1\b|\bdes\b|3des|rc4|ecb|blowfish' --glob '!*.lock' --glob '!node_modules'
# Hard-coded keys, IVs, and salts
rg -n -i '(secret|key|iv|salt|nonce)\w*\s*[:=]\s*["'"'"'][A-Za-z0-9+/=_-]{8,}' --glob '*.{js,ts,py,go,java,kt,rb,php,cs,yaml,yml,json,env}'
# Non-cryptographic random numbers
rg -n 'Math\.random|\brand\(|random\.(random|randint|choice)|java\.util\.Random|math/rand|new Random\('
# Disabled certificate checks
rg -n -i 'InsecureSkipVerify|verify\s*=\s*False|rejectUnauthorized\s*:\s*false|TrustAll|ALLOW_ALL_HOSTNAME|CERT_NONE'
# Home-made schemes (look for XOR loops and manual padding)
rg -n -i 'xor|custom.*(encrypt|cipher)|base64.*(secret|password)'
```
## Choose the primitive by purpose
| Purpose | Use | Avoid |
| --- | --- | --- |
| Store a password | Argon2id, scrypt, bcrypt, or PBKDF2 with a high work factor and a per-password salt | Plain or fast hashes, reversible encryption |
| Encrypt data at rest or in a message | Authenticated encryption (AES-GCM, ChaCha20-Poly1305) through a high-level library API | ECB, unauthenticated CBC or CTR, custom ciphers |
| Prove a message came from a holder of a shared secret | HMAC with SHA-256 or stronger | Hash of secret plus message, unkeyed hashes |
| Prove a message came from a key holder to many verifiers | Digital signature (Ed25519, ECDSA P-256, RSA-PSS) | Reusing encryption keys as signing keys |
| Generate a token or identifier | OS secure random, at least 128 bits for secrets | Time, counters, user ids, non-secure PRNGs |
| Derive a key from a secret | HKDF (from a high-entropy secret) or a password KDF (from a password) | A single hash round |
| Protect data in transit | TLS with verification on and a minimum version | Custom protocols, disabled verification |
| Compare secrets or MACs | Constant-time comparison from the standard library | `==` on strings |
## Patterns
```python
# Risky: fast hash, no salt
digest = hashlib.sha256(password.encode()).hexdigest()
# Safer: a password hashing library's high-level call (any of the approved algorithms)
hashed = password_hasher.hash(password)
password_hasher.verify(hashed, candidate)
```
```javascript
// Risky: fixed IV and no authentication
const cipher = crypto.createCipheriv("aes-256-cbc", key, Buffer.alloc(16));
// Safer: authenticated encryption with a fresh random nonce per message
const iv = crypto.randomBytes(12);
const cipher = crypto.createCipheriv("aes-256-gcm", key, iv);
const ciphertext = Buffer.concat([cipher.update(plaintext), cipher.final()]);
const tag = cipher.getAuthTag(); // store iv, ciphertext, and tag together
```
```go
// Risky: signature computed but result ignored
mac.Write(body)
_ = mac.Sum(nil)
// Safer: compare in constant time and reject on mismatch
if !hmac.Equal(mac.Sum(nil), providedMAC) {
return errBadSignature
}
```
## Migration notes
- Hash upgrades: keep the old verifier, rehash with the new algorithm on successful login, and track how many records remain on the old scheme.
- Cipher changes: store a version byte or prefix with each ciphertext so old and new data can both be read during the migration.
- Key rotation: encrypt new data with the new key, keep old keys available for decryption until re-encryption is done, then retire them.
Related
Companion skills
Questions
How do I install the Cryptography misuse review skill?
Download https://www.saasment.com/ai-security/skills/crypto-misuse-review/download.zip and unzip it into your agent's skills directory (for example .cursor/skills, .claude/skills, .agents/skills, or .github/skills) so that crypto-misuse-review/SKILL.md exists. Or connect to https://www.saasment.com/api/mcp and call the get_skill tool with the slug crypto-misuse-review.
What license is the Cryptography misuse review skill under?
It is original Saasment content under the MIT license, stated in the SKILL.md frontmatter and in the LICENSE file in the skill folder.
Is it safe to run this skill?
A skill is a set of instructions your agent follows, so read SKILL.md first. It tells the agent to test only systems you own or are authorized to test, to use test environments and synthetic data, and to avoid destructive probes. Downloading it does not run any code on your machine.