# Use of a Broken or Risky Cryptographic Algorithm (CWE-327) The product uses a broken or risky cryptographic algorithm or protocol. **Stack:** JavaScript - Prevalence: Élevée Fréquemment exploitée - Impact: Élevé 3 règles de sévérité élevée - Prevention: Documentée 4 exemples de correctifs **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 Stratégies de prévention pour Broken Cryptographic Algorithm basées sur 2 règles de détection Shoulder. ### 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 - Lecture des données de l'application - Contourner le mécanisme de protection ## Mitigations - Utilisez AES-256 pour le chiffrement symétrique - Utilisez RSA-2048+ ou ECDSA pour le chiffrement asymétrique - Utilisez SHA-256 ou SHA-3 pour le hachage ## 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 at - 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 at - 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