CWE-532 通过日志文件的信息暴露

Inclusion of Sensitive Information in Log Files

结构: Simple

Abstraction: Variant

状态: Incomplete

被利用可能性: Medium


Information written to log files can be of a sensitive nature and give valuable guidance to an attacker or expose sensitive user information.


While logging all information may be helpful during development stages, it is important that logging levels be set appropriately before a product ships so that sensitive user data and system information are not accidentally exposed to potential attackers.

Different log files may be produced and stored for:


  • cwe_Nature: ChildOf cwe_CWE_ID: 538 cwe_View_ID: 1000 cwe_Ordinal: Primary

  • cwe_Nature: ChildOf cwe_CWE_ID: 538 cwe_View_ID: 699 cwe_Ordinal: Primary

  • cwe_Nature: ChildOf cwe_CWE_ID: 200 cwe_View_ID: 1003 cwe_Ordinal: Primary

  • cwe_Nature: ChildOf cwe_CWE_ID: 552 cwe_View_ID: 1000

  • cwe_Nature: ChildOf cwe_CWE_ID: 552 cwe_View_ID: 699


范围 影响 注释
Confidentiality Read Application Data Logging sensitive user data often provides attackers with an additional, less-protected path to acquiring the information.


['Architecture and Design', 'Implementation']


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



Remove debug log files before deploying the application into production.



Protect log files against unauthorized read/write.



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


In the following code snippet, a user's full name and credit card number are written to a log file.

bad Java"Username: " + usernme + ", CCN: " + ccn);

This code stores location information about the current user:

bad Java

locationClient = new LocationClient(this, this, this);

catch (Exception e) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Sorry, this application has experienced an error.");
AlertDialog alert = builder.create();;
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 Java

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.


标识 说明 链接
CVE-2017-9615 verbose logging stores admin credentials in a world-readablelog file
CVE-2018-1999036 SSH password for private key stored in build log


映射的分类名 ImNode ID Fit Mapped Node Name
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


  • CAPEC-215