Cryptographic Failures

Crypto MisuseWeak CryptographyTLS/SSL Issues

Cryptographic Failures vulnerabilities at a glance

What it is: Mistakes when setting up cryptography that lead to broken, weak, or misconfigured cryptography, or disabling it entirely and can leave users exposed.
Why it happens: Rather than using robust cryptography methods, weaker or faster methods of cryptography are used.
How to fix: To prevent cryptographic vulnerabilities, use well-established, vetted libraries and algorithms, apply modern standards for encryption and hashing, ensure proper key and certificate management, and generate all secrets and tokens using secure, high-entropy random sources.

Overview

Cryptographic failures are mistakes in selecting, configuring, or applying cryptography. They often come from speed, legacy code, or copy paste from examples. Common patterns are fast password hashing, static or hardcoded keys, ECB mode, fixed IVs, accepting JWT alg=none, and turning off TLS validation.

The right fixes are simple but strict, for example using high level, battle tested libraries with safe defaults, pinning algorithms, and generating randomness from the OS CSPRNG.

sequenceDiagram participant App as App Server participant DB as Database participant CLI as Cracking Rig App->>DB: Store MD5(password) note over DB: User table leaked via another bug DB->>CLI: Hash data extracted CLI->>CLI: Run hash cracking on MD5 hashes note over CLI: Recovered plaintext passwords CLI->>App: Login with recovered credentials
A potential flow for a Cryptographic Failures exploit

Where it occurs

These issues often show up in home grown auth, token generators, encryption helpers, and HTTP client configuration.

Impact

Attackers can steal credentials, read or manipulate sensitive data, impersonate services, or escalate to full account or environment compromise. Because traffic and data appear valid, detection is difficult.

Prevention

Use secure random generators for secrets, store and rotate keys safely, apply strong salted password hashing, and enforce strict TLS certificate and hostname verification.

Specific Vulnerabilities

Explore specific vulnerability types within this category:

Examples

Switch tabs to view language/framework variants.

Express, JWT verification accepts alg=none

The server decodes a JWT but does not enforce a signature algorithm, so unsigned tokens are treated as valid.

Vulnerable
JavaScript • Express — Bad
const jwt = require('jsonwebtoken');
function auth(req, res, next){
  const t = (req.headers.authorization||'').replace('Bearer ', '');
  try {
    // BUG: decode or verify without forcing algorithm and key
    const payload = jwt.decode(t) || jwt.verify(t, 'secret');
    req.user = payload;
    next();
  } catch { res.status(401).end(); }
}
  • Line 5: jwt.decode does not verify a signature
  • Line 5: jwt.verify without restricting algorithms may misverify if used incorrectly

Decoding or loosely verifying JWTs accepts tokens that are not signed or signed with the wrong algorithm. Attackers forge admin claims and bypass auth.

Secure
JavaScript • Express — Good
const jwt = require('jsonwebtoken');
const PUB = Buffer.from(process.env.JWT_PUBLIC_KEY_PEM, 'utf8');
const ALGS = ['RS256'];
function auth(req, res, next){
  const t = (req.headers.authorization||'').replace('Bearer ', '');
  try {
    const payload = jwt.verify(t, PUB, { algorithms: ALGS });
    req.user = payload; next();
  } catch { return res.status(401).end(); }
}
  • Line 3: Pin acceptable algorithms
  • Line 7: Verify with the correct public key and algorithm

Always verify with an expected algorithm list and the correct key material. Reject alg=none.

Detect These Vulnerabilities in Your Code

Sourcery automatically identifies cryptographic failures and related vulnerabilities in your codebase.

Scan Your Code for Free