Poodle Attack in Fastapi with Basic Auth
Poodle Attack in Fastapi with Basic Auth — how this specific combination creates or exposes the vulnerability
A Poodle attack (Padding Oracle On Downgraded Legacy Encryption) targets weak configurations in TLS implementations, typically those that allow SSLv3. When FastAPI is deployed with Basic Authentication over a connection that negotiates SSLv3, the protocol’s lack of integrity protection for certain cipher suites can expose encrypted data to adaptive chosen-ciphertext attacks. In this scenario, an attacker who can intercept and modify TLS ciphertext can iteratively decrypt sensitive information byte by byte by observing whether the server’s error responses differ based on padding validity.
Using Basic Authentication compounds the risk because credentials are transmitted in an Authorization header. If the transport layer is downgraded to SSLv3, captured authentication tokens can be subjected to padding oracle attacks, potentially revealing the base64-encoded credentials or session cookies. Even when Basic Auth itself is not inherently flawed, its combination with a weak protocol like SSLv3 allows an attacker to leverage protocol-level weaknesses to recover the plaintext credentials transmitted within the protected payload.
FastAPI applications that rely on standard ASGI servers (such as Uvicorn) without explicit TLS hardening may support legacy protocols if the underlying SSL/TLS library is not configured to disable SSLv3. Developers might inadvertently permit SSLv3 if they accept default or outdated server settings provided by hosting platforms or container images. Consequently, an endpoint like /users/me that requires Basic Auth can become vulnerable when SSLv3 remains negotiable, enabling an attacker to perform Poodle-style decryption of the Authorization header and gain unauthorized access to protected resources.
middleBrick scans such endpoints in an unauthenticated, black-box manner, identifying whether SSLv3 is offered and whether error responses vary in ways indicative of a padding oracle. The scanner’s TLS-related checks fall under broader encryption and data exposure assessments, surfacing weak protocol support that could facilitate Poodle attacks on Basic Auth–protected routes. This helps teams detect unintended protocol downgrade risks before an adversary can exploit them.
Basic Auth-Specific Remediation in Fastapi — concrete code fixes
Remediation focuses on two areas: disabling SSLv3 and ensuring Basic Auth is only transmitted over strong, modern TLS. On the server or reverse proxy side, explicitly disable SSLv3 and prefer strong cipher suites. In FastAPI, you typically manage TLS at the ASGI server or load balancer level rather than in application code, but application-level enforcement and secure coding practices remain essential.
Below are concrete FastAPI examples demonstrating secure Basic Auth usage over HTTPS, with clear comments on why SSLv3 must be disabled at the infrastructure level.
Secure Basic Auth endpoint in FastAPI (application code)
from fastapi import FastAPI, Depends, HTTPException, status
from fastapi.security import HTTPBasic, HTTPBasicCredentials
import secrets
app = FastAPI()
security = HTTPBasic()
def verify_credentials(credentials: HTTPBasicCredentials):
# In production, use constant-time comparison and a secure user store
expected_user = "admin"
expected_pass = "s3cr3t" # replace with a hashed secret in real use
if credentials.username != expected_user:
return False
# Use secrets.compare_digest to avoid timing attacks
return secrets.compare_digest(credentials.password, expected_pass)
@app.get("/users/me")
def read_current_user(credentials: HTTPBasicCredentials = Depends(security)):
if not verify_credentials(credentials):
raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED,
detail="Invalid credentials",
headers={"WWW-Authenticate": "Basic"},
)
return {"username": credentials.username, "note": "Always use HTTPS to protect credentials"}
Infrastructure and configuration guidance
- Disable SSLv3 explicitly in your TLS configuration. For example, with OpenSSL-based servers, set
SSLProtocolto!SSLv3or use modern minimum TLS versions (TLSv1.2 or TLSv1.3). - Use strong cipher suites that provide integrity protection and resist padding oracle attacks. Avoid NULL, export, or anonymous ciphers.
- Ensure your certificate chain is valid and served over HTTPS only. Use HSTS headers to prevent protocol downgrade requests from clients.
- Consider migrating from Basic Auth to token-based mechanisms (e.g., OAuth 2.0 bearer tokens) where feasible, as they reduce the exposure of reusable credentials over long-lived sessions.
middleBrick’s continuous monitoring and CI/CD integrations (GitHub Action and MCP Server) can be used to verify that SSLv3 is not offered and that security headers and TLS settings remain aligned with best practices. This helps prevent regressions that could re-introduce legacy protocol support.