CWE-209: Generation of Error Message Containing Sensitive Information

Description:
The product generates an error message that includes sensitive information about its environment, users, or associated data.

Affected languages: PHP, Java, Not Language-Specific
Affected technologies: Not Technology-Specific
Parent weaknesses: CWE-200, CWE-200, CWE-755

Consequences:
  - Confidentiality: Read Application Data

Detection methods:
  - Manual Analysis: This weakness generally requires domain-specific interpretation using manual analysis. However, the number of potential error conditions may be too large to cover completely within limited time constr
  - Automated Analysis: Automated methods may be able to detect certain idioms automatically, such as exposed stack traces or pathnames, but violation of business rules or privacy requirements is not typically feasible.
  - Automated Dynamic Analysis: This weakness can be detected using dynamic tools and techniques that interact with the software using large test suites with many diverse inputs, such as fuzz testing (fuzzing), robustness testing, a
  - Manual Dynamic Analysis: Identify error conditions that are not likely to occur during normal usage and trigger them. For example, run the program under low memory conditions, run with insufficient privileges or permissions, 

Mitigations:
  - [Implementation] Ensure that error messages only contain minimal details that are useful to the intended audience and no one else. The messages need to strike the balance between being too cryptic (which can confuse users) or being too detailed (which may reveal more than intended). The messages should not reveal th
  - [Implementation] Handle exceptions internally and do not display errors containing potentially sensitive information to a user.
  - [Implementation] Use naming conventions and strong types to make it easier to spot when sensitive data is being used. When creating structures, objects, or other complex entities, separate the sensitive and non-sensitive data as much as possible.
  - [Implementation] Debugging information should not make its way into a production release.

Demonstrative examples:
In the following example, sensitive information might be printed depending on the exception that occurs.
If an exception related to SQL is handled by the catch, then the output might contain sensitive information such as SQL query structure or private information. If this output is redirected to a web user, this may represent a security problem.
try { /.../ } catch (Exception e) { System.out.println(e); }

This code tries to open a database connection, and prints any exceptions that occur.
If an exception occurs, the printed message exposes the location of the configuration file the script is using. An attacker can use this information to target the configuration file (perhaps exploiting a Path Traversal weakness). If the file can be read, the attacker could gain credentials for accessing the database. The attacker may also be able to replace the file with a malicious one, causing the application to use an arbitrary database.
try { openDbConnection(); } 
                      //print exception message that includes exception message and configuration file location 
                      catch (Exception $e) { echo 'Caught exception: ', $e->getMessage(), '\n'; echo 'Check credentials in confi

Real-world examples:
  - CVE-2008-2049: POP3 server reveals a password in an error message after multiple APOP commands are sent. Might be resultant from another weakness.
  - CVE-2007-5172: Program reveals password in error message if attacker can trigger certain database errors.
  - CVE-2008-4638: Composite: application running with high privileges (CWE-250) allows user to specify a restricted file to process, which generates a parsing error that leaks the contents of the file (CWE-209).
  - CVE-2008-1579: Existence of user names can be determined by requesting a nonexistent blog and reading the error message.
  - CVE-2007-1409: Direct request to library file in web application triggers pathname leak in error message.