Giter Club home page Giter Club logo

mjolnir's Introduction

mjolnir

A moderation tool for Matrix. Visit #mjolnir:matrix.org for more information.

Features

As an all-in-one moderation tool, it can protect your server from malicious invites, spam messages, and whatever else you don't want. In addition to server-level protection, Mjolnir is great for communities wanting to protect their rooms without having to use their personal accounts for moderation.

The bot by default includes support for bans, redactions, anti-spam, server ACLs, room directory changes, room alias transfers, account deactivation, room shutdown, and more.

A Synapse module is also available to apply the same rulesets the bot uses across an entire homeserver.

Setting up

See the setup documentation for first-time setup documentation.

See the configuration sample with documentation for detailed information about Mjolnir's configuration.

See the synapse module documentation for information on how to setup Mjolnir's accompanying Synapse Module.

Quickstart guide

After your bot is up and running, you'll want to run a couple commands to get everything set up:

  1. !mjolnir list create COC code-of-conduct-ban-list - This will create a new ban list with the shortcode COC and an alias of #code-of-conduct-ban-list:example.org. You will be invited to the room it creates automatically where you can change settings such as the visibility of the room.
  2. !mjolnir default COC - This sets the default ban list to the list we just created to help with the ban commands later on.
  3. Review the Moderator's Guide.
  4. Review !mjolnir help to see what else the bot can do.

Enabling readable abuse reports

Since version 1.2, Mjölnir offers the ability to replace the Matrix endpoint used to report abuse and display it into a room, instead of requiring you to request this data from an admin API.

This requires two configuration steps:

  1. In your Mjölnir configuration file, typically /etc/mjolnir/config/production.yaml, copy and paste the web section from default.yaml, if you don't have it yet (it appears with version 1.20) and set enabled: true for both web and abuseReporting.
  2. Setup a reverse proxy that will redirect requests from ^/_matrix/client/(r0|v3)/rooms/([^/]*)/report/(.*)$ to http://host:port/api/1/report/$2/$3, where host is the host where you run Mjölnir, and port is the port you configured in production.yaml. For an example nginx configuration, see test/nginx.conf. It's the confirmation we use during runtime testing.

Security note

This mechanism can extract some information from unencrypted rooms. We have taken precautions to ensure that this cannot be abused: the only case in which this feature will publish information from room foo is:

  1. If it is used by a member of room foo; AND
  2. If said member did witness the event; AND
  3. If the event was unencrypted; AND
  4. If the event was not redacted/removed/...

Essentially, this is a more restricted variant of the Admin APIs available on homeservers.

However, if you are uncomfortable with this, please do not activate this feature. Also, you should probably setup your production.yaml to ensure that the web server can only receive requests from your reverse proxy (e.g. localhost).

Development

TODO. It's a TypeScript project with a linter.

Development and testing with mx-tester

WARNING: mx-tester is currently work in progress, but it can still save you some time and is better than struggling with nothing.

If you have docker installed you can quickly get setup with a development environment by using mx-tester.

To use mx-tester you will need to have rust installed. You can do that at rustup or here, you should probably also check your distro's documentation first to see if they have specific instructions for installing rust.

Once rust is installed you can install mx-tester like so.

$ cargo install mx-tester

Once you have mx-tester installed you we will want to build a synapse image with synapse_antispam from the Mjolnir project root.

$ mx-tester build

Then we can start a container that uses that image and the config in mx-tester.yml.

$ mx-tester up

Once you have called mx-tester up you can run the integration tests.

$ yarn test:integration

After calling mx-tester up, if we want to play with mojlnir locally we can run the following and then point a matrix client to http://localhost:9999. You should then be able to join the management room at #moderators:localhost:9999.

yarn test:manual

Once we are finished developing we can stop the synapse container.

mx-tester down

Running integration tests

The integration tests can be run with yarn test:integration. The config that the tests use is in config/harness.yaml and by default this is configured to work with the server specified in mx-tester.yml, but you can configure it however you like to run against your own setup.

mjolnir's People

Contributors

