# Use of a Broken or Risky Cryptographic Algorithm (CWE-327) The product uses a broken or risky cryptographic algorithm or protocol. **Stack:** JavaScript - Prevalence: High Frequently exploited - Impact: High 3 high-severity rules - Prevention: Documented 4 fix examples **OWASP:** Cryptographic Failures (A02:2021-Cryptographic Failures) - #2 ## Description Cryptographic algorithms are the backbone of modern information security. Using algorithms that have known weaknesses, such as MD5 or DES, can make it trivial for attackers to defeat the protection. ## Prevention Prevention strategies for Broken Cryptographic Algorithm based on 2 Shoulder detection rules. ### JavaScript Always specify allowed algorithms when verifying JWT tokens Use SHA-256+ for hashing, AES-256-GCM for encryption, and bcrypt for passwords ## Warning Signs - [HIGH] jwt.verify() without algorithm specification allows 'none' algorithm attack - [HIGH] JWT verification without explicit algorithm specification, allowing "none" algorithm attacks that by - [HIGH] use of weak or broken cryptographic algorithms for hashing passwords or sensitive data ## Consequences - Read Application Data - Bypass Protection Mechanism ## Mitigations - Use AES-256 for symmetric encryption - Use RSA-2048+ or ECDSA for asymmetric encryption - Use SHA-256 or SHA-3 for hashing ## Detection - Total rules: 4 - Languages: go, javascript, typescript, python ## Rules by Language ### Javascript (2 rules) - **JWT Algorithm Confusion Attack** [HIGH]: Detects JWT verification without explicit algorithm specification, allowing "none" algorithm attacks that bypass authentication. - Remediation: Always specify allowed algorithms when verifying JWT tokens. Example: jwt.verify(token, secret, { algorithms: ['RS256'] }) - **Use of Weak Cryptographic Algorithm** [HIGH]: Detects use of weak or broken cryptographic algorithms for hashing passwords or sensitive data. **Weak algorithms detected:** - **MD5**: Cryptographically broken, vulnerable to collision attacks - **SHA1**: Deprecated, vulnerable to collision attacks - **DES/3DES**: Weak block cipher with small key size - **RC4**: Stream cipher with known vulnerabilities **Impact:** - Password hashes can be cracked using rainbow tables or brute force - Data encrypted with weak algorithms can be decrypted by attackers - Integrity of hashed data cannot be guaranteed **For password hashing**, use: - bcrypt (recommended) - scrypt - argon2 - PBKDF2 with strong parameters **For general hashing**, use: - SHA-256 or SHA-512 (for non-password data) - SHA-3 for future-proofing **For encryption**, use: - AES-256-GCM - ChaCha20-Poly1305 - Remediation: Use bcrypt/argon2 for passwords, SHA-256+ for hashing, and AES-256-GCM for encryption. ```javascript const bcrypt = require('bcrypt'); const hash = await bcrypt.hash(password, 12); ``` Learn more: https://shoulder.dev/learn/javascript/cwe-327/weak-crypto-algorithm ### Typescript (2 rules) - **JWT Algorithm Confusion Attack** [HIGH]: Detects JWT verification without explicit algorithm specification, allowing "none" algorithm attacks that bypass authentication. - Remediation: Always specify allowed algorithms when verifying JWT tokens. Example: jwt.verify(token, secret, { algorithms: ['RS256'] }) - **Use of Weak Cryptographic Algorithm** [HIGH]: Detects use of weak or broken cryptographic algorithms for hashing passwords or sensitive data. **Weak algorithms detected:** - **MD5**: Cryptographically broken, vulnerable to collision attacks - **SHA1**: Deprecated, vulnerable to collision attacks - **DES/3DES**: Weak block cipher with small key size - **RC4**: Stream cipher with known vulnerabilities **Impact:** - Password hashes can be cracked using rainbow tables or brute force - Data encrypted with weak algorithms can be decrypted by attackers - Integrity of hashed data cannot be guaranteed **For password hashing**, use: - bcrypt (recommended) - scrypt - argon2 - PBKDF2 with strong parameters **For general hashing**, use: - SHA-256 or SHA-512 (for non-password data) - SHA-3 for future-proofing **For encryption**, use: - AES-256-GCM - ChaCha20-Poly1305 - Remediation: Use bcrypt/argon2 for passwords, SHA-256+ for hashing, and AES-256-GCM for encryption. ```javascript const bcrypt = require('bcrypt'); const hash = await bcrypt.hash(password, 12); ``` Learn more: https://shoulder.dev/learn/javascript/cwe-327/weak-crypto-algorithm