Certificate Validation Failures

CWE-295, CWE-297, CWE-298, CWE-299, CWE-346:

Vulnerabilities in how applications validate SSL/TLS certificates:

Together, they allow man-in-the-middle attacks despite HTTPS.


Real-World Attack Scenarios

Scenario 1: Accepting Any Certificate

Application doesn't validate certificate at all:

import requests

# VULNERABLE - verify=False
response = requests.get('https://api.example.com', verify=False)

# Or in urllib
import urllib.request
import ssl

context = ssl._create_unverified_context()
urllib.request.urlopen('https://api.example.com', context=context)

The attack:

Attacker performs MITM:

  1. User connects to attacker's fake server

  2. Fake server uses self-signed certificate

  3. Application accepts ANY certificate (even self-signed)

  4. Attacker intercepts all HTTPS traffic

  5. All data encrypted to attacker, not real server

Result:

  • Complete MITM attack

  • All HTTPS data compromised

  • Credentials stolen

  • Complete encryption bypass

Finding it: Check certificate validation code. Look for verify=False. Test with self-signed certificate.


Scenario 2: Hostname Mismatch

Certificate for wrong hostname accepted:

The attack:

Result:

  • MITM attack succeeds

  • Encryption provides false sense of security

  • All traffic compromised

Finding it: Intercept with proxy using wrong certificate. Check if accepted.


Scenario 3: Wildcard Certificate Mismatch

Wildcard certificate abused:

Finding it: Test with wildcard certificates. Try subdomain variations.


Scenario 4: Self-Signed Certificate Accepted

Application trusts self-signed certificates:

The attack:

Attacker uses self-signed certificate for MITM:

Result:

  • MITM attack

  • All traffic compromised

Finding it: Look for CERT_NONE, check_hostname = False. Test with self-signed cert.


Scenario 5: Origin Validation Error

Application doesn't validate request origin:

Attacker from different origin can make request:

Result:

  • CSRF attack

  • Unauthorized actions

  • Fund theft

Finding it: Check CORS headers. Try requests from different origins. Check for Origin validation.


Mitigation Strategies

Always verify certificates

Use proper SSL context

Never disable verification

Use certificate pinning

For mobile apps, pin expected certificates:

Implement CORS properly

Validate origin header

Use HSTS

Tells browsers to always use HTTPS, never HTTP.


Last updated