Base · Medium

CWE-532: Insertion of Sensitive Information into Log File

The product writes sensitive information to a log file.

CWE-532 · Base Level ·2 CVEs ·4 Mitigations

Description

The product writes sensitive information to a log file.

Potential Impact

Confidentiality

Read Application Data

Demonstrative Examples

In the following code snippet, a user's full name and credit card number are written to a log file.
Bad
logger.info("Username: " + usernme + ", CCN: " + ccn);
This code stores location information about the current user:
Bad
locationClient = new LocationClient(this, this, this);locationClient.connect();currentUser.setLocation(locationClient.getLastLocation());
                     ...
                     
                     catch (Exception e) {AlertDialog.Builder builder = new AlertDialog.Builder(this);builder.setMessage("Sorry, this application has experienced an error.");AlertDialog alert = builder.create();alert.show();Log.e("ExampleActivity", "Caught exception: " + e + " While on User:" + User.toString());}
When the application encounters an exception it will write the user object to the log. Because the user object contains location information, the user's location is also written to the log.
In the example below, the method getUserBankAccount retrieves a bank account object from a database using the supplied username and account number to query the database. If an SQLException is raised when querying the database, an error message is created and output to a log file.
Bad
public BankAccount getUserBankAccount(String username, String accountNumber) {
                        BankAccount userAccount = null;String query = null;try {if (isAuthorizedUser(username)) {query = "SELECT * FROM accounts WHERE owner = "+ username + " AND accountID = " + accountNumber;DatabaseManager dbManager = new DatabaseManager();Connection conn = dbManager.getConnection();Statement stmt = conn.createStatement();ResultSet queryResult = stmt.executeQuery(query);userAccount = (BankAccount)queryResult.getObject(accountNumber);}} catch (SQLException ex) {String logMessage = "Unable to retrieve account information from database,\nquery: " + query;Logger.getLogger(BankManager.class.getName()).log(Level.SEVERE, logMessage, ex);}return userAccount;
                     }
The error message that is created includes information about the database query that may contain sensitive information about the database or query logic. In this case, the error message will expose the table name and column names used in the database. This data could be used to simplify other attacks, such as SQL injection (CWE-89) to directly access the database.

Mitigations & Prevention

Architecture and DesignImplementation

Consider seriously the sensitivity of the information written into log files. Do not write secrets into the log files.

Distribution

Remove debug log files before deploying the application into production.

Operation

Protect log files against unauthorized read/write.

Implementation

Adjust configurations appropriately when software is transitioned from a debug state to production.

Detection Methods

  • Automated Static Analysis High — Automated static analysis, commonly referred to as Static Application Security Testing (SAST), can find some instances of this weakness by analyzing source code (or binary/compiled code) without having to execute it. Typically, this is done by building a model of data flow and control flow, then sea

Real-World CVE Examples

CVE IDDescription
CVE-2017-9615verbose logging stores admin credentials in a world-readable log file
CVE-2018-1999036SSH password for private key stored in build log

Taxonomy Mappings

  • The CERT Oracle Secure Coding Standard for Java (2011): FIO13-J — Do not log sensitive information outside a trust boundary
  • Software Fault Patterns: SFP23 — Exposed Data

Frequently Asked Questions

What is CWE-532?

CWE-532 (Insertion of Sensitive Information into Log File) is a software weakness identified by MITRE's Common Weakness Enumeration. It is classified as a Base-level weakness. The product writes sensitive information to a log file.

How can CWE-532 be exploited?

Attackers can exploit CWE-532 (Insertion of Sensitive Information into Log File) to read application data. This weakness is typically introduced during the Architecture and Design, Implementation, Operation phase of software development.

How do I prevent CWE-532?

Key mitigations include: Consider seriously the sensitivity of the information written into log files. Do not write secrets into the log files.

What is the severity of CWE-532?

CWE-532 is classified as a Base-level weakness (Medium abstraction). It has been observed in 2 real-world CVEs.