Skip to main content

Data Masking Filter

The Data Masking Extension allows you to hide phone numbers, email address and other sensitive information in messages. You as a developer, can add regular expressions for matching & masking.

Extension settings

  1. Login to CometChat and select your app.

  2. Go to the Extensions section and enable the Data Masking Filter extension.

  3. Open the Settings for this extension and configure the following:

    1. Drop Message: If enabled, any message with sensitive information will be dropped.
    2. Default Masks: Masks for Emails, Social Security Numbers (SSN), US phone numbers are built in.
    3. Custom Masks: Add more regex that will act as masks for some form of sensitive information.
  4. Save the extension settings.

info

Refer this for more details on Regular Expressions.

How does it work?

Once the Extension is enabled for your App and the Extension Settings are done, the recipients will receive metadata with the masked message. Here is a sample response:

"@injected": {
"extensions": {
"data-masking": {
"data": {
"sensitive_data": "yes",
"message_masked": "My number is ***** & my email id is ****"
}
}
}
}

If the data-masking key is missing, it means that the extension is either not enabled or has timed out.

Implementation

At the recipients' end, from the message object, you can fetch the metadata by calling the getMetadata() method. Using this metadata, you can fetch the masked message.

var metadata = message.getMetadata();
if (metadata != null) {
var injectedObject = metadata["@injected"];
if (injectedObject != null && injectedObject.hasOwnProperty("extensions")) {
var extensionsObject = injectedObject["extensions"];
if (
extensionsObject != null &&
extensionsObject.hasOwnProperty("data-masking")
) {
var dataMaskingFilterObject = extensionsObject["data-masking"]["data"];
var sensitive_data = dataMaskingFilterObject["sensitive_data"];
var message_masked = dataMaskingFilterObject["message_masked"];
}
}
}