Overview
This vulnerability occurs when an application transmits sensitive data, such as passwords, session tokens, or personal information, over an unencrypted channel (like HTTP). An attacker on the same network (e.g., public Wi-Fi) can “sniff” this traffic and steal the data, leading to account compromise or data breaches.Business Impact
Transmitting data in cleartext is a critical failure of confidentiality. It can lead to the widespread theft of user credentials, session hijacking, and the exposure of all data your application handles. This directly violates compliance standards like PCI-DSS and GDPR, leading to severe fines and a complete loss of user trust.Reference Details
CWE ID: CWE-319
OWASP Top 10 (2021): A02:2021 - Cryptographic Failures
Severity: High
Framework-Specific Analysis and Remediation
This is a deployment and configuration issue. The fix is to enforce HTTPS-only communication. This involves:- Setting up a TLS/SSL certificate on your web server (e.g., Nginx, Apache) or load balancer.
- Configuring your application framework to redirect all HTTP traffic to HTTPS.
- Setting the
Secureflag on all sensitive cookies.
- Python
- Java
- .NET(C#)
- PHP
- Node.js
- Ruby
Framework Context
This is controlled bySECURE_SSL_REDIRECT in settings.py. In a production deployment behind a reverse proxy (like Nginx), you must also ensure the proxy is configured to pass the correct headers.Vulnerable Scenario 1: SECURE_SSL_REDIRECT = False
The application is deployed without SSL redirection, allowing users to access the site and submit forms over HTTP.Vulnerable Scenario 2: Misconfigured Proxy
TheSECURE_SSL_REDIRECT is True, but the reverse proxy (Nginx) doesn’t set the X-Forwarded-Proto header. Django won’t know it’s behind a secure connection and may cause a redirect loop or serve insecure content.Mitigation and Best Practices
In your productionsettings.py, set SECURE_SSL_REDIRECT, SESSION_COOKIE_SECURE, and CSRF_COOKIE_SECURE to True. Configure your proxy to pass the X-Forwarded-Proto header and enable SECURE_PROXY_SSL_HEADER.Secure Code Example
Testing Strategy
Use a tool likecurl -I http://your-domain.com. Assert that the response is a 301 Moved Permanently with a Location header pointing to https://your-domain.com. Also, check your session cookies in a browser to ensure the “Secure” flag is set.
