CWE-327OWASP A02:2021CWE-328

CWE-327: Use of a Broken or Risky Cryptographic Algorithm

Data is protected with a cryptographic algorithm that is broken or outdated, so the protection can be defeated.

Also known as: Weak cryptography, Broken crypto algorithm, Risky cipher

Risk

Varies from moderate to critical. Broken algorithms can expose stored passwords, decrypt sensitive data, or let signatures be forged.

Definition

What it is

CWE-327 occurs when data is protected with a cryptographic algorithm or mode that is known to be weak, such as MD5, SHA-1, DES, or ECB. The algorithm runs and produces output, so the code looks correct, but the protection it provides can be broken. This affects password storage, encryption, and signatures alike. The fix is to use modern, vetted primitives and let a maintained library pick safe defaults.

Use-cases

How it shows up in real code

Passwords hashed with MD5

Account passwords are stored as fast MD5 hashes. A leaked database is cracked quickly because the hash is both fast and broken.

ECB mode leaks patterns

Data is encrypted with AES in ECB mode. Identical plaintext blocks produce identical ciphertext, revealing structure to anyone who sees it.

Signatures over SHA-1

A signing scheme uses SHA-1 for integrity. A collision lets an attacker substitute content while the signature still verifies.

Legacy cipher for tokens

Session tokens are protected with DES or RC4. The weak cipher is broken, so tokens can be forged or recovered.

AI risk

Why AI-generated code has increased the exposure

  • Asked to hash a password or encrypt a value, assistants often emit MD5, SHA-1, DES, or ECB-mode code, because those appear constantly in the training data and still run correctly.
  • Models reproduce dated tutorial patterns that predate current guidance, so a weak algorithm or mode is chosen by default.
  • Generated code picks an algorithm for the prompt's wording without the threat context, so it cannot tell that this value needs a modern, authenticated, or slow construction.
  • When scaffolding login, token, or storage features, the easiest generated snippet reaches for a familiar but broken primitive rather than a vetted library default.
  • Each generated crypto call made from the same weak pattern is an independent exposure, so more generated security features means more broken algorithms in the codebase.

Vibe coding

How vibe coding amplifies the risk

  • Vibe coding ships the generated crypto unread, so a broken algorithm choice reaches production with no one checking it against current guidance.
  • Prompt-and-ship skips the review where MD5 for a password or ECB for data would be caught.
  • Iterating by prompt copies the existing weak primitive into new code paths rather than upgrading it.
  • The code encrypts and decrypts correctly in testing, so the weakness is invisible until an attacker exploits the algorithm, not the code.
  • Rapid growth spreads the same broken choice across features faster than review can standardize on a safe library.

Detection

How to find it

  • Look for use of MD5, SHA-1, DES, RC4, or ECB mode, and for fast general-purpose hashes used on passwords.
  • Check that encryption uses an authenticated mode and that keys and nonces are generated and managed correctly.
  • Inventory every cryptographic call and compare the chosen algorithm against current recommendations.
  • Use static analysis rules that flag known-broken algorithms and modes.

Remediation

How to fix it

  • Use modern, vetted primitives: AES-GCM or equivalent authenticated encryption, and SHA-256 or stronger for integrity.
  • Hash passwords with a slow, salted function such as Argon2, scrypt, or bcrypt, never a fast general hash.
  • Rely on a maintained crypto library's safe defaults instead of assembling primitives by hand.
  • Generate keys and nonces from a cryptographically secure source and manage them outside the code.
  • Add a CI rule that fails the build on known-broken algorithms so weak choices cannot return.

Frequently asked questions

What is CWE-327 (use of a broken or risky cryptographic algorithm)?
CWE-327, use of a broken or risky cryptographic algorithm, is when data is protected with a weak or outdated primitive such as MD5, SHA-1, DES, or ECB mode, so the protection runs but can be defeated, affecting password storage, encryption, and signatures.
How have AI assistants and vibe coding increased use of a broken or risky cryptographic algorithm risk?
Assistants often emit MD5, SHA-1, DES, or ECB code because those appear constantly in training data and still run correctly, reproducing dated tutorial patterns. Vibe coding ships that choice unread, so a broken algorithm reaches production, and because encryption still works in testing the weakness is invisible until the algorithm itself is attacked.
How do I fix use of a broken or risky cryptographic algorithm?
Use modern vetted primitives such as AES-GCM and SHA-256, hash passwords with a slow salted function like Argon2, scrypt, or bcrypt, rely on a maintained library's safe defaults, generate keys and nonces from a secure source, and add a CI rule that fails the build on broken algorithms.

Related weaknesses

Catch CWE-327 before you ship

Tethlyn Audit scans your codebase and its git history for CWE-327 and the rest of the injection & code vulnerabilities class, then ranks each finding by real exploitability and data sensitivity.

See Tethlyn Audit