Skip to main content

A Synapse module that forwards spam checking to an HTTP server

Project description

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".

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

synapse_http_antispam-0.5.0.tar.gz (5.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

synapse_http_antispam-0.5.0-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

Details for the file synapse_http_antispam-0.5.0.tar.gz.

File metadata

  • Download URL: synapse_http_antispam-0.5.0.tar.gz
  • Upload date:
  • Size: 5.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for synapse_http_antispam-0.5.0.tar.gz
Algorithm Hash digest
SHA256 566f6d32c5a005ef6054d9b0f5a6c8c7ed428ef42f2d238ba5ba3ae956d5ecc0
MD5 5f1044fc8946ddc44224d79f868c6110
BLAKE2b-256 4c891155c646f1d4f6f6d1001b4fd110be59c3d80a7b83bb2983d404b70bf3bc

See more details on using hashes here.

File details

Details for the file synapse_http_antispam-0.5.0-py3-none-any.whl.

File metadata

File hashes

Hashes for synapse_http_antispam-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 44e6db338c376c1427ba3831f746a93b8985783c1931bf429f64286ffa8569e5
MD5 71ca14ab87fa6f3512812fdecc601444
BLAKE2b-256 20e0e3bd19307733885b73d3729eb29b012e7100604f414b62c5f5b705a736d5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page