Poodle Attack in Fastapi with Cockroachdb
Poodle Attack in Fastapi with Cockroachdb — how this specific combination creates or exposes the vulnerability
The Poodle attack (Padding Oracle On Downgraded Legacy Encryption) targets systems that negotiate SSL 3.0. In a Fastapi service backed by Cockroachdb, the risk arises when the application or its infrastructure still supports SSL 3.0 cipher suites, even if Cockroachdb itself does not use SSL 3.0 for internal storage. If Fastapi is fronted by a load balancer, reverse proxy, or API gateway that permits SSL 3.0, an attacker can force or downgrade a connection to SSL 3.0 and exploit the padding oracle to decrypt or manipulate ciphertext. Cockroachdb typically requires TLS for client connections; if Fastapi connects to Cockroachdb using a client TLS configuration that negotiates SSL 3.0 or accepts legacy options, the transport between Fastapi and Cockroachdb becomes vulnerable.
Consider a Fastapi endpoint that queries Cockroachdb with user-supplied identifiers, for example, a profile lookup by user_id. If the TLS configuration on the Fastapi side does not explicitly disable SSL 3.0 and does not enforce strong cipher suites, an attacker can intercept or influence the encrypted traffic between Fastapi and Cockroachdb. By sending modified requests and observing error differences—such as a padding error versus a SQL error—an attacker can gradually recover plaintext. The presence of Cockroachdb does not prevent Poodle; what matters is whether the TLS stack used by Fastapi (or any intermediary) allows SSL 3.0. middleBrick scans for this by checking TLS configuration and cipher suite support across the unauthenticated attack surface, flagging endpoints that accept SSL 3.0 as part of its Encryption checks.
Additionally, insecure error handling in Fastapi can amplify Poodle-related risks. If Fastapi returns distinct errors for padding failures versus database or validation errors, it provides an oracle that an attacker can leverage. For instance, a crafted request that triggers an SSL 3.0 padding error might yield a different response than a request that reaches Cockroachdb but fails SQL parsing. Attackers use these side-channel differences to iteratively decrypt traffic. Because Cockroachdb enforces strong server-side TLS, the practical exposure in this stack is usually limited to the Fastapi application or intermediary proxies. middleBrick’s Encryption checks surface such configuration weaknesses, including cipher suites that enable legacy protocols like SSL 3.0.
Cockroachdb-Specific Remediation in Fastapi — concrete code fixes
To mitigate Poodle in a Fastapi + Cockroachdb deployment, explicitly disable SSL 3.0 and weak ciphers in all TLS configurations, and ensure error handling does not leak padding-related information. For Cockroachdb client connections, use modern TLS settings and avoid legacy protocol options.
Secure Cockroachdb client setup in Fastapi
Use the Cockroachdb Python driver with strict TLS parameters. The following example configures an httpx.AsyncClient to connect to Cockroachdb with enforced TLS 1.2+ and strong ciphers, avoiding SSL 3.0.
from fastapi import Fastapi, HTTPException, Depends
import httpx
import ssl
app = Fastapi()
# Configure a secure SSL context that disables SSL 3.0 and weak ciphers
ssl_context = ssl.create_default_context(ssl.Purpose.SERVER_AUTH)
ssl_context.minimum_version = ssl.TLSVersion.TLSv1_2
ssl_context.set_ciphers(
"ECDHE+AESGCM:ECDHE+CHACHA20:DHE+AESGCM:DHE+CHACHA20:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!SSLv3"
)
COCKROACHDB_URI = "cockroachdb://myuser:mypassword@cockroachdb-host:26257/defaultdb?sslmode=verify-full&sslrootcert=/path/to/ca.pem"
async def get_db_client():
# Use httpx with the strict SSL context for TLS-secured Cockroachdb connections
async with httpx.AsyncClient(verify=str(ssl_context)) as client:
# Example: execute a simple query via Cockroachdb HTTP endpoint or use an ORM
# Here we demonstrate a raw request to highlight TLS enforcement
resp = await client.get(
"https://cockroachdb-host:26257/_status/vars",
timeout=10.0
)
resp.raise_for_status()
return resp.json()
@app.get("/profile/{user_id}")
async def get_profile(user_id: int):
try:
client = await get_db_client()
# Proper parameterized query to avoid SQL injection
data = await client.get(f"/profile/{user_id}")
return data
except httpx.HTTPStatusError as e:
raise HTTPException(status_code=502, detail="Upstream service error")
except Exception as e:
raise HTTPException(status_code=500, detail="Internal error")
In this setup:
minimum_version = ssl.TLSVersion.TLSv1_2disables SSL 3.0 and TLS 1.0/1.1.- The cipher string explicitly excludes weak and export ciphers, including SSLv3 references, ensuring modern negotiated suites.
sslmode=verify-fulland a trusted CA certificate enforce server identity verification, preventing man-in-the-middle attacks that could otherwise facilitate oracle attacks.
Also ensure Fastapi’s own server settings do not allow SSL 3.0. If using an ASGI server like uvicorn, pass TLS parameters that disable legacy protocols:
import ssl
ssl_context = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH)
ssl_context.minimum_version = ssl.TLSVersion.TLSv1_2
ssl_context.set_ciphers("ECDHE+AESGCM:ECDHE+CHACHA20:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!SSLv3")
# Run with: uvicorn main:app --ssl-keyfile=key.pem --ssl-certfile=cert.pem --ssl-min-version TLSv1.2
Finally, apply consistent error handling to avoid leaking padding-related side channels. Use generic error responses for request failures and ensure logging does not expose stack traces or protocol-level details that could assist an attacker.