

Also from Kynth Studios


Also from Kynth Studios


Also from Kynth Studios
12345# JavaScript Cryptographic Failures (OWASP A02:2021)67<rule>8name: javascript_cryptographic_failures9description: Detect and prevent cryptographic failures in JavaScript applications as defined in OWASP Top 10:2021-A021011actions:12 - type: enforce13 conditions:14 # Pattern 1: Weak or insecure cryptographic algorithms15 - pattern: "(?:createHash|crypto\\.createHash)\\(['\"](?:md5|sha1)['\"]\\)|(?:crypto|require\\(['\"]crypto['\"]\\))\\.(?:createHash|Hash)\\(['\"](?:md5|sha1)['\"]\\)|new (?:MD5|SHA1)\\(|CryptoJS\\.(?:MD5|SHA1)\\("16 message: "Using weak hashing algorithms (MD5/SHA1). Use SHA-256 or stronger algorithms."1718 # Pattern 2: Hardcoded secrets/credentials19 - pattern: "(?:const|let|var)\\s+(?:password|secret|key|token|auth|apiKey|api_key)\\s*=\\s*['\"][^'\"]+['\"]"20 message: "Potential hardcoded credentials detected. Store secrets in environment variables or a secure vault."2122 # Pattern 3: Insecure random number generation23 - pattern: "Math\\.random\\(\\)|Math\\.floor\\(\\s*Math\\.random\\(\\)\\s*\\*"24 message: "Using Math.random() for security purposes. Use crypto.randomBytes() or Web Crypto API for cryptographic operations."2526 # Pattern 4: Weak SSL/TLS configuration27 - pattern: "(?:tls|https|require\\(['\"]https['\"]\\)|require\\(['\"]tls['\"]\\))\\.(?:createServer|request|get)\\([^\\)]*?{[^}]*?secureProtocol\\s*:\\s*['\"](?:SSLv2_method|SSLv3_method|TLSv1_method|TLSv1_1_method)['\"]"28 message: "Using deprecated/insecure SSL/TLS protocol versions. Use TLS 1.2+ for secure communications."2930 # Pattern 5: Missing certificate validation31 - pattern: "(?:rejectUnauthorized|strictSSL)\\s*:\\s*false"32 message: "SSL certificate validation is disabled. Always validate certificates in production environments."3334 # Pattern 6: Insecure cipher usage35 - pattern: "(?:createCipheriv|crypto\\.createCipheriv)\\(['\"](?:des|des3|rc4|bf|blowfish|aes-\\d+-ecb)['\"]"36 message: "Using insecure encryption cipher or mode. Use AES with GCM or CBC mode with proper padding."3738 # Pattern 7: Insufficient key length39 - pattern: "(?:generateKeyPair|generateKeyPairSync)\\([^,]*?['\"]rsa['\"][^,]*?{[^}]*?modulusLength\\s*:\\s*(\\d{1,3}|1[0-9]{3}|20[0-3][0-9]|204[0-7])\\s*}"40 message: "Using insufficient key length for asymmetric encryption. RSA keys should be at least 2048 bits, preferably 4096 bits."4142 # Pattern 8: Insecure password hashing43 - pattern: "(?:createHash|crypto\\.createHash)\\([^)]*?\\)\\.(?:update|digest)\\([^)]*?\\)|CryptoJS\\.(?:SHA256|SHA512|SHA3)\\([^)]*?\\)"44 negative_pattern: "(?:bcrypt|scrypt|pbkdf2|argon2)"45 message: "Using plain hashing for passwords. Use dedicated password hashing functions like bcrypt, scrypt, or PBKDF2."4647 # Pattern 9: Missing salt in password hashing48 - pattern: "(?:pbkdf2|pbkdf2Sync)\\([^,]+,[^,]+,[^,]+,\\s*\\d+\\s*,[^,]+\\)"49 negative_pattern: "(?:salt|crypto\\.randomBytes)"50 message: "Ensure you're using a proper random salt with password hashing functions."5152 # Pattern 10: Insecure cookie settings53 - pattern: "(?:document\\.cookie|cookies\\.set|res\\.cookie|cookie\\.serialize)\\([^)]*?\\)"54 negative_pattern: "(?:secure\\s*:|httpOnly\\s*:|sameSite\\s*:)"55 message: "Cookies with sensitive data should have secure and httpOnly flags enabled."5657 # Pattern 11: Client-side encryption58 - pattern: "(?:encrypt|decrypt|createCipher|createDecipher)\\([^)]*?\\)"59 location: "(?:frontend|client|browser|react|vue|angular)"60 message: "Performing sensitive cryptographic operations on the client side. Move encryption/decryption logic to the server."6162 # Pattern 12: Insecure JWT implementation63 - pattern: "(?:jwt\\.sign|jsonwebtoken\\.sign)\\([^,]*?,[^,]*?,[^\\)]*?\\)"64 negative_pattern: "(?:expiresIn|algorithm\\s*:\\s*['\"](?:HS256|HS384|HS512|RS256|RS384|RS512|ES256|ES384|ES512)['\"])"65 message: "JWT implementation missing expiration or using weak algorithm. Set expiresIn and use a strong algorithm."6667 # Pattern 13: Weak PRNG in Node.js68 - pattern: "(?:crypto\\.pseudoRandomBytes|crypto\\.rng|crypto\\.randomInt)\\("69 message: "Using potentially weak pseudorandom number generator. Use crypto.randomBytes() for cryptographic security."7071 # Pattern 14: Insecure local storage usage for sensitive data72 - pattern: "(?:localStorage\\.setItem|sessionStorage\\.setItem)\\(['\"](?:token|auth|jwt|password|secret|key|credential)['\"]"73 message: "Storing sensitive data in browser storage. Use secure HttpOnly cookies for authentication tokens."7475 # Pattern 15: Weak password validation76 - pattern: "(?:password\\.length\\s*>=?\\s*\\d|password\\.match\\(['\"][^'\"]+['\"]\\))"77 negative_pattern: "(?:password\\.length\\s*>=?\\s*(?:8|9|10|11|12)|[A-Z]|[a-z]|[0-9]|[^A-Za-z0-9])"78 message: "Weak password validation. Require at least 12 characters with a mix of uppercase, lowercase, numbers, and special characters."7980 - type: suggest81 message: |82 **JavaScript Cryptography Best Practices:**8384 1. **Secure Password Storage:**85 - Use dedicated password hashing algorithms:86```javascript87 // Node.js with bcrypt88 const bcrypt = require('bcrypt');89 const saltRounds = 12;90 const hashedPassword = await bcrypt.hash(password, saltRounds);9192 // Verify password93 const match = await bcrypt.compare(password, hashedPassword);94```95 - Or use Argon2 (preferred) or PBKDF2 with sufficient iterations:96```javascript97 // Node.js with crypto98 const crypto = require('crypto');99100 function hashPassword(password) {101 const salt = crypto.randomBytes(16);102 const hash = crypto.pbkdf2Sync(password, salt, 310000, 32, 'sha256');103 return { salt: salt.toString('hex'), hash: hash.toString('hex') };104 }105```106107 2. **Secure Random Number Generation:**108 - In Node.js:109```javascript110 const crypto = require('crypto');111 const randomBytes = crypto.randomBytes(32); // 256 bits of randomness112```113 - In browsers:114```javascript115 const array = new Uint8Array(32);116 window.crypto.getRandomValues(array);117```118119 3. **Secure Communications:**120 - Use TLS 1.2+ for all communications:121```javascript122 // Node.js HTTPS server123 const https = require('https');124 const fs = require('fs');125126 const options = {127 key: fs.readFileSync('private-key.pem'),128 cert: fs.readFileSync('certificate.pem'),129 minVersion: 'TLSv1.2'130 };131132 https.createServer(options, (req, res) => {133 res.writeHead(200);134 res.end('Hello, world!');135 }).listen(443);136```137 - Always validate certificates:138```javascript139 // Node.js HTTPS request140 const https = require('https');141142 const options = {143 hostname: 'example.com',144 port: 443,145 path: '/',146 method: 'GET',147 rejectUnauthorized: true // Default, but explicitly set for clarity148 };149150 const req = https.request(options, (res) => {151 // Handle response152 });153```154155 4. **Proper Key Management:**156 - Never hardcode secrets in source code157 - Use environment variables or secure vaults:158```javascript159 // Node.js with dotenv160 require('dotenv').config();161 const apiKey = process.env.API_KEY;162```163 - Consider using dedicated key management services164165 5. **Secure Encryption:**166 - Use authenticated encryption (AES-GCM):167```javascript168 // Node.js crypto169 const crypto = require('crypto');170171 function encrypt(text, masterKey) {172 const iv = crypto.randomBytes(12);173 const cipher = crypto.createCipheriv('aes-256-gcm', masterKey, iv);174175 let encrypted = cipher.update(text, 'utf8', 'hex');176 encrypted += cipher.final('hex');177178 const authTag = cipher.getAuthTag().toString('hex');179180 return {181 iv: iv.toString('hex'),182 encrypted,183 authTag184 };185 }186187 function decrypt(encrypted, masterKey) {188 const decipher = crypto.createDecipheriv(189 'aes-256-gcm',190 masterKey,191 Buffer.from(encrypted.iv, 'hex')192 );193194 decipher.setAuthTag(Buffer.from(encrypted.authTag, 'hex'));195196 let decrypted = decipher.update(encrypted.encrypted, 'hex', 'utf8');197 decrypted += decipher.final('utf8');198199 return decrypted;200 }201```202203 6. **Secure Cookie Handling:**204 - Set secure and httpOnly flags:205```javascript206 // Express.js207 res.cookie('session', sessionId, {208 httpOnly: true,209 secure: true,210 sameSite: 'strict',211 maxAge: 3600000 // 1 hour212 });213```214215 7. **JWT Security:**216 - Use strong algorithms and set expiration:217```javascript218 // Node.js with jsonwebtoken219 const jwt = require('jsonwebtoken');220221 const token = jwt.sign(222 { userId: user.id },223 process.env.JWT_SECRET,224 {225 expiresIn: '1h',226 algorithm: 'HS256'227 }228 );229```230 - Validate tokens properly:231```javascript232 try {233 const decoded = jwt.verify(token, process.env.JWT_SECRET);234 // Process request with decoded data235 } catch (err) {236 // Handle invalid token237 }238```239240 8. **Constant-Time Comparison:**241 - Use crypto.timingSafeEqual for comparing secrets:242```javascript243 const crypto = require('crypto');244245 function safeCompare(a, b) {246 const bufA = Buffer.from(a);247 const bufB = Buffer.from(b);248249 // Ensure the buffers are the same length to avoid timing attacks250 // based on length differences251 if (bufA.length !== bufB.length) {252 return false;253 }254255 return crypto.timingSafeEqual(bufA, bufB);256 }257```258259 - type: validate260 conditions:261 # Check 1: Proper password hashing262 - pattern: "bcrypt\\.hash|scrypt|pbkdf2|argon2"263 message: "Using secure password hashing algorithm."264265 # Check 2: Secure random generation266 - pattern: "crypto\\.randomBytes|window\\.crypto\\.getRandomValues"267 message: "Using cryptographically secure random number generation."268269 # Check 3: Strong TLS configuration270 - pattern: "minVersion\\s*:\\s*['\"]TLSv1_2['\"]|minVersion\\s*:\\s*['\"]TLSv1_3['\"]"271 message: "Using secure TLS configuration."272273 # Check 4: Proper certificate validation274 - pattern: "rejectUnauthorized\\s*:\\s*true|strictSSL\\s*:\\s*true"275 message: "Properly validating SSL certificates."276277metadata:278 priority: high279 version: 1.0280 tags:281 - security282 - javascript283 - nodejs284 - browser285 - cryptography286 - encryption287 - owasp288 - language:javascript289 - framework:express290 - framework:react291 - framework:vue292 - framework:angular293 - category:security294 - subcategory:cryptography295 - standard:owasp-top10296 - risk:a02-cryptographic-failures297 references:298 - "https://owasp.org/Top10/A02_2021-Cryptographic_Failures/"299 - "https://cheatsheetseries.owasp.org/cheatsheets/Cryptographic_Storage_Cheat_Sheet.html"300 - "https://nodejs.org/api/crypto.html"301 - "https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto"302 - "https://www.npmjs.com/package/bcrypt"303 - "https://www.npmjs.com/package/jsonwebtoken"304</rule>305
One repository carrying more than one format is the comparison this product exists for: does anyone actually write different content in each file, or is one a copy of the other?
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| ivangrynenko/cursorrules.cursor/rules/cursor-rules.mdc · 86 | Cursor rules | teststylearchgit+2 | 77/100 | 14 days ago | |
| ivangrynenko/cursorrules.cursor/rules/behat-steps.mdc · 86 | Cursor rules | lint-formatstyleperformanceagent-behaviour | 42/100 | 14 days ago | |
| ivangrynenko/cursorrules.cursor/rules/php-drupal-development-standards.mdc · 86 | Cursor rules | no sections | 34/100 | 14 days ago | |
| ivangrynenko/cursorrules.cursor/rules/python-insecure-design.mdc · 86 | Cursor rules | no sections | 40/100 | 14 days ago | |
| ivangrynenko/cursorrules.cursor/rules/python-cryptographic-failures.mdc · 86 | Cursor rules | security | 40/100 | 14 days ago | |
| ivangrynenko/cursorrules.cursor/rules/python-injection.mdc · 86 | Cursor rules | styledo-not | 51/100 | 14 days ago | |
| ivangrynenko/cursorrules.cursor/rules/node-dependencies.mdc · 86 | Cursor rules | no sections | 16/100 | 14 days ago | |
| ivangrynenko/cursorrules.cursor/rules/behat-ai-guide.mdc · 86 | Cursor rules | testtesting-strategydo-not | 45/100 | 14 days ago | |
| ivangrynenko/cursorrules.cursor/rules/new-pull-request.mdc · 86 | Cursor rules | archtesting-strategygitsecurity+3 | 58/100 | 14 days ago | |
| ivangrynenko/cursorrules.cursor/rules/accessibility-standards.mdc · 86 | Cursor rules | ui | 44/100 | 14 days ago | |
| ivangrynenko/cursorrules.cursor/rules/api-standards.mdc · 86 | Cursor rules | api | 44/100 | 14 days ago | |
| ivangrynenko/cursorrules.cursor/rules/build-optimization.mdc · 86 | Cursor rules | build | 48/100 | 14 days ago | |
| ivangrynenko/cursorrules.cursor/rules/code-generation-standards.mdc · 86 | Cursor rules | lint-formatstyletypesdocs | 52/100 | 14 days ago | |
| ivangrynenko/cursorrules.cursor/rules/confluence-editing-standards.mdc · 86 | Cursor rules | stylearchsecuritydeployment | 60/100 | 14 days ago | |
| ivangrynenko/cursorrules.cursor/rules/debugging-standards.mdc · 86 | Cursor rules | no sections | 30/100 | 14 days ago | |
| ivangrynenko/cursorrules.cursor/rules/docker-compose-standards.mdc · 86 | Cursor rules | style | 62/100 | 14 days ago | |
| ivangrynenko/cursorrules.cursor/rules/drupal-authentication-failures.mdc · 86 | Cursor rules | security | 48/100 | 14 days ago | |
| ivangrynenko/cursorrules.cursor/rules/drupal-broken-access-control.mdc · 86 | Cursor rules | stylesecurity | 52/100 | 14 days ago | |
| ivangrynenko/cursorrules.cursor/rules/drupal-cryptographic-failures.mdc · 86 | Cursor rules | security | 48/100 | 14 days ago | |
| ivangrynenko/cursorrules.cursor/rules/drupal-database-standards.mdc · 86 | Cursor rules | database | 30/100 | 14 days ago |
Same format, overlapping stack, ranked by quality.
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| hiromaily/go-crypto-wallet.cursor/rules/typescript.mdc · 126 | Cursor rules | setupbuildtestlint-format+6 | 100/100 | 14 days ago | |
| TechSquidTV/Hermes.cursor/rules/10-hermes-api.mdc · 45 | Cursor rules | testlint-formatstylearch+5 | 100/100 | 14 days ago | |
| langflow-ai/langflow.cursor/rules/docs_development.mdc · 153k | Cursor rules | setupbuildtestlint-format+7 | 97/100 | 14 days ago | |
| TechSquidTV/Hermes.cursor/rules/20-hermes-api-tests.mdc · 45 | Cursor rules | teststyletesting-strategysecurity+3 | 97/100 | 14 days ago | |
| skillrecordings/egghead-next.cursor/rules/gh-task-plan.mdc · 1.4k | Cursor rules | teststylearchtypes+2 | 96/100 | 14 days ago | |
| skillrecordings/egghead-next.cursor/rules/project-update-rules.mdc · 1.4k | Cursor rules | buildtestlint-formatstyle+7 | 96/100 | 14 days ago | |
| skillrecordings/egghead-next.cursor/rules/project-update-user-rules.mdc · 1.4k | Cursor rules | buildtestlint-formatstyle+7 | 96/100 | 14 days ago | |
| hiromaily/go-crypto-wallet.cursor/rules/proto.mdc · 126 | Cursor rules | buildlint-formatstylearch+3 | 96/100 | 14 days ago |
A badge carrying the measured quality of the strongest agent config file in this repository, out of 100. It reads from this index every time somebody loads your page, so it changes when the measurement changes and there is nothing to keep up to date. Free, no account, and the value is not something you or we can set by hand.
[](https://rulestack.kynth.studio/configs/ivangrynenko-cursorrules-cursor-rules-javascript-cryptographic-failures)Would rather not hotlink us? Every badge is also served in shields.io’s endpoint schema, so shields renders the image and your readers never talk to our domain:
Published by Toolproof, the masthead over this index and eight others. The method behind the number is at toolproof.kynth.studio/methodology, and the whole thing is readable as JSON with no key at /api.