Skip to main content

synapse-http-antispam

A Synapse spam checker module that forwards requests to an HTTP server.

Discussion

This project was written for use with Meowlnir, so it can be discussed in the Meowlnir room: #meowlnir:maunium.net

Installation

In the Python environment where Synapse is installed:

pip install synapse-http-antispam

or if you want the main branch instead of the last release:

pip install synapse-http-antispam@git+https://github.com/maunium/synapse-http-antispam.git

Installation with Synapse Debian packages

The upstream Debian packages for Synapse create a virtualenv in /opt/matrix-synapse. You must install the module inside that virtualenv, not globally on the system.

Installation inside Docker

You can make your own overlay image to install the module:

FROM matrixdotorg/synapse

RUN pip install synapse-http-antispam

Alternatively, you can create a bind mount at runtime, e.g.

docker run -v /path/to/synapse_http_antispam.py:/usr/local/lib/python3.12/site-packages/synapse_http_antispam.py:ro ...

(you need to acquire synapse_http_antispam.py yourself and may need to adjust the python version in the path)

Configuration reference

The exact callbacks to enable depend on what you want to do with antispam. Most users should not read these docs and should instead refer to the docs of whatever antispam server they have. For example, if you want to block invites, refer to the Meowlnir or Draupnir docs.

If you want to write your own antispam server or just want to find out all available options, continue reading here.

Reference for the module configuration in homeserver.yaml:

modules:
  - module: synapse_http_antispam.HTTPAntispam
    config:
      base_url: http://localhost:8080
      authorization: random string
      do_ping: true
      enabled_callbacks:
        - user_may_invite
      async:
        user_may_join_room: true
      fail_open:
        check_event_for_spam: true

If enabled_callbacks is not specified, all callbacks will be enabled.

See https://element-hq.github.io/synapse/v1.126/modules/spam_checker_callbacks.html for the list of available callbacks. All callbacks except check_media_file_for_spam, check_registration_for_spam and should_drop_federated_event are available.

The module will make HTTP requests to <base_url>/<callback_name> with all function parameters as JSON fields. The authorization field will be sent as a Authorization: Bearer <value> header if specified.

The response body must always be JSON. Any 2xx response will be return NOT_SPAM to Synapse. The content of 2xx responses is ignored, so an empty object is sufficient. Any other response is treated as a rejection and the response body will be returned to the client as-is. If the errcode field is not present in error responses, it will default to M_FORBIDDEN.

If the server returns a non-JSON response or if the request fails, the module will fail closed and reject the callback with an M_UNKNOWN error by default, except for callbacks specified in fail_open. Additionally, the check_event_for_spam callback will fail open by default, unless set to false in fail_open.

Any callbacks set to true in the async map will be executed in the background and will always return NOT_SPAM to Synapse. The response status and data will be ignored for async callbacks.

if do_ping is set to true, the module will call the ping callback with an id field, expecting a response with the same ID and "status": "ok".

Metadata

Release files for synapse-http-antispam 0.5.1

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

Source distribution (sdist)

Source distribution for synapse-http-antispam 0.5.1
File Size Uploaded Provenance
synapse_http_antispam-0.5.1.tar.gz 6.1 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for synapse-http-antispam 0.5.1
File Interpreter ABI Platform
synapse_http_antispam-0.5.1-py3-none-any.whl Python 3 none any Details

Total release size: 11.9 kB

Release files / synapse_http_antispam-0.5.1.tar.gz

Download URL synapse_http_antispam-0.5.1.tar.gz
Size 6.1 kB
Tags Source
SHA-256 checksum
How to use checksums
ed92fcf6c4a6168acc0972bb2151a7937893f1d0957727ae9cb510a3a922049f
BLAKE2b-256 checksum
How to use checksums
c6d7ce041a00b4eebdaf789bf9ba53187652f3919d5aac0a2a831d6381eda174
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.4

Release files / synapse_http_antispam-0.5.1-py3-none-any.whl

Download URL synapse_http_antispam-0.5.1-py3-none-any.whl
Size 5.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
324fbb8a7b79ade34d2414f41cf9c6b0f6b219d62aec0a5a599fa5a1ab12648c
BLAKE2b-256 checksum
How to use checksums
ccbe57946a6d6e75a17a2c977a9a1191ffc816feb7157ec89433fe6e5ec0468f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.4

Security for synapse-http-antispam 0.5.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

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