There can be business sensitive information that are added to logs in the WSO2 product console and/or WSO2 Carbon log files. When these logs are analyzed, the information is exposed to those who check this.
To avoid this potential security pitfall, users can mask sensitive information from the log file at the time of logging. In this feature, you can define patterns that need to be masked from the logs. This is particularly useful in the case of credit card numbers, access tokens, etc.
To configure this feature, follow the instructions below.
Enabling log masking
<PRODUCT_HOME>/repository/conf/log4j.propertiesfile in a text editor.
Uncomment or add the following property under
path-to-masking-patterns value must be a absolute path to the masking patterns file. In this file, each pattern is defined as key, value pairs (patten-name=pattern). Please refer to the next section for information on this file.
The following is a sample configuration for the above property.
DailyRollingFileAppender value, the above property would be similar to the following.
In this case, you can define separate masking pattern files for console appender and file appender. (or configure only one property.)
The masking pattern file
The masking pattern file is a property file that can contain one or more masking patterns. The following is a sample configuration that showcases how to mask the credit card numbers from the logs.
With this configuration, each log line is checked for all the configured patterns. If any match is found, it is masked with ‘*****’.
If the pattern file that is configured in the log4j.properties file is not found, a default property file will be used (
If there are no any patterns defined in the file, no masking happens.
Important: There can be a performance impact when using this feature with many masking patterns since each log line is matched with each of the patterns. So it is highly advisable to only use the most necessary patterns.