CWE-210: Self-generated Error Message Containing Sensitive Information

Learn about CWE-210 (Self-generated Error Message Containing Sensitive Information), its security impact, exploitation methods, and prevention guidelines.

What is Self-generated Error Message Containing Sensitive Information?

• Overview: Self-generated error messages containing sensitive information occur when a software application encounters an error and creates its own messages that inadvertently include sensitive data, such as passwords, API keys, or personally identifiable information (PII).

• Exploitation Methods:

  • Attackers can exploit this vulnerability by triggering errors deliberately to extract sensitive information from the error messages.
  • Common attack patterns and techniques include input manipulation to cause errors and monitoring error responses to gather data.

• Security Impact:

  • Direct consequences of successful exploitation include unauthorized access to sensitive information and potential data breaches.
  • Potential cascading effects include further exploitation of the system using the extracted information, leading to more profound security breaches.
  • Business impact includes loss of customer trust, legal liabilities, and financial losses due to data breaches and regulatory fines.

• Prevention Guidelines:

  • Specific code-level fixes involve sanitizing error messages to ensure they do not contain sensitive information before being returned to users.
  • Security best practices include implementing proper error handling and logging mechanisms that separate internal error details from user-facing messages.
  • Recommended tools and frameworks include using logging libraries that obfuscate sensitive data automatically and security testing tools to identify instances where sensitive information might be exposed in error messages.
Corgea can automatically detect and fix Self-generated Error Message Containing Sensitive Information in your codebase. [Try Corgea free today](https://corgea.app).

Technical Details

Likelihood of Exploit: Not specified

Affected Languages: Not Language-Specific

Affected Technologies: Not specified

Vulnerable Code Example

import logging

def process_user_request(user_request):
    try:
        # Simulate processing user request
        result = process_request(user_request)
        return result
    except Exception as e:
        # Vulnerable: Logging the exception with sensitive information
        logging.error(f"Error processing request: {e}")
        return "An error occurred while processing your request."

def process_request(user_request):
    # Simulate a potential error in processing
    if user_request == "cause_error":
        raise ValueError("Sensitive Information: User ID 12345")
    return "Request processed successfully."

Explanation: In this code, the process_user_request function logs the exception message directly, which might contain sensitive information such as user IDs. This is a security vulnerability because sensitive data can be exposed in logs accessible to unauthorized users. The example demonstrates how error messages can inadvertently leak sensitive information.

How to fix Self-generated Error Message Containing Sensitive Information?

To fix this issue, avoid logging sensitive information directly. Instead, log a generic error message and use unique identifiers (e.g., request ID, error code) that can be traced back to detailed logs stored securely. Additionally, ensure exceptions are handled in a way that prevents sensitive data from being exposed.

Best Practices:

  • Log generic error messages without sensitive details.
  • Use unique identifiers to track errors.
  • Store detailed error information securely and accessibly only to authorized personnel.
  • Implement proper exception handling to ensure sensitive data is not exposed.

Fixed Code Example

import logging
import uuid

def process_user_request(user_request):
    try:
        result = process_request(user_request)
        return result
    except Exception:
        # Fixed: Log a generic message with a unique error ID
        error_id = uuid.uuid4()
        logging.error(f"Error processing request, reference ID: {error_id}")
        return f"An error occurred while processing your request. Please contact support with this reference ID: {error_id}"

def process_request(user_request):
    if user_request == "cause_error":
        raise ValueError("Sensitive Information: User ID 12345")
    return "Request processed successfully."

Explanation: In the fixed code, a generic error message is logged along with a unique error ID when an error occurs. This ID can be used to look up detailed error information stored securely, preventing sensitive data from being exposed in logs. The unique identifier (error_id) aids in troubleshooting without compromising sensitive information. This approach adheres to best practices by ensuring sensitive data is protected while still providing meaningful error tracking.

Corgea Logo

Find this vulnerability and fix it with Corgea

Scan your codebase for CWE-210: Self-generated Error Message Containing Sensitive Information and get remediation guidance

Start for free and no credit card needed.