Overview
Sensitive Data Exposure occurs when an application unintentionally reveals sensitive information to an unauthorized party. This can include PII, financial data, internal system details, or credentials. This weakness is often the result of misconfiguration (like running in “debug” mode) or failing to filter sensitive data from API responses.Business Impact
This vulnerability can lead to massive data breaches, loss of user trust, and severe regulatory fines (e.g., under GDPR, CCPA). Leaked system information and stack traces also provide attackers with a detailed map of your application, making other attacks (like Injection or Access Control bypass) much easier.Reference Details
CWE ID: CWE-200
OWASP Top 10 (2021): A01:2021 - Broken Access Control
Severity: Medium
Framework-Specific Analysis and Remediation
All frameworks have a “debug” or “development” mode that is intentionally verbose. The most common vulnerability is a simple failure to disable this mode in production. The second most common is serializing entire data models (like aUser object) directly to an API response, which accidentally includes password hashes, tokens, or PII.
- Python
- Java
- .NET(C#)
- PHP
- Node.js
- Ruby
Framework Context
Django’sDEBUG = True setting is the primary culprit. For Django Rest Framework (DRF), ModelSerializer can over-share data if not explicitly configured.Vulnerable Scenario 1: Debug Mode in Production
LeavingDEBUG = True in settings.py on a production server will show detailed stack traces to the public.Vulnerable Scenario 2: Over-sharing in API
AModelSerializer for the User model that doesn’t restrict fields.Mitigation and Best Practices
SetDEBUG = False in production. Use environment variables to control this. For DRF, explicitly list fields using the fields tuple or use exclude to blacklist sensitive ones.Secure Code Example
Use a DTO (Data Transfer Object) pattern, which DRF serializers provide, to create a “whitelist” of safe fields.Testing Strategy
Write a test to ensureDEBUG is False. For APIs, write a unit test for the serializer or an integration test for the endpoint and assert that sensitive keys are not in the response.
