|
| 1 | +rules: |
| 2 | + # ── Weak Cipher Algorithm ──────────────────────────────────────── |
| 3 | + - id: sec.crypto.weak-cipher |
| 4 | + description: > |
| 5 | + Use of a known-broken or weak cipher algorithm. |
| 6 | + Vulnerable: DES, 3DES (TDEA), RC4, RC2, Blowfish, IDEA, ECB mode for any cipher. |
| 7 | + Per language: |
| 8 | + - Python: Crypto.Cipher.DES, Crypto.Cipher.ARC4, algorithms.TripleDES, mode=ECB |
| 9 | + - Java: Cipher.getInstance("DES"), Cipher.getInstance("RC4"), "AES/ECB/*" |
| 10 | + - Go: des.NewCipher, rc4.NewCipher, cipher.NewECBEncrypter |
| 11 | + - Rust: des crate, rc4 crate, ecb mode |
| 12 | + - JavaScript: crypto.createCipheriv('des-*'), createCipheriv('rc4') |
| 13 | + - C#: DESCryptoServiceProvider, RC2CryptoServiceProvider |
| 14 | + Safe alternatives: AES-256-GCM, ChaCha20-Poly1305, XChaCha20-Poly1305. |
| 15 | + scope: "**/*.{py,js,ts,rb,go,rs,java,kt,cs,php,c,cpp}" |
| 16 | + severity: error |
| 17 | + category: security |
| 18 | + tags: [crypto, weak-cipher, owasp-a02, cwe-327] |
| 19 | + source: diffscope-builtin |
| 20 | + |
| 21 | + # ── Insecure TLS Configuration ─────────────────────────────────── |
| 22 | + - id: sec.crypto.weak-tls |
| 23 | + description: > |
| 24 | + TLS configuration allowing insecure protocol versions or cipher suites. |
| 25 | + Vulnerable: SSLv2, SSLv3, TLS 1.0, TLS 1.1, ssl.PROTOCOL_TLSv1, PROTOCOL_SSLv23 |
| 26 | + without disabling old versions, MinVersion < tls.VersionTLS12 (Go), |
| 27 | + SecurityProtocolType.Ssl3/Tls (C#), ssl_protocols TLSv1 (nginx/Apache). |
| 28 | + Also flag: verify_mode = ssl.CERT_NONE, InsecureSkipVerify: true (Go), |
| 29 | + NODE_TLS_REJECT_UNAUTHORIZED=0, CURLOPT_SSL_VERIFYPEER => false. |
| 30 | + Safe: TLS 1.2+ with AEAD cipher suites, certificate pinning. |
| 31 | + scope: "**/*.{py,js,ts,rb,go,rs,java,kt,cs,php,conf,yaml,yml,toml}" |
| 32 | + severity: error |
| 33 | + category: security |
| 34 | + tags: [crypto, tls, ssl, owasp-a02, cwe-326] |
| 35 | + source: diffscope-builtin |
| 36 | + |
| 37 | + # ── Insecure Randomness ────────────────────────────────────────── |
| 38 | + - id: sec.crypto.insecure-random |
| 39 | + description: > |
| 40 | + Use of non-cryptographic PRNG for security-sensitive operations. |
| 41 | + Vulnerable (when used for tokens, keys, nonces, passwords, session IDs): |
| 42 | + - Python: random.random(), random.randint(), random.choice() — use secrets module |
| 43 | + - JavaScript: Math.random() — use crypto.getRandomValues() or crypto.randomUUID() |
| 44 | + - Java: java.util.Random — use java.security.SecureRandom |
| 45 | + - Go: math/rand — use crypto/rand |
| 46 | + - Ruby: rand, Random.new — use SecureRandom |
| 47 | + - Rust: rand::thread_rng() is OK, but rand::rngs::SmallRng is not for crypto |
| 48 | + - C/C++: rand(), srand() — use platform CSPRNG |
| 49 | + - PHP: rand(), mt_rand() — use random_bytes(), random_int() |
| 50 | + Safe: os.urandom, secrets.token_*, SecureRandom, crypto/rand, CSPRNG. |
| 51 | + scope: "**/*.{py,js,ts,rb,go,rs,java,kt,cs,php,c,cpp}" |
| 52 | + severity: error |
| 53 | + category: security |
| 54 | + tags: [crypto, random, prng, owasp-a02, cwe-330] |
| 55 | + source: diffscope-builtin |
| 56 | + |
| 57 | + # ── Weak Key Size ──────────────────────────────────────────────── |
| 58 | + - id: sec.crypto.weak-key-size |
| 59 | + description: > |
| 60 | + Cryptographic key size below recommended minimum. |
| 61 | + Minimum key sizes: RSA >= 2048 (prefer 4096), EC >= 256 bits (P-256+), |
| 62 | + AES >= 128 (prefer 256), HMAC key >= hash output length. |
| 63 | + Flag: RSA 1024, DSA 1024, DH 1024, EC P-192, AES-64. |
| 64 | + Per language: generate_private_key(1024), KeyPairGenerator with < 2048, |
| 65 | + rsa.GenerateKey(rand, 1024), openssl genrsa 1024. |
| 66 | + scope: "**/*.{py,js,ts,rb,go,rs,java,kt,cs,php,c,cpp}" |
| 67 | + severity: error |
| 68 | + category: security |
| 69 | + tags: [crypto, key-size, owasp-a02, cwe-326] |
| 70 | + source: diffscope-builtin |
| 71 | + |
| 72 | + # ── Broken Hash for Integrity ──────────────────────────────────── |
| 73 | + - id: sec.crypto.broken-hash |
| 74 | + description: > |
| 75 | + Use of broken hash algorithms for integrity verification or digital signatures. |
| 76 | + Vulnerable: MD5, SHA1 for checksums, file integrity, digital signatures, HMAC. |
| 77 | + (Note: MD5/SHA1 for password hashing is covered by sec.auth.weak-password-hash.) |
| 78 | + Flag: hashlib.md5() for file verification, MessageDigest.getInstance("MD5"), |
| 79 | + crypto.createHash('sha1') for HMAC, Digest::MD5 for signatures. |
| 80 | + Safe: SHA-256, SHA-384, SHA-512, SHA-3, BLAKE2, BLAKE3. |
| 81 | + scope: "**/*.{py,js,ts,rb,go,rs,java,kt,cs,php,c,cpp}" |
| 82 | + severity: warning |
| 83 | + category: security |
| 84 | + tags: [crypto, broken-hash, md5, sha1, owasp-a02, cwe-328] |
| 85 | + source: diffscope-builtin |
| 86 | + |
| 87 | + # ── Hardcoded IV / Nonce ───────────────────────────────────────── |
| 88 | + - id: sec.crypto.hardcoded-iv |
| 89 | + description: > |
| 90 | + Initialization vector (IV) or nonce is hardcoded, static, or reused. |
| 91 | + IV/nonce must be unique per encryption operation. Reuse with CTR/GCM modes |
| 92 | + leads to catastrophic key recovery. Flag: string/byte literals assigned to |
| 93 | + iv/nonce variables, IV = b'\x00' * 16, static final byte[] IV. |
| 94 | + Safe: generate random IV per operation, store IV alongside ciphertext. |
| 95 | + scope: "**/*.{py,js,ts,rb,go,rs,java,kt,cs,php,c,cpp}" |
| 96 | + severity: error |
| 97 | + category: security |
| 98 | + tags: [crypto, iv-reuse, nonce, owasp-a02, cwe-329] |
| 99 | + source: diffscope-builtin |
| 100 | + |
| 101 | + # ── Unauthenticated Encryption ─────────────────────────────────── |
| 102 | + - id: sec.crypto.missing-mac |
| 103 | + description: > |
| 104 | + Encryption without authentication (no MAC/AEAD), enabling bit-flipping |
| 105 | + and padding oracle attacks. Vulnerable: AES-CBC without HMAC, |
| 106 | + AES-CTR without MAC, any stream cipher without authentication. |
| 107 | + Flag: CBC/CTR mode usage without a paired HMAC-then-encrypt or encrypt-then-MAC. |
| 108 | + Safe: AES-GCM, AES-CCM, ChaCha20-Poly1305, XChaCha20-Poly1305, NaCl secretbox. |
| 109 | + scope: "**/*.{py,js,ts,rb,go,rs,java,kt,cs,php,c,cpp}" |
| 110 | + severity: warning |
| 111 | + category: security |
| 112 | + tags: [crypto, authenticated-encryption, mac, owasp-a02, cwe-353] |
| 113 | + source: diffscope-builtin |
| 114 | + |
| 115 | + # ── Disabled Certificate Validation ────────────────────────────── |
| 116 | + - id: sec.crypto.cert-validation |
| 117 | + description: > |
| 118 | + TLS certificate validation disabled, enabling MITM attacks. |
| 119 | + Flag per language: |
| 120 | + - Python: verify=False (requests), ssl.CERT_NONE, check_hostname=False |
| 121 | + - Go: InsecureSkipVerify: true, tls.Config with no verification |
| 122 | + - Java: TrustAllCerts, X509TrustManager accepting all, HostnameVerifier accepting all |
| 123 | + - Node.js: rejectUnauthorized: false, NODE_TLS_REJECT_UNAUTHORIZED=0 |
| 124 | + - Ruby: verify_mode = OpenSSL::SSL::VERIFY_NONE |
| 125 | + - Rust: danger_accept_invalid_certs(true) (reqwest) |
| 126 | + - C#: ServerCertificateValidationCallback returning true |
| 127 | + - PHP: CURLOPT_SSL_VERIFYPEER => false, verify_peer => false |
| 128 | + scope: "**/*.{py,js,ts,rb,go,rs,java,kt,cs,php}" |
| 129 | + severity: error |
| 130 | + category: security |
| 131 | + tags: [crypto, certificate, tls, mitm, owasp-a02, cwe-295] |
| 132 | + source: diffscope-builtin |
| 133 | + |
| 134 | + # ── Timing Attack on Secret Comparison ─────────────────────────── |
| 135 | + - id: sec.crypto.timing-attack |
| 136 | + description: > |
| 137 | + Non-constant-time comparison of secrets, tokens, or MACs. |
| 138 | + Flag: == or != operator comparing HMAC digests, API keys, tokens, passwords. |
| 139 | + Safe alternatives per language: |
| 140 | + - Python: hmac.compare_digest(), secrets.compare_digest() |
| 141 | + - Go: subtle.ConstantTimeCompare() |
| 142 | + - Java: MessageDigest.isEqual() |
| 143 | + - Node.js: crypto.timingSafeEqual() |
| 144 | + - Ruby: Rack::Utils.secure_compare(), ActiveSupport::SecurityUtils.secure_compare() |
| 145 | + - Rust: constant_time_eq crate, subtle crate ConstantTimeEq |
| 146 | + scope: "**/*.{py,js,ts,rb,go,rs,java,kt,cs,php}" |
| 147 | + severity: warning |
| 148 | + category: security |
| 149 | + tags: [crypto, timing-attack, side-channel, owasp-a02, cwe-208] |
| 150 | + source: diffscope-builtin |
| 151 | + |
| 152 | + # ── Weak Key Derivation ────────────────────────────────────────── |
| 153 | + - id: sec.crypto.weak-kdf |
| 154 | + description: > |
| 155 | + Key derivation function with insufficient work factor or using a |
| 156 | + non-standard approach. Flag: PBKDF2 with < 600,000 iterations (OWASP 2023), |
| 157 | + single-pass SHA/MD5 as KDF, custom "key stretching" implementations, |
| 158 | + scrypt with N < 2^15 or r < 8, argon2 with < 3 iterations. |
| 159 | + Safe: argon2id (>=3 iterations, >=64MB), bcrypt (cost >= 12), |
| 160 | + scrypt (N >= 2^17, r >= 8), PBKDF2-SHA256 (>= 600k iterations). |
| 161 | + scope: "**/*.{py,js,ts,rb,go,rs,java,kt,cs,php}" |
| 162 | + severity: warning |
| 163 | + category: security |
| 164 | + tags: [crypto, kdf, key-derivation, owasp-a02, cwe-916] |
| 165 | + source: diffscope-builtin |
0 commit comments