alch-emi avatar chirayudesai avatar clokep avatar cremesk avatar dbkr avatar deepbluev7 avatar dependabot[bot] avatar dmrobertson avatar erikjohnston avatar gnuxie avatar grahamc avatar h-shay avatar half-shot avatar jae1911 avatar jaywink avatar jesopo avatar jojosch avatar jryans avatar mahdi1234 avatar maranda avatar natrius avatar neilmiddleton avatar no-realm avatar rasmusrendal avatar reivilibre avatar shadowjonathan avatar tanriol avatar turt2live avatar yoric avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mjolnir's Issues

Lots of duplicates in moderation room messages

After giving the error message about missing PL in certain rooms, the bot will start spamming the moderator room with messages, presumably because it's still trying to update there but failing
afbeelding

Command for arbitrary JS input?

For when the bot is missing a feature you really need, we could do light sandboxing and expose an instance of MatrixClient in a closure. Sanboxing would not be a huge concern because the command would only be available to moderators/managers of the bot.

Related: #17

M_LIMIT_EXCEEDED errors

And i get many of these errors:

  errcode: 'M_LIMIT_EXCEEDED',
  error: 'Too Many Requests',

This could be because of ratelimiting in synapse. Maybe a proper rc_admin_redaction value could solve the problem?

Feature request: Make the name Mjolnir responds to configurable.

How tricky would it be to make the name the Mjolnir bot responds to configurable? Calling it with !mjolnir works, to be fair, but when the account's not named mjolnir:matrix.example.com it can be a bit confusing, especially when the banhammer must be swung in broad arcs, if you catch my drift.

Being able to set an arbitrary name in the config file (like !anton or !nuke) but defaulting to !mjolnir would be really handy.

Add a Debian package

Hi,

I'd like to propose a feature request for a Debian package of mjolnir in https://packages.matrix.org/debian/. The rationale is that:

  1. I already and prefer to use this packages repository for synapse on my Debian server
  2. I prefer to avoid Docker
  3. Building mjolnir has the disavantage that I don't get automatic updates when there's a new release

Thanks for considering this feature request :).

The bot should resist banning/blocking itself

  • Don't let moderators set ACLs that prevent the bot from participating
  • Prevent globs from matching the bot's user ID (but still allow people to set rules like @*:*)
  • Don't let moderators demote the bot in rooms that are protected. Allow promotions though.

Crash from unhandled promise rejection when trying to join room without invite

Tue, 08 Oct 2019 09:16:59 GMT [DEBUG] [MatrixLiteClient (REQ-8)] qs = {}
Tue, 08 Oct 2019 09:16:59 GMT [DEBUG] [Metrics] matrix_client_function_call { functionName: 'doRequest', uniqueId: '1570526219330-18' } 333
Tue, 08 Oct 2019 09:16:59 GMT [DEBUG] [Metrics] matrix_client_function_call { functionName: 'getUserId', uniqueId: '1570526219330-17' } 333
Tue, 08 Oct 2019 09:16:59 GMT [DEBUG] [MatrixLiteClient (REQ-8 RESP-H403)] { errcode: 'M_FORBIDDEN',
  error: 'You are not invited to this room.' }
Tue, 08 Oct 2019 09:16:59 GMT [ERROR] [MatrixLiteClient (REQ-8)] { errcode: 'M_FORBIDDEN',
  error: 'You are not invited to this room.' }
Tue, 08 Oct 2019 09:16:59 GMT [DEBUG] [Metrics] matrix_client_function_call { functionName: 'doRequest', uniqueId: '1570526219660-19' } 286
Tue, 08 Oct 2019 09:16:59 GMT [DEBUG] [Metrics] matrix_client_function_call { functionName: 'joinRoom', uniqueId: '1570526219330-16' } 618
(node:23775) UnhandledPromiseRejectionWarning: #<IncomingMessage>
(node:23775) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:23775) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

unbans are not applied

Either I am misunderstanding something or it's broken, I have banned someone:

!mjolnir ban sunpy user @Nabobalis:matrix.org Test ban

the state event get's put in the ban list, and the bans are issued over all the rooms as expected.

running

!mjolnir unban sunpy user @Nabobalis:matrix.org true

removes the ban from the ban list but doesn't actually reverse the ban in any of the rooms. (This was the only ban in the ban list, so nothing else should be getting in the way).

Mjolnir could intercept the /report endpoint to do fancy things with it

