Skip to main content

Matrix Content Scanner

A web service for scanning media hosted on a Matrix media repository.

Installation

This project requires libmagic to be installed on the system. On Debian/Ubuntu:

sudo apt install libmagic1

Then, preferably in a virtual environment, install the Matrix Content Scanner:

pip install matrix-content-scanner

Usage

Copy and edit the sample configuration file. Each key is documented in this file.

Then run the content scanner (from within your virtual environment if one was created):

python -m matrix_content_scanner.mcs -c CONFIG_FILE

Where CONFIG_FILE is the path to your configuration file.

Docker

This project provides a Docker image to run it, published as vectorim/matrix-content-scanner.

To use it, copy the sample configuration file into a dedicated directory, edit it accordingly with your requirements, and then mount this directory as /data in the image. Do not forget to also publish the port that the content scanner's Web server is configured to listen on.

For example, assuming the port for the Web server is 8080:

docker run -p 8080:8080 -v /path/to/your/config/directory:/data vectorim/matrix-content-scanner

API

See the API documentation for information about how clients are expected to interact with the Matrix Content Scanner.

Migrating from the legacy Matrix Content Scanner

Because it uses the same APIs and Olm pickle format as the legacy Matrix Content Scanner, this project can be used as a drop-in replacement. The only change (apart from the deployment instructions) is the configuration format:

  • the server section is renamed web
  • scan.tempDirectory is renamed scan.temp_directory
  • scan.baseUrl is renamed download.base_homeserver_url (and becomes optional)
  • scan.doNotCacheExitCodes is renamed result_cache.exit_codes_to_ignore
  • scan.directDownload is removed. Direct download always happens when download.base_homeserver_url is absent from the configuration file, and setting a value for it will always cause files to be downloaded from the server configured.
  • proxy is renamed download.proxy
  • middleware.encryptedBody.pickleKey is renamed crypto.pickle_key
  • middleware.encryptedBody.picklePath is renamed crypto.pickle_path
  • acceptedMimeType is renamed scan.allowed_mimetypes
  • requestHeader is renamed download.additional_headers and turned into a dictionary.

Note that the format of the cryptographic pickle file and key are compatible between this project and the legacy Matrix Content Scanner. If no file exist at that path one will be created automatically.

Development

In a virtual environment with poetry (>=1.8.3) installed, run

poetry install

To run the unit tests, you can use:

tox -e py

To run the linters and mypy type checker, use ./scripts-dev/lint.sh.

Releasing

The exact steps for releasing will vary; but this is an approach taken by the Synapse developers (assuming a Unix-like shell):

  1. Set a shell variable to the version you are releasing (this just makes subsequent steps easier):

    version=X.Y.Z
    
  2. Update setup.cfg so that the version is correct.

  3. Stage the changed files and commit.

    git add -u
    git commit -m v$version -n
    
  4. Push your changes.

    git push
    
  5. When ready, create a signed tag for the release:

    git tag -s v$version
    

    Base the tag message on the changelog.

  6. Push the tag.

    git push origin tag v$version
    
  7. Create a release, based on the tag you just pushed, on GitHub or GitLab.

  8. Create a source distribution and upload it to PyPI:

    python -m build
    twine upload dist/matrix_content_scanner-$version*
    

Metadata

Release files for matrix-content-scanner 1.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for matrix-content-scanner 1.4.0
File Size Uploaded
matrix_content_scanner-1.4.0.tar.gz 63.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for matrix-content-scanner 1.4.0
File Interpreter ABI Platform
matrix_content_scanner-1.4.0-cp314-cp314-manylinux_2_40_x86_64.whl CPython 3.14 CPython 3.14 Linux glibc 2.40+ x86-64 Details

Total release size: 558.4 kB

Release files / matrix_content_scanner-1.4.0.tar.gz

Download URL matrix_content_scanner-1.4.0.tar.gz
Size 63.3 kB
Tags Source
SHA-256 checksum
How to use checksums
0cc160edba304dcccce505d47a8bf34119fa1fa6b04a669afa6d1775921f2477
BLAKE2b-256 checksum
How to use checksums
452108043bada8a2e0aff9b828a079aedccb8bdfd494bc4dd6c188e295253cde
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.2

Release files / matrix_content_scanner-1.4.0-cp314-cp314-manylinux_2_40_x86_64.whl

Download URL matrix_content_scanner-1.4.0-cp314-cp314-manylinux_2_40_x86_64.whl
Size 495.1 kB
Tags CPython 3.14 Linux glibc 2.40+ x86-64
SHA-256 checksum
How to use checksums
7fa9ea96c343b81714a736b78968cd4cd4eb703d38b47013e6a241b95a617062
BLAKE2b-256 checksum
How to use checksums
0ad6ee56939f2b966180e846ea9e270048013f6dd8ed953cff61295935e525c5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.2

Release history Release notifications | RSS feed

1.4.1

2 release files

This release

1.4.0 This release

2 release files

1.3.0

2 release files

1.2.1

2 release files

1.2.0

2 release files

1.1.0

2 release files

1.0.8

2 release files

1.0.7

2 release files

1.0.6

2 release files

1.0.5

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page