Poodle Attack in Fastapi
How POODLE Attack Manifests in FastAPI
The POODLE (Padding Oracle On Downgraded Legacy Encryption) attack, CVE-2014-3566, exploits a vulnerability in SSL 3.0's CBC padding mechanism. In a FastAPI application, the attack manifests when the server (or a downstream proxy like Nginx) supports SSL 3.0 and an attacker can force a protocol downgrade from TLS to SSL 3.0. This is typically a security misconfiguration in the TLS stack, not a FastAPI code flaw per se, but FastAPI applications are vulnerable if deployed with an insecure SSL/TLS configuration.
FastAPI itself does not manage TLS; it relies on an ASGI server (like Uvicorn or Hypercorn) and the underlying OpenSSL library. A common FastAPI deployment pattern uses a command like uvicorn main:app --host 0.0.0.0 --port 443 --ssl-keyfile key.pem --ssl-certfile cert.pem. If the system's OpenSSL is configured to allow SSL 3.0, or if the FastAPI/ASGI server's SSL context is not explicitly restricted, the application will negotiate SSL 3.0 with vulnerable clients. An attacker on the same network can perform a man-in-the-middle attack, injecting JavaScript or using other techniques to trigger protocol downgrade, then systematically decrypt session cookies or other encrypted data one byte at a time.
FastAPI-specific risk factors include:
- Default Server Configurations: Uvicorn's default SSL context uses
ssl.SSLContext(ssl.PROTOCOL_SSLv23)on older Python versions, which may enable SSLv3 if the OpenSSL library supports it. Even on modern Python, if the system OpenSSL is compiled withenable-ssl3(rare but possible in legacy environments), the vulnerability exists. - Proxy Misconfiguration: Many FastAPI apps sit behind Nginx or HAProxy. If these proxies are configured with
ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2;(explicitly including SSLv3) instead ofssl_protocols TLSv1.2 TLSv1.3;, they introduce the vulnerability regardless of the FastAPI app's code. - Compliance Impact: This violates OWASP API Security Top 10 (A6: Security Misconfiguration), PCI-DSS requirement 4.1 (use strong cryptography), and HIPAA's transmission security rules.
FastAPI-Specific Detection
Detecting POODLE vulnerability requires testing the live TLS configuration of your API endpoint. Since middleBrick performs black-box scanning without credentials, it probes the SSL/TLS handshake directly. The scanner's Encryption check (one of its 12 parallel tests) attempts to negotiate SSL 3.0 and analyzes the server's response and cipher suite behavior.
When you scan a FastAPI endpoint (e.g., https://api.example.com) with middleBrick, it returns a risk score and category breakdown. A finding in the Encryption category with high severity indicates the server supports SSL 3.0 or uses weak ciphers. The report will include:
- Severity: Typically 'High' for POODLE, as it allows decryption of HTTPS traffic.
- Evidence: Details like 'SSL 3.0 supported' or 'CBC cipher suites enabled'.
- Remediation Guidance: Specific steps to disable SSLv3 and configure strong ciphers.
You can also use the middleBrick CLI for integration into scripts or CI/CD:
middlebrick scan https://your-fastapi-app.comThe output (in JSON or text) will flag encryption issues. For a FastAPI app behind Nginx, you must scan the public-facing URL (the Nginx endpoint), not the internal Uvicorn socket. middleBrick's OpenAPI/Swagger spec analysis is not directly relevant here, as POODLE is a transport-layer issue, but the scanner correlates runtime findings with your API spec for a comprehensive view.
Manual Verification: You can independently confirm using openssl s_client:
openssl s_client -connect your-fastapi-app.com:443 -ssl3If the handshake succeeds (you see SSL-Session: details), SSL 3.0 is enabled and the app is vulnerable. A failure like 140735209195968:error:1408A0C1:SSL routines:ssl3_get_client_hello:no shared cipher indicates SSLv3 is disabled.
FastAPI-Specific Remediation
Remediation involves configuring your ASGI server and any reverse proxy todisable SSL 3.0 and use only TLS 1.2 or higher with secure cipher suites. The fix is not in FastAPI application code but in the server/OpenSSL configuration.
1. For Uvicorn (direct TLS termination): Use a modern Python (3.7+) and explicitly create an SSL context that disables SSLv3 and sets secure options. In your startup script:
import ssl
import uvicorn
ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
ssl_context.minimum_version = ssl.TLSVersion.TLSv1_2 # Python 3.7+
ssl_context.set_ciphers('ECDHE+AESGCM:ECDHE+CHACHA20:DHE+AESGCM:DHE+CHACHA20')
# Load your cert/key as usual
ssl_context.load_cert_chain(certfile='cert.pem', keyfile='key.pem')
uvicorn.run(
'main:app',
host='0.0.0.0',
port=443,
ssl=ssl_context
)The key is ssl.PROTOCOL_TLS_SERVER (which selects the highest protocol version both sides support, but not SSLv2/SSLv3) and setting minimum_version. The cipher string excludes CBC-mode ciphers vulnerable to POODLE and prefers forward secrecy (ECDHE/DHE).
2. For Nginx as a reverse proxy (common in production): Update your Nginx configuration:
server {
listen 443 ssl http2;
ssl_certificate /path/to/cert.pem;
ssl_certificate_key /path/to/key.pem;
# Disable SSLv3 and old TLS
ssl_protocols TLSv1.2 TLSv1.3;
# Use strong ciphers with forward secrecy
ssl_ciphers 'ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384';
ssl_prefer_server_ciphers off;
location / {
proxy_pass http://127.0.0.1:8000; # your uvicorn/gunicorn
# ... other proxy settings
}
}3. System-wide OpenSSL hardening: Ensure your OS OpenSSL is up-to-date and compiled without SSLv3. On modern Linux distributions, SSLv3 is disabled by default. Verify with openssl version -a and check for no-ssl3 in the build options.
4. Re-scan with middleBrick: After applying these changes, rescan your endpoint with middleBrick (via Dashboard, CLI, or GitHub Action) to confirm the Encryption category score improves and the POODLE finding disappears. Include this scan in your CI/CD pipeline using the middleBrick GitHub Action to prevent regression.
Important: If your FastAPI app communicates with third-party APIs over HTTPS, ensure those outbound connections also use secure TLS settings (using httpx.AsyncClient with proper SSL context), as POODLE could affect client-side connections too.
Additional Resources
Understanding POODLE requires knowledge of TLS internals. Key references:
- Original POODLE paper (security imperfection in CBC padding)
- OWASP Transport Layer Protection Cheat Sheet (configuration guidance)
- RFC 7568: Deprecating SSLv3 (official IETF deprecation)
For FastAPI deployments, always audit your entire TLS chain: from the client-facing load balancer (if any) down to the ASGI server. middleBrick's black-box scanning is designed to catch these configuration issues from an attacker's perspective, providing a clear risk score and remediation steps tailored to your API's public endpoint.