Commit Graph

252 Commits

Author SHA1 Message Date
Jess Porter
b03d81dcc4
ability to disable displaying new reports in moderation room (#320) 2022-07-07 12:55:03 +01:00
Gnuxie
b850e4554c
Remove debug leftovers from a test. (#314)
* Remove debug leftovers from a test.

This is really terrible and has meant whenever anyone has run `yarn test:integration` they have only been running this test.
💀💀💀
https://www.youtube.com/watch?v=jmX-tzSOFE0

* Set a default timeout for integration tests that is 5 minutes long.

Seriously, I don't think there is much to gain by making people guess
a reasnoble time for a test to complete in all the time, especially
with how much Synapse changes in response time and all of the machines
involved in running these tests.

* Warn when giving up on being throttled

* For some reason it takes longer for events to appear in /state

no i am not going to track down why yet.

* Rate limiting got a lot more aggresive.

https://github.com/matrix-org/synapse/pull/13018

Rate limiting in Synapse used to reset the burst count and remove
the backoff when you were spamming continuously, now it doesn't.
Ideally we'd rewrite the rate limiting logic to back off for longer
than suggested so we could get burst again, but for now
lets just unblock CI by reducing the number of events we send in these
tests.
2022-07-06 14:20:25 +01:00
Jess Porter
ed68e02c4e
implement polling reports in synapse (#259) 2022-07-04 15:06:36 +01:00
gnuxie
d7b846cdb3 Remove duplicated kick from kick command (merging cleanup)
Accidentally introduced while merging https://github.com/matrix-org/mjolnir/pull/291.
2022-06-15 12:34:59 +01:00
Jae Lo Presti
a876a05520
Glob kick command (#291)
This pull requests adds for glob support in the `!mjolnir kick` command.

## Example
```
!mjolnir kick @*:domain.tld <reason> --force
```
This command will kick every user having a mxid matching `domain.tld`.  
You can also still kick a particular user:
```
!mjolnir kick @user:domain.tld <reason>
```

## Tests:
Tested on the Furry Tech room (`vRGLvqJYlFvzpThbxI:matrix.org`) after a spam wave.  
It kicked over 13k bots in a matter of hours without putting too much strain on the homeserver.  
For instance, this command was matching `@spam*`:
![image](https://user-images.githubusercontent.com/76598503/167320002-f0575f50-4b54-41d1-8220-f67d72ccaf16.png)

  
  
Signed-off-by: Jae Lo Presti <me@jae.fi>
2022-06-15 12:20:27 +01:00
David Teller
0eea04bd69
A background queue for kicking (#296)
A background queue for kicking
2022-06-08 11:49:43 +02:00
Gnuxie
558cbb3cae
Remove the need to call /initialSync in getMessagesByUserIn. (#297)
* Remove the need to call `/initialSync` in `getMessagesByUserIn`.

At the moment we call `/initialSync` to give a `from` token to `/messages`.
In this PR we instead do not provide a `from` token when calling `/messages`,
which has recently been permitted in the spec
Technically this is still unstable in the spec
https://spec.matrix.org/unstable/client-server-api/#get_matrixclientv3roomsroomidmessages
https://github.com/matrix-org/matrix-spec/pull/1002

Synapse has supported this for over 2 years and Element web depends on it for threads.
https://github.com/matrix-org/matrix-js-sdk/pull/2065

Given that redactions are super heavy in Mjolnir already and have been reported
as barely functional on matrix.org I believe we should also adopt this approach as
if for some reason the spec did change before the next release (1.3) (extremely unlikely) we can revert this commit.
2022-05-24 11:16:52 +01:00
David Teller
bcc3405e51
Revert "Fix traceback on Abuse Report. (#230)" (#293)
This reverts commit 27ae3ec625.
2022-05-13 15:29:49 +02:00
Marco Cirillo
27ae3ec625
Fix traceback on Abuse Report. (#230)
* Have the callback work on the packed event Obj.

And also explicitly pack the Mjolnir object inside the event.

* Add VS ignores.

* Commit suggested review changes.

- Add bind to callback
- Add type cast for event packed object

* Fix missing parenthesis.

* Don't pass Mjolnir obj to handleReport().

Co-authored-by: David Teller <davidt@element.io>
2022-05-13 15:18:30 +02:00
David Teller
74d8caa7e7
Since command: adding the ability to mute (#272) 2022-05-10 17:19:16 +02:00
Jonathan de Jong
9fce35c000
Add Join Wave Short-Circuit Protection (#280)
* Add Short Circuit Protection

* fix module name

* change to dynamic timescales

* address feedback
2022-05-06 09:24:34 +01:00
Gnuxie
c8caf744c5
Apply members and server bans to the most recently active rooms first. (#274)
* Apply members and server bans to the most recently active rooms first.

https://github.com/matrix-org/mjolnir/issues/273
2022-05-03 12:36:53 +01:00
Gnuxie
f63edbefa0
Make startup failures more controlled and understandable. (#270)
There is no reason to call process.exit() from `index.ts` or in `Mjolnir.start()` because

https://nodejs.org/api/process.html#warning-using-uncaughtexception-correctly

>The 'uncaughtException' event is emitted when an uncaught JavaScript exception bubbles all the way back to the event loop. By default, Node.js handles such exceptions by printing the stack trace to stderr and exiting with code 1, overriding any previously set process.exitCode. Adding a handler for the 'uncaughtException' event overrides this default behaviour.
2022-04-01 16:40:10 +01:00
jesopo
fccb4627ce show room ID in consequence log 2022-03-21 14:25:12 +00:00
jesopo
afd003b905 remove line leftover from debugging 2022-03-21 14:11:45 +00:00
David Teller
e05616b327
New command !mjolnir since <date or duration> <kick | ban | show> <limit> [reason] [...rooms] (#238)
A new command `since` to affect all users who have joined a protected room since a given date.
2022-03-21 10:39:15 +01:00
Jess Porter
1880287ac4
standard protection consequences (#232)
* standard protection consequences

* add integration test to make sure good users aren't banned

* the less far `event` propagates, the better

* better document consequence.ts

* improve innocent user integration test

* switch to room.event emit
2022-03-18 10:11:23 +00:00
David Teller
26ae55cd24
A command to show when users in a given room have joined (#225) 2022-03-07 11:34:25 +01:00
Marco Cirillo
97df4d5f61
Add command to elevate a user (or the bot) as room administrator (#219) 2022-03-07 10:14:06 +01:00
jesopo
65af82d46f send whole channel shutdown reason, not just the first word 2022-03-02 10:20:43 +00:00
David Teller
eb7f5f6b3e
Reduce stackspam (#237)
This should cut a lot on the noise in logs.
2022-02-25 17:59:34 +01:00
David Teller
82a2e63d23
A room Protection designed to measure lag in a room (#217) 2022-02-24 13:43:31 +01:00
Gnuxie
332da15d0d
Remove old rules when unbanning entities from BanLists. (#227)
* Remove old rules when unbanning entities from BanLists.

Fixes #220
2022-02-21 16:51:14 +00:00
Jess Porter
a58c7d3f1a
move LogProxy.logMessage to Mjolnir.logMessage (#194) 2022-02-15 15:44:41 +00:00
Gnuxie
e9dff8fd5a
Batch events from ban lists together during sync (#221)
* Test for batching ACL.

* Batch events from sync within BanList.

* Introduce the BanList.batch event to the BanList emitter to let Mjolnir sync after new events have been added from sync.

Fixes #203
2022-02-15 13:51:20 +00:00
Marco Cirillo
097829d75a
Set missing CORS headers for Report API responses. (#222) 2022-02-15 09:19:13 +01:00
Jess Porter
f74cf8a6e5
trusted reporters (#183)
* Trusted Reporters protection

* redact/ban reasons

* some documentation
2022-02-08 13:07:42 +00:00
Gnuxie
ff9a7db159
Make ACL safe so that Mjolnir will not ban itself. (#213) 2022-02-07 17:02:06 +00:00
jesopo
813741c42c refactor (and simplify) how protections are stored in-memory 2022-02-07 13:48:32 +00:00
jesopo
8b23f93b71 splice returns removed items, not a new list with items removed 2022-02-07 13:33:44 +00:00
Jess Porter
58e228be7d
make roomIds param on replaceRoomIdsWithPills a Set<string> (#146) 2022-02-02 17:35:02 +00:00
Jess Porter
f70d97e4d9
enable noImplicitAny (#209) 2022-02-02 12:43:05 +00:00
Gnuxie
8a9ded80c1
do not require rule server config to be present. (#208) 2022-02-01 13:20:26 +00:00
Jess Porter
423a34bebe
runtime persistent settings system (#158) 2022-01-25 14:47:50 +00:00
David Teller
c7a96a3afe
Retry requests in case of throttling (#178)
* Retry requests in case of throttling


Co-authored-by: gnuxie <gnuxie@element.io>
2022-01-25 12:19:44 +00:00
gnuxie
1a65122b0d Initial Ruleserver prototype.
This is an experimental ruleserver that will serve the combined rules from
the active policy lists to a Synapse module over a web api.
This makes it easier to communicate changes in policy lists to Synapse workers
that do not have an immediate view over all of the policy rooms at
the same time.
This also allows us to express moderation actions to the homeserver
beyond what is currently expressible via MSC2313 policy
lists.
2022-01-21 12:13:04 +00:00
gnuxie
6a723eaa1b Stop reacting to reports Mjolnir didn't send in report manager. 2022-01-18 11:08:17 +00:00
Jess Porter
941d10b015
never mutate config.managementRoom in-place (#184) 2022-01-17 16:24:12 +00:00
David Teller
a88a494f7a Let's not overwrite the error message when we're fixing the stack. 2022-01-07 14:06:10 +01:00
David Teller
c48a1e8ffc Let's make sure that we can still check for errors with concise error handling 2022-01-07 14:06:10 +01:00
David Teller
3f2039f6a7 Let's use getRequestFn/setRequestFn to keep errors readable 2022-01-07 14:06:10 +01:00
David Teller
9a8fed1695 Slightly cleaner MatrixClient wrapping 2022-01-07 14:06:10 +01:00
David Teller
57746f7fb4 Wrap MatrixClient into something that displays nicer error messages 2022-01-07 14:06:10 +01:00
David Teller
1592440bc9
Abuse Report UX: Keep the text shorter (#152)
* Abuse Report UX: Keep the text shorter

* ReportManager: Clarifying why some actions are disabled
2021-12-10 09:09:32 +01:00
gnuxie
33011ddb04 Store BanList rules only in the room state cache.
We do this so that there is only one source of truth for which rules
are active and it simplifies de-duplicating rules of conflicting event
types (e.g. m.room.rule.user vs m.policy.rule.user).
2021-11-29 11:45:22 +00:00
gnuxie
0bbfe93a4b Use MSC2313 m.policy.rule.* for rules and always prefer these types.
The reason for doing this is because otherwise there may be duplicate
rules under different state types for the same entity.
This simplifies the process of modifying or invalidating rules affecting
an entity because the rule with the most recent type will always be
preferred.
2021-11-29 11:45:22 +00:00
gnuxie
9c47fc917a Provide notice showing how a BanList has changed after updating.
Only shows changes to lists made by other accounts (than the one used by Mjolnir).
Displays when rules are added, removed and modified by either replacing the state event or redacting them.
2021-11-29 11:45:22 +00:00
David Teller
a21415a04c
Give the ability to moderators to react quickly to /report abuse reports. (#137) 2021-11-09 13:15:49 +01:00
gnuxie
911707ab2e await the callback in getUserMessagesIn
This is so that the context of failing callbacks are not lost.
We also await during pagination and not after so that if a call to the callback fails, we will not call it again.
2021-10-20 11:00:44 +01:00
gnuxie
fefe29e98b Improve readability of getMessagesByUser 2021-10-20 11:00:44 +01:00
gnuxie
743f6d043a Fix filter when paginating history in getMessagesByUser.
Related to https://github.com/matrix-org/mjolnir/pull/132.
The old code would call `/sync` with this filter. If a token was
provided in the response of `/sync` for earlier messages, it would
then use this same filter to call `/rooms/messages`. However, this
filter does not do anything on that endpoint when we know the id of
the sender, as it requires a RoomEventFilter and there is no warning
or error from synapse about the structure of the filter being wrong.
This was not noticed until after the related PR because `/sync` with
the filter would usually be able to provide a user's
entire history in one room. This is because in most cases a user is banned/redacted
shortly after joining a room.
In the case that `/rooms/messages` was called for more events, the method would
always paginate the timeline up until the limit or the end of the room
history, which is only the expected behavior when matching the sender
with a "glob".
2021-10-19 16:28:55 +01:00
David Teller
06e5f00b2d
Intercept /report and display human-readable abuse reports in the moderation room - Resolves #38 (#135)
* Intercept /report and display human-readable abuse reports in the moderation room - Resolves #38
2021-10-07 14:42:08 +02:00
gnuxie
776c1fe063 Tidy logging in integration tests 2021-09-30 15:52:06 +01:00
gnuxie
400af48e6e Move Mjolnir setup and configuration to a sensible place. 2021-09-27 16:04:01 +01:00
gnuxie
0a6b122f5c Tidy up documentation and test utils 2021-09-27 15:33:15 +01:00
gnuxie
68aa717826 Rework integration tests to work with mx-tester 2021-09-24 18:25:27 +01:00
gnuxie
1d2da60bee Allow relative paths for mjolnir data
These are relative to the project directory.
2021-09-24 18:25:27 +01:00
gnuxie
57ef8ab7fe Tidy up test harness. 2021-09-24 18:25:27 +01:00
Gnuxie
002e4ee749 Create docker-compose for testing purposes 2021-09-24 18:25:27 +01:00
Chirayu Desai
69ace9cfa5 Add a new protection, MessageIsMedia
* Simply redacts any media sent to the room, by anyone
* Meant to serve as a temporary measure to prevent image spam,
  in conjunction with FirstMessageIsImage
2021-09-24 16:57:16 +05:30
gnuxie
6edf503a9c Use rooms/initialSync instead of sync to fetch room history.
See https://github.com/matrix-org/synapse/issues/10842.
For the time being this seems to be the only way to avoid requests
that take several minutes for synapse to complete and timeout.
2021-09-17 12:02:14 +01:00
gnuxie
5acc38c8b5 EventRedactionQueue documentation improvements from review 2021-09-16 17:10:59 +01:00
gnuxie
ad199cc7d7 Use a Map for queueing redactions by roomId. 2021-09-15 12:18:55 +01:00
gnuxie
2889599eb2 Rename AutomaticRedactionQueue to UnlistedUserRedactionQueue.
This seems to be a more descriptive name and it also doesn't clash
with the new redaction queue.
2021-09-14 14:45:07 +01:00
gnuxie
c949d26582 When checking a member change, process redactions for that room. 2021-09-14 14:45:07 +01:00
gnuxie
c5b5026d4d WIP: Redact events after all bans have been applied. 2021-09-14 14:13:24 +01:00
David Teller
e45791f66e
Merge pull request #102 from jojosch/catch-errors
catch errors and set non-zero exit code
2021-08-31 11:52:47 +02:00
Travis Ralston
37031764ac
Merge pull request #117 from matrix-org/yoric/delete-rooms-api
Replace shutdown_room API with DELETE /_synapse/admin/v1/rooms/<room_…
2021-08-17 09:23:55 -06:00
David Teller
dd6c06eae5 Fix: Let's default to Synapse's default message when deleting a room without a message 2021-08-17 17:21:17 +02:00
Travis Ralston
f09fd5d507
Merge pull request #123 from matrix-org/travis/voice-prot
Add a voice message protection to easily redact unwanted messages
2021-08-17 08:46:34 -06:00
David Teller
b60f503e2e FIXUP 2021-08-17 12:56:25 +02:00
David Teller
62b30b19d9 Replace shutdown_room API with DELETE /_synapse/admin/v1/rooms/<room_id> - Resolves #76, closes #96
As per https://github.com/matrix-org/synapse/issues/9052, shutdown_room is going away, to be replaced with DELETE /_synapse/admin/v1/rooms/<room_id>.
2021-08-17 12:54:24 +02:00
Travis Ralston
4c6511ba3d Definitely didn't copy/paste 2021-08-16 20:35:39 -06:00
Travis Ralston
453784d7ef Add a voice message protection to easily redact unwanted messages 2021-08-16 20:32:00 -06:00
David Teller
46d099e8e0 Lint: Enabling 'noUnusedLocals' 2021-07-22 08:47:41 +02:00
David Teller
2e22154870 Lint: Enabling 'strictNullChecks' 2021-07-22 08:40:29 +02:00
David Teller
2a77509f9e Lint: Enabling 'noImplicitReturns' 2021-07-22 08:24:12 +02:00
Travis Ralston
ff4cbc018f Update matrix-bot-sdk and use request cleaning function 2021-07-01 15:11:27 -06:00
Johannes Schleifenbaum
662b06df8e
catch errors and set non-zero exit code
Signed-off-by: Johannes Schleifenbaum <johannes@js-webcoding.de>
2021-06-14 19:03:35 +02:00
Neil Middleton
1c5c4bdc15
Remove errant log 2021-06-14 14:51:18 +01:00
Neil Middleton
531fd1379c Make !mjolnir not case sensitive 2021-06-14 14:43:50 +01:00
J. Ryan Stinnett
259cdd8c12 Improve force handling
This improves the force argument parsing to keep it from getting glued onto the
reason. It also adjusts tests for the new behaviour.
2021-02-05 17:03:36 +00:00
J. Ryan Stinnett
46192ac6f7 Add confirmation for wildcard bans
This adds a default enabled option to require confirmation for wildcard bans
(e.g. those containing `*` or `?`). Users will need to also add `--force` for
the commands to be accepted.
2021-02-05 16:09:11 +00:00
Emi Tatsuo
50f2352001
Refactored to more verbose variable names; Updated copyright 2020-10-31 09:28:50 -04:00
Emi Tatsuo
4c0bbd845d
Removed default words from word list in favor of more neutral words 2020-10-31 09:23:18 -04:00
Emi Tatsuo
6fa93e3bae
Corrected description of WordList to be time-independant 2020-06-21 16:26:51 -04:00
Emi Simpson
1e47be497b
Fix lint
Signed-off-by: Emi Simpson <emi@alchemi.dev>
2020-06-21 15:21:50 -04:00
Emi Simpson
c2fbf0934a
Added configuration for wordlist protection 2020-06-21 15:18:34 -04:00
Emi Simpson
bccb18225b
Added unconfigurable wordlist protection 2020-06-21 13:56:11 -04:00
Travis Ralston
635f9ba03f Prioritize bans over redactions, and queue redactions faster
This could do with some cleanup, particularly around the part where it uses a callback.
2020-06-12 08:15:48 -06:00
Travis Ralston
4751b093a5 Add Healthz support 2020-06-12 08:03:08 -06:00
Travis Ralston
7ee66a03dd Trim command arguments too for accessory spaces 2020-05-11 21:36:53 -06:00
Travis Ralston
7cb34f99b9 Appease the linter 2020-05-11 21:36:05 -06:00
Travis Ralston
013cac1365 Fix remaining getRoomAlias calls 2020-05-11 21:35:37 -06:00
Travis Ralston
45a8f2899b Fully remove ban list server support 2020-05-11 21:33:28 -06:00
Travis Ralston
46bc6a1a0f Bump bot-sdk version to handle published aliases better 2020-05-11 21:31:47 -06:00
Travis Ralston
9e18a6dfff Add additional safety around room alias resolution for pills
Just fall back to not caring if we have to.
2020-05-11 21:30:22 -06:00
Travis Ralston
7fa025f678 Remove ban list server support
This will take the shape of something else eventually.
2020-05-11 21:11:24 -06:00
Travis Ralston
cdc8170a8f Fix assumption that an error message will be present 2020-05-05 18:36:24 -06:00
Travis Ralston
7f185eced3 Appease the linter 2020-04-15 09:22:03 -06:00