TLS DSL offers a regular expression replacement function. You can hide sensitive data in logs by using regex replacements, which reduces the risk of sensitive data leakage.
Phone number masking
To desensitize a phone number, you can use the regex replacement function to substitute the middle digits of a phone number with specified characters. For example, use the regex_replace function to replace the middle four digits of an 11-digit phone number, so the full number is not displayed.
Raw log
DSL processing rules
f_set("phone", regex_replace(v("phone"), "(\\d{0,3})\\d{4}(\\d{4})", replace="$1****$2"))
Processing result
IP address masking
To achieve IP address masking, you can use the regex replacement function to substitute the middle digits of an IP address with a specified character. For example, if a log contains an IP address, you can use the regex_replace function to identify and mask the IP address with regular expressions.
Raw log
DSL processing rules
f_set("ip", regex_replace(v("ip"), "(\\d+).(\\d+).(\\d+).(\\d+)", replace="$1.*.*.$4"))
Processing result
Email address masking
To achieve email address masking, you can use a regular expression replacement function to replace the prefix of an email address with specified characters. For example, if the following log contains a complete email address, you can replace the prefix of the email address so that all characters except the first are replaced with *. Through this method, the displayed email address will not be shown as full address.
Raw log
"mail":"seo1893@dev.com"
DSL processing rules
f_set("mail", regex_replace(v("mail"), "([A-Za-z\d])[A-Za-z\d]+(@.*)", replace="$1***$2"))
Processing result