Stuff like sending to moderators (a popular request) first, approve/disapprove of recommended actions, and general cataloguing.


We'd intercept the /report endpoint from Matrix at the reverse proxy level for the homeserver, and do things with it. Common requests are documented in the comment below.

Provide a docker container with pantalaimon

It would be nice to have a docker container preconfigured with pan installed, so that it can be easily activated in some manner. Either in the main container or a separate tag.

The ban command could be smarter

!mjolnir ban tos user @example:example.org is fairly complicated to remember, particularly when you flip the order of the arguments by accident. Instead, the bot should support a default ban list in the room to make the shortcode optional and it should discern the entity from the thing being banned, optionally.

This would make the command work for:

  • !mjolnir ban @example:example.org
  • !mjolnir ban tos @example:example.org
  • !mjolnir ban user @example:example.org
  • !mjolnir ban tos user @example:example.org

Setup and documentation improvements

Hi,

thank you for your great job and this cool software!
I just want to leave some suggestions for improvements and say where the setup needs some explanation:

  • Explain where to get access token. When logging in to riot, copy the access key and log out, the access key is outdated
  • Docker container refused to start until i deleted /config/default.yaml even if production.yaml exists
  • Docker container refused to start when not having set "protectedRooms" even if protectedAllJoinedRooms is set to true
  • Explain how to kill container and/or to run in background when started like in your documentation
  • Explain how to set up ACL and ban lists

fallback text/rendering for Riot

It would be nice if Riot can render the rule events, so I can join someone else's banlist room, and keep track manually, without giving their banlist full control over my room

yarn build fails with 4 errors

Following the instructions in the readme, I get this from yarn build:

yarn run v1.19.0
$ tsc
src/index.ts:22:5 - error TS2305: Module '"../node_modules/matrix-bot-sdk/lib"' has no exported member 'PantalaimonClient'.

22     PantalaimonClient,
       ~~~~~~~~~~~~~~~~~

src/index.ts:54:38 - error TS2339: Property 'parseUrl' does not exist on type 'typeof Permalinks'.

54         const permalink = Permalinks.parseUrl(roomRef);
                                        ~~~~~~~~

src/index.ts:69:38 - error TS2339: Property 'parseUrl' does not exist on type 'typeof Permalinks'.

69         const permalink = Permalinks.parseUrl(roomRef);
                                        ~~~~~~~~

src/models/ListRule.ts:17:28 - error TS2307: Cannot find module 'matrix-bot-sdk/lib/MatrixGlob'.

17 import { MatrixGlob } from "matrix-bot-sdk/lib/MatrixGlob";
                              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


Found 4 errors.

node v12.11.0
yarn 1.19.0

Fix the help menu

It's awful. Take inspiration from Trello bot?

Possibly on !mjolnir help show a quick summary from the moderator's guide, then on !mjolnir help all give the giant thing.

Support requiring multiple confirmations before a ban is issued

This takes two forms:

  1. Literally the entity has to match N rules before they'll be banned, across any number of lists.
  2. The entity must match N lists before they'll be banned. The lists valid for counting N might be specified by the moderation team.

Multiple confirmations are useful for communities who want to subscribe to another community's lists, but don't want to subject control of their rooms to that community. A good example of this is any community which wants to use the matrix.org homeserver lists, but isn't willing to let us ban whoever we want in their rooms.

Mjolnir could support pluggable protections through state events

Limited tightly in scope to the management room, there could be state events which have arbitrary bits of JS in them to process messages. The state key could be the protection name (with some sort of prefix to avoid clashes with the official ones?). The JS would be a function which takes some sort of arguments to do the processing. For instance:

return async function(mjolnir, roomId, event) {
    // Do work
    return Promise.resolve();
};

This is relatively safe because the only way to pwn the bot is to be a moderator, who already has the power to !mjolnir ban @* lol if they wanted to.

A version number should be in the event content for future iterations. Mjolnir will not make any guarantees about API compatibility, so maybe it needs a "compatible version number" too?

Startup failures are not reported to the room

An instance of the bot failed the list sync due to a 500 on resolving the room alias of a ban list. The bot never reported this failure to the management room, though the silence of it indicated failure.

It should report the problem to the room, and if it fails to report the problem to the room, crash.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.