In 2012, the LinkedIn password database leak exposed 6.5 million SHA-1 unsalted hashes. Within 24 hours the majority were cracked using rainbow tables. In 2017 Google's Project Zero demonstrated a practical SHA-1 collision — the SHAttered attack — producing two different PDF files with identical SHA-1 digests, costing roughly $110,000 in cloud compute. By 2020, AI code assistants trained on pre-2010 Stack Overflow answers were still suggesting SHA-1 for password hashing and MD5 for file integrity in generated code snippets, because those snippets dominated the training corpus.
Large language models learn from code repositories and Q&A forums accumulated over decades. A question asked in 2006 — "How do I hash a password in Python?" — with an accepted answer demonstrating hashlib.md5() still sits in the training data with high engagement signals. The model has no internal calendar; it cannot natively distinguish "this was valid advice in 2006" from "this is valid advice today."
The practical result is that AI code generators frequently produce cryptographic code that was already considered weak or broken at the time of generation. Auditors need pattern recognition for these choices, not just abstract awareness that old algorithms exist.
Telegram's original MTProto protocol used a custom combination of AES-IGE mode and SHA-1 for message authentication. Security researchers identified that IGE mode does not provide ciphertext integrity and that SHA-1 was already weakened. The design was criticized in published cryptanalysis (Albrecht et al., 2012). Telegram rewrote MTProto2 using SHA-256 and HMAC constructions, but the original flaw arose from combining primitives that were individually familiar rather than collectively secure — precisely the pattern AI-generated crypto tends to reproduce.
Auditors should recognize three categories of deprecated cryptographic primitives that appear in AI-generated code with high frequency:
| Primitive | Category | Known Break | Severity |
|---|---|---|---|
| MD5 | Hash | Collision attacks since 2004 (Wang et al.); practical chosen-prefix collisions 2009 (Sotirov, Stevens) | Critical |
| SHA-1 | Hash | Theoretical breaks 2005; SHAttered practical collision 2017 (Stevens et al., Google) | Critical |
| DES | Symmetric cipher | 56-bit key exhausted by EFF Deep Crack 1998 in 56 hours; 3DES deprecated by NIST 2017 | Critical |
| RC4 | Stream cipher | Biases in first bytes known 1995; full prohibitions in TLS by RFC 7465 (2015) | Critical |
| RSA-512 / RSA-768 | Asymmetric | RSA-512 factored 1999 (Cavallar et al.); RSA-768 factored 2009 (Kleinjung et al.) | Critical |
| ECB mode (any cipher) | Block cipher mode | Deterministic, reveals plaintext patterns; the "ECB penguin" demonstration is canonical | High |
| SHA-256 for passwords | Hash (misuse) | Not broken, but wrong tool: GPU cracking at billions of hashes/sec without work factor | High |
The following patterns appear verbatim in AI-generated code. Each represents an auditable red flag:
When reviewing AI-generated code, search for the string literals "MD5", "SHA1", "SHA-1", "DES", "RC4", "ECB", and "RSA" combined with key-size parameters under 2048. These strings in imports, Cipher.getInstance() calls, or hashlib invocations are near-certain indicators of deprecated cryptography requiring remediation before deployment.
hashlib.sha256(password).hexdigest() for password storage. What is the primary security concern?You are reviewing AI-generated Python code for a healthcare data platform. The assistant has produced several modules that handle encryption and hashing. Your task is to identify every deprecated or misused cryptographic primitive, explain why each is dangerous, and recommend a secure replacement.
The AI lab assistant will present code snippets and answer your auditing questions. Complete at least 3 exchanges to finish the lab.
In January 2019, researcher Tanya Janca (SheHacksPurple) documented a pattern she had observed across hundreds of code reviews: AI-assisted code completion tools were inserting placeholder cryptographic keys that developers forgot to replace before deployment. The pattern appeared in AWS credential leaks tracked by the GitGuardian 2022 State of Secrets Sprawl report, which found over 10 million secrets exposed in public GitHub commits — a 50% year-over-year increase coinciding with the rise of AI code completion adoption. In 2023, GitGuardian's report identified secrets in 1 in every 10 public GitHub repositories.
AI code assistants generate hardcoded cryptographic material through three distinct mechanisms:
1. Placeholder completion: When asked to write encryption code, the model generates a complete working example including a literal key — because training examples almost always include literal keys for demonstrability. The developer copies the snippet and the placeholder key survives into production.
2. Test-to-production bleeding: AI-generated test fixtures include hardcoded test credentials. When production code is scaffolded from the same pattern, the test values persist.
3. IV/nonce reuse: AI generators frequently produce a hardcoded initialization vector (IV) of all-zeros or a literal byte string — an error that in many cipher modes (especially CTR) reduces the encryption to trivially recoverable plaintext given two messages encrypted with the same key.
In 2016, Uber suffered a breach affecting 57 million riders and drivers. The root cause: AWS access credentials were committed to a private GitHub repository in plaintext. Attackers — scanning for hardcoded secrets, a fully automated process — found the credentials, authenticated to AWS, and downloaded the data. The incident cost Uber $148 million in a 2018 settlement with US states. While not AI-generated, the pattern is identical to what AI code assistants now reproduce automatically.
Nonce reuse in stream cipher modes (CTR, GCM) is particularly dangerous because it is mathematically catastrophic rather than merely weakening. In CTR mode, the keystream is generated as E(key, nonce || counter). If the same nonce is reused with the same key, both messages are XORed with the identical keystream. An attacker who observes both ciphertexts can compute their XOR, obtaining the XOR of the two plaintexts — which is trivially recoverable using frequency analysis or known-plaintext attacks.
In AES-GCM, nonce reuse is even worse: it allows an attacker to recover the authentication key, defeating both confidentiality and integrity simultaneously. This is not theoretical — the Forbidden Attack (Joux, 2006, formalized by Handschuh and Preneel) demonstrates GCM nonce reuse as a practical key recovery.
Sony's PlayStation 3 used ECDSA signatures to verify game code. The implementation reused the same random nonce k for every signature. Fail0verflow demonstrated at CCC 2010 that when nonce k is repeated across two signatures (r, s₁) and (r, s₂), the private key d can be algebraically recovered: d = (s₁ - s₂)⁻¹ × (z₁ - z₂) mod n. This allowed arbitrary code signing on the PS3 — catastrophic firmware-level compromise from a single cryptographic implementation error. AI-generated ECDSA code today frequently omits deterministic nonce generation (RFC 6979), reproducing the same flaw.
When reviewing AI-generated cryptographic code, apply this checklist:
Any stream cipher (including AES-CTR and AES-GCM) used to encrypt two messages with the same key and nonce becomes a two-time pad. The security collapses completely — not gradually, but immediately. Auditors must treat any hardcoded or static nonce as a critical finding regardless of the surrounding code's quality.
You are auditing a fintech startup's codebase that was primarily written using AI code assistants. The engineering team suspects hardcoded secrets and improper IV/nonce handling may exist but has not conducted a formal review. Your task is to interrogate the AI assistant about specific files and patterns, identify all hardcoded secret findings, and recommend remediation.
Complete at least 3 meaningful exchanges to finish this lab.
In 2014, Apple shipped iOS 7 with a bug in SecureTransport — the notorious "goto fail" vulnerability (CVE-2014-1266). A duplicated goto fail; statement caused the signature verification function to always return success, regardless of whether certificate validation passed. This meant any TLS connection appeared valid regardless of certificate authenticity. The bug was present for months in shipping iOS and OS X builds. While not AI-generated, the pattern — a single line change defeating all TLS trust — is precisely what AI code generators reproduce when they suggest verify=False or similar certificate-disabling patterns to resolve SSL errors.
When developers encounter SSL certificate errors during development, a common Stack Overflow resolution — heavily represented in training data — is to pass verify=False to the requests library. AI code generators reproduce this suggestion frequently because it appears as a working solution to a common error message. The developer copies it, the SSL error disappears, and the code ships to production with TLS verification permanently disabled.
The Equifax breach (September 2017, 147 million records) involved multiple failures. One contributing factor identified in Congressional testimony and the post-incident GAO report was the failure to inspect encrypted traffic at a TLS inspection point that had an expired certificate — the monitoring device had stopped inspecting traffic silently when its own certificate expired. The breach persisted for 76 days partly because encrypted internal traffic was not being inspected. TLS configuration errors — including disabled verification and expired certificates — created blind spots that allowed exfiltration to go undetected.
AI-generated server configuration code commonly omits explicit minimum TLS version enforcement, defaulting to library defaults that often include TLS 1.0 and 1.1 for compatibility. This enables protocol downgrade attacks.
POODLE (CVE-2014-3566): Bodo Möller, Thai Duong, and Krzysztof Kotowicz at Google demonstrated in 2014 that an attacker controlling the network could force a TLS session to downgrade to SSL 3.0, then exploit a padding oracle in CBC mode to decrypt cookies one byte at a time. The attack requires roughly 256 requests per byte — practical for session cookie recovery.
BEAST (CVE-2011-3389): Demonstrated by Duong and Rizzo at Ekoparty 2011, BEAST exploited predictable IVs in TLS 1.0's CBC implementation to perform a chosen-plaintext attack against browser cookies, recovering CSRF tokens and session identifiers.
Mobile AI-generated code often includes certificate pinning implementations with subtle flaws: pinning only the leaf certificate (breaking on certificate renewal), implementing pinning but bypassing it on exceptions, or pinning to a self-signed certificate with no rotation plan. The 2015 Superfish adware incident installed a self-signed root certificate on Lenovo laptops, enabling MITM against all HTTPS traffic — functionally identical to what happens when applications bypass standard certificate validation.
| AI-Generated Pattern | Attack Enabled | Severity |
|---|---|---|
| verify=False / setHostnameVerifier(→true) | Full MITM — any certificate accepted | Critical |
| No minimum TLS version | POODLE, BEAST downgrade attacks | High |
| Weak cipher suites allowed (RC4, DES in TLS) | SWEET32, CRIME, RC4 biases | High |
| Certificate pinning on leaf cert only | Pin bypass on cert renewal; service disruption | Medium |
| Self-signed cert accepted in production | MITM; no chain of trust | Critical |
requests library, which parameter indicates TLS certificate verification has been disabled?A development team used an AI assistant to configure TLS for their new API gateway, a mobile application's network layer, and an internal microservice mesh. You suspect the AI introduced certificate verification bypasses, weak protocol versions, and misconfigured cipher suites. Your job is to audit the configurations, identify each vulnerability, and prescribe specific remediation steps.
Complete at least 3 meaningful exchanges to finish this lab.
In 2012, researchers Lenstra, Hughes, Kleinjung, Lange, Simmons, and Stern conducted a large-scale analysis of RSA public keys collected from the internet. They found that 0.2% of RSA keys — over 27,000 keys — shared a prime factor with at least one other key. This meant those RSA keys could be factored using a simple GCD computation in milliseconds, recovering the private key entirely. The root cause was insufficient entropy during key generation on embedded devices — routers, firewalls, and VPN concentrators that generated keys during early boot before sufficient entropy had accumulated. Weak random number generation collapsed the security of approximately 5,000 distinct hosts to effectively zero.
AI code generators conflate general-purpose random number functions with cryptographically secure random number generators (CSPRNGs) because both categories appear in the same training contexts. The critical difference:
General-purpose PRNGs (Math.random() in JavaScript, random.random() in Python, java.util.Random) use algorithms like linear congruential generators or Mersenne Twister. These are fast, statistically uniform, and completely predictable if the seed or any output is observed.
CSPRNGs (window.crypto.getRandomValues() in JS, os.urandom() or secrets module in Python, java.security.SecureRandom) draw entropy from the operating system and are computationally infeasible to predict even with knowledge of previous outputs.
In 2006, a Debian maintainer removed two lines from the OpenSSL PRNG seeding code during a valgrind audit, believing them to be uninitialized memory accesses. Those two lines were the primary source of entropy. For two years, Debian and Ubuntu systems generated all SSL/SSH keys using a PRNG seeded only with the process ID — a 15-bit value with at most 32,768 possible seeds. When the bug was discovered in May 2008 (CVE-2008-0166), all keys generated on affected systems were compromised. Pre-generated tables of all possible keys were published within hours. Millions of deployed SSH and SSL keys required emergency replacement.
AI-generated code frequently makes critical errors in key derivation — the process of converting a password or passphrase into a cryptographic key. The two most common patterns:
Direct hashing without KDF: Using SHA-256(password) as a key skips the work factor and salt, enabling offline dictionary attacks at GPU speed (billions of attempts per second). This is distinct from but related to the password storage problem — here the attacker recovers the encryption key rather than verifying a password.
PBKDF2 with insufficient iterations: PBKDF2 is a valid KDF, but AI generators frequently use the default iteration count from documentation examples — often 1,000 iterations — rather than the NIST-recommended 600,000 iterations for HMAC-SHA256 (NIST SP 800-132, 2023 update). At 1,000 iterations, PBKDF2 provides minimal protection over direct hashing.
When Lavabit (Edward Snowden's email provider) was ordered to produce SSL private keys by the US government in 2013, founder Ladar Levison complied by providing the 2,560-character key printed in a 4-point font on paper — arguably compliant but practically unusable. The incident highlighted the importance of per-user key derivation: if each user's data is encrypted with a key derived from their password using a proper KDF, even disclosure of server-side keys does not compromise content if passwords remain unknown. Systems using server-side keys derived without per-user salts collapse this model, making the server the single point of trust and failure.
A modern variant of the Debian PRNG bug: AI-generated Docker containers and cloud functions that generate cryptographic keys at startup may encounter entropy starvation — insufficient /dev/random entropy in the container's entropy pool during early initialization. The solution is not to fall back to /dev/urandom (acceptable on modern Linux with getrandom() which blocks until initialized) but to ensure the container environment has access to a hardware RNG source (virtio-rng on VM hosts, or the host's /dev/hwrng via device mapping). AI-generated Kubernetes configurations rarely include these provisions.
| Pattern | Vulnerability | Severity |
|---|---|---|
| Math.random() / random.random() for tokens | Predictable tokens; session hijacking if seed observable | Critical |
| sha256(password) as encryption key | No work factor; offline brute-force at GPU speed | Critical |
| PBKDF2 with ≤10,000 iterations | Inadequate work factor; vulnerable to GPU attacks | High |
| No salt in password hashing | Rainbow table attacks; identical passwords share hashes | Critical |
| Key generation at container startup without entropy check | Entropy starvation; predictable keys (Debian pattern) | High |
A cloud-native SaaS application was scaffolded almost entirely by an AI code assistant. You need to audit its random number generation across all layers (frontend JavaScript, backend Python, infrastructure Terraform) and its key derivation logic for user data encryption. Identify every CSPRNG failure, every KDF misconfiguration, and every missing salt — then prescribe specific fixes.
Complete at least 3 meaningful exchanges to finish this lab.
cipher = AES.new(key, AES.MODE_ECB). The primary security failure is that ECB mode:requests.get(url, verify=False) in production Python code. Which attack does this directly enable?token = str(int(time.time() * 1000))[-6:]. This is vulnerable because: