logo
logo

Antivirus scan

An antivirus scan is a component of an antivirus package that scans files for viruses and other harmful items. Sitecore Content Hub™ has an antivirus scan functionality that triggers when users upload assets, either through the Creation component, or Excel import.

As a superuser, you can configure the antivirus scan in media processing. This document describes how to set it up.

Enable antivirus

To enable the antivirus scan:

  1. On the main menu bar, click Manage .
  2. On the Manage page, click Settings.
  3. On the Settings page, search for Antivirus.
  4. Search and select the AntivirusSetting.
  5. On the AntivirusSetting, set the antivirusEnabled flag to true.
  6. Click Save.

Configure an antivirus task

Because the antivirus scan functionality makes a call to an external service API, you need to configure a RunExternalWebTask processing task. You add this task to the M.MediaMatrix of the media flow you want to configure.

Note

An external web task is a webhook that Content Hub uses in file processing to create custom renditions (pre-defined file conversions).

To create a task under a media flow:

  1. On the main menu bar, click Manage .
  2. On the Manage page, click Entities.
  3. Search and select the M.MediaMatrix entity you want to configure.
  4. On the Media Matrix entities page, on the Content item, click View detail.
  5. On the Entity detail page, click Edit .
  6. Select the Text view of the matrix.
  7. Add your task code.
  8. Click Save.

The following is a code example used for the Images flow:

```javascript
"tasks": {
       "antivirus": {
             "type": "RunExternalWebTask",
             "do_update": true,
             "input": "source",
             "output": "antivirus",
             "outputfileprovider": "local",
             "contentdisposition": "attachment",
             "url": "https://example.beeceptor.com",
             "parameters": {},
             "headers": {}
             }
```
Note

The URL corresponds to the endpoint of the REST API. The URL provided in this example is from Beeceptor, which is used as a mock REST API replacing the endpoint.

Task order

Within a media flow, Content Hub processes the other tasks after the antivirus task is completed, so you need to ensure the other tasks are dependent on the antivirus task.

Add the following line of code in the other tasks to make them dependent:

"deps": [
    "antivirus"
]

By default, the input of a dependent task is the output of the previous task. This means the rendition tasks use the antivirus scan result as input. The antivirus result is a string, which should be the initial file (such as images or pdf).

To configure the antivirus result, you need to set the input property of the rendition tasks to source. This forces the tasks to use the initial uploaded file as input.

Store antivirus output

The external web antivirus task needs to communicate with an Azure function that handles all the API calls and responses. Content Hub expects a returned value of Ok or Malicious.

Note

If a file is flagged as malicious, all the renditions are deleted and a placeholder replaces the thumbnail and all other renditions. The Download option is also disabled.

To configure the matrix to store the output in the antivirus property of the file, add the following line of code:

"properties": {
    "VirusScanResult": "antivirus"
}

Configuration example

The following example fully configures the Images flow. It uses the Beeceptor URL as a mock REST API, replacing the endpoint URL in the code:

{
    "name": "Images",
    "priority": 100,
    "extensions": [
      "bmp",
      "cr2",
      "dng",
      "erf",
      "gif",
      "jpeg",
      "jpg",
      "nef",
      "orf",
      "raf",
      "raw",
      "srw",
      "tga",
      "webp"
    ],
    "flow": {
      "tasks": {
        "antivirus": {
          "type": "RunExternalWebTask",
          "do_update": true,
          "input": "source",
          "output": "antivirus",
          "outputfileprovider": "local",
          "contentdisposition": "attachment",
          "url": "https://example.beeceptor.com",
          "parameters": {},
          "headers": {}
        },
        "metadata": {
          "type": "ExtractMetadata",
          "deps": [
            "antivirus"
          ],
          "input": "source",
          "output": "metadata",
          "outputfileprovider": "local",
          "contenttype": "application/json",
          "contentdisposition": "attachment"
        },
        "pdf": {
          "type": "ConvertImage",
          "deps": [
            "antivirus"
          ],
          "input": "source",
          "output": "pdf",
          "outputfileprovider": "local",
          "contenttype": "application/pdf",
          "contentdisposition": "inline",
          "imageresizeoption": "DoNotResize",
          "targetextension": "pdf",
          "density": 72
        },
        "preview": {
          "type": "ConvertImage",
          "deps": [
            "antivirus"
          ],
          "input": "source",
          "output": "preview",
          "outputfileprovider": "local",
          "outputproperties": [
            "width",
            "height"
          ],
          "contenttype": "image/jpeg",
          "contentdisposition": "inline",
          "imageresizeoption": "OnlyShrinkLargerImages",
          "targetextension": "jpg",
          "width": 1100,
          "height": 1100,
          "colorprofile": "sRGB",
          "density": 72
        },
        "bigthumbnail": {
          "type": "ConvertImage",
          "deps": [
            "preview"
          ],
          "input": "preview",
          "output": "bigthumbnail",
          "outputfileprovider": "local",
          "contenttype": "image/jpeg",
          "contentdisposition": "inline",
          "imageresizeoption": "OnlyShrinkLargerImages",
          "targetextension": "jpg",
          "width": 400,
          "height": 400,
          "colorprofile": "sRGB",
          "density": 72
        },
        "thumbnail_cropped": {
          "type": "ConvertImage",
          "deps": [
            "preview"
          ],
          "input": "preview",
          "output": "thumbnail_cropped",
          "outputfileprovider": "local",
          "contenttype": "image/jpeg",
          "contentdisposition": "inline",
          "imageresizeoption": "ResizeForCrop",
          "targetextension": "jpg",
          "width": 200,
          "height": 200,
          "colorprofile": "sRGB",
          "density": 72
        },
        "thumbnail": {
          "type": "ConvertImage",
          "deps": [
            "preview"
          ],
          "input": "preview",
          "output": "thumbnail",
          "outputfileprovider": "local",
          "outputproperties": [
            "width",
            "height"
          ],
          "contenttype": "image/jpeg",
          "contentdisposition": "inline",
          "imageresizeoption": "OnlyShrinkLargerImages",
          "targetextension": "jpg",
          "width": 150,
          "height": 150,
          "colorprofile": "sRGB",
          "density": 72
        },
        "preview_download": {
          "type": "StoreFile",
          "deps": [
            "preview"
          ],
          "input": "preview",
          "output": "preview_download",
          "outputfileprovider": "local",
          "contenttype": "image/jpeg",
          "contentdisposition": "attachment"
        }
      }
    },
    "output": {
      "location": "local",
      "renditions": {
        "Renditions": {
          "metadata": {
            "file": "metadata",
            "sticky": true,
            "initial": {
              "status": "pending"
            }
          },
          "pdf": {
            "file": "pdf",
            "initial": {
              "status": "pending"
            }
          },
          "preview": {
            "file": "preview",
            "properties": [
              "width",
              "height"
            ],
            "initial": {
              "status": "pending"
            }
          },
          "preview_download": {
            "file": "preview_download",
            "initial": {
              "status": "pending"
            }
          },
          "thumbnail": {
            "file": "thumbnail",
            "properties": [
              "width",
              "height"
            ],
            "initial": {
              "status": "pending"
            }
          },
          "thumbnail_cropped": {
            "file": "thumbnail_cropped",
            "initial": {
              "status": "pending"
            }
          },
          "bigthumbnail": {
            "file": "bigthumbnail",
            "initial": {
              "status": "pending"
            }
          }
        }
      },
      "properties": {
        "VirusScanResult": "antivirus"
      }
    }
  }

The following images show how the example configuration changes made to the Images flow in the media matrix reflect on the Media Processing page.

The antivirus task is visible at the origin of the flow (showing the other tasks are dependent on it):

The parameters are as follows:

The output is as follows:

  • Output: Property.
  • Property: Virusscan result.

Note

If you make any changes to a flow on the Media Processing page, saving them overwrites any changes previously made to the M.MediaMatrix entity back to the default input value of dependent tasks.

Can we improve this article ? Provide feedback