# Use of a Broken or Risky Cryptographic Algorithm (CWE-327) The product uses a broken or risky cryptographic algorithm or protocol. **Stack:** JavaScript - Prevalence: उच्च बार-बार शोषित - Impact: उच्च 3 उच्च गंभीरता वाले नियम - Prevention: प्रलेखित 4 फिक्स उदाहरण **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 2 Shoulder डिटेक्शन नियमों पर आधारित Broken Cryptographic Algorithm के लिए रोकथाम रणनीतियाँ। ### 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 - एप्लिकेशन डेटा पढ़ना - सुरक्षा तंत्र को बायपास करना ## Mitigations - सममित एनक्रिप्शन के लिए AES-256 का उपयोग करें - असममित एनक्रिप्शन के लिए RSA-2048+ या ECDSA का उपयोग करें - हैशिंग के लिए SHA-256 या SHA-3 का उपयोग करें ## 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