mod_clamav

Uses clamd to scan all uploaded files for viruses.

The scanning happens after the mime type and access control is checked, but before the sanitization. If a file is infected then the error infected will be returned. The admin will display a growl message telling that the file was infected.

Clamd has a maximum size for checks, above that size the error sizelimit will be returned.

Configure in the zotonic.config file where clamd is listening.

The following configs are available:

clamav_ip

Address of clamd, default to "127.0.0.1". Set to socket to connect only to the Unix domain socket configured by clamav_socket, or set it to an absolute socket path to connect only to that socket. Socket-only connections never fall back to TCP.

clamav_port

Port of clamd, default to 3310

clamav_socket

Unix domain socket path of clamd, default to /run/clamav/clamd.ctl. When clamav_ip is a network address, the module tries this socket first and falls back to clamav_ip and clamav_port. Set to false or an empty string to use TCP only. When clamav_ip is socket, this is the exclusive socket path. The Zotonic process must have permission to connect to it. The path must match LocalSocket in clamd.conf.

clamav_max_size

The StreamMaxLength of clamd, default to 26214400 (25M)

clamav_reject_msoffice_external_links

Reject Microsoft Office documents containing externalLinks information. If the Zotonic config is set to false then rejection can be forced by setting the site’s config key mod_clamav.reject_msoffice_external_links to 1. Defaults to true.

All clamav results are logged, any infected files or other errors are logged to the error.log.

Every hour the module checks if it can reach clamd using the configured settings. It will log an error if clamd can’t be reached, and an info message if it can be reached.

The admin dashboard also checks connectivity asynchronously on each page load. If ClamAV cannot be reached, it displays a warning that file uploads are blocked until the scanner is available again.

Accepted Events

This module handles the following notifier callbacks:

  • observe_media_upload_preprocess: Check the uploaded file with clamav using z_acl:user.
  • observe_tick_1h: Periodic ping of clamav using the configured socket or TCP endpoint.

Edit on GitHub

Configuration

Configuration keys declared by this module. The defaults below are from the source code.

Module Key Type Default Description
mod_clamav clamav_reject_msoffice_external_links boolean false Reject MS Office files with external links. Set by the Zotonic config clamav_reject_msoffice_external_links (defaults to true), and if not set, can also be enabled by this config.

Observes

Notifications

observe_media_upload_preprocess/2

Notification to translate or map a file after upload, before insertion into the database Used in mod_video to queue movies for conversion to mp4. You can set…

Models

Models

clamav

Reports whether the ClamAV daemon ( clamd ) is available. The m.clamav.is_available model path sends a ping and returns true when the daemon responds with PONG…