Skip to main content

Virus and Malware Scanner

The Virus & Malware Scanner Extension allows the developer to scan files uploaded by users so that a warning can be added for malicious content.

Before you begin

This Extension uses a third-party API service - Scanii - to scan media messages. Create an account with Scanii API Service and get your pair of API Key and Secret.

Extension settings

  1. Login to CometChat and select your app.
  2. Go to the Extensions section and enable the Virus and Malware Scanner extension.
  3. Open the Settings for this extension.
  4. Enter Scanii API Key and Scanii Secret and click on save.

How does it work?

Once the Extension is enabled for your App and the Extension Settings are saved, the recipients will receive metadata with an array of results.

The Virus Scan results will be updated later for the message and hence you need to implement the onMessageEdited listener. Please check the Edit a Message page under the Messaging section of each SDK for more details.

This can be used to show warning messages:

{
"@injected": {
"extensions": {
"virus-malware-scanner": {
"attachments": [
{
"data": {
"url": "https://media.com/1646056756_400568974.mp3",
"name": "a2.mp3",
"size": 1519658,
"verdict": {
"scan_results": [],
},
"mimeType": "audio/mpeg",
"extension": "mp3",
},
"error": null,
},
{
"data": {
"url": "https://media.com/1646056756_400568933.mp3",
"name": "a1.mp3",
"size": 1519658,
"mimeType": "audio/mpeg",
"extension": "mp3",
"verdict": null
},
"error": {
"code": "ERROR_CODE",
"message": "Error Message",
"devMessage": "Error message",
"source": "ext-api"
}
}
],
"scan_results": [],
},
},
},
}

If the scan_results is an empty array, it means the message is safe.

If the virus-malware-scanner key is missing, then either the extension is not enabled or your Scanii credits are over.

info

The scan_results, to the outside of attachments are the result for the first attachment from the attachments array. This has been retained for backward compatibility only.
You can iterate over attachments array for better implementation.

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 Rich Media Embed.

const metadata = message.getMetadata();
if (metadata != null) {
const injectedObject = metadata["@injected"];
if (injectedObject != null && injectedObject.hasOwnProperty("extensions")) {
const extensionsObject = injectedObject["extensions"];
if (
extensionsObject != null &&
extensionsObject.hasOwnProperty("virus-malware-scanner")
) {
const { attachments } = extensionsObject["virus-malware-scanner"];
for (const attachment of attachments) {
if (!attachment.error) {
const { scan_results } = attachment.data.verdict;
// Check the other parameters as required.
}
}
}
}
}