Commit Graph
211 Commits
Author SHA1 Message Date
Jess Porter 4376679b99 load config yaml manually, remove more references to static config (#347) 2022-08-16 15:51:18 +01:00
Gnuxie 64c26e55f4 Merge pull request #352 from matrix-org/gnuxie/room-activity
Fix Intermittent integration test failures
2022-08-16 13:21:05 +01:00
Jess Porter 1e67eed30b change report polling to read oldest first, so we paginate to end and wait (#353) 2022-08-15 15:58:25 +01:00
gnuxie d5171bd299 Activity tracker wouldn't update for recently joined/parted protected rooms. 2022-08-15 13:29:19 +01:00
Gnuxie 21aabc879a Stop the config being global (in almost all contexts). (#334)
* Stop the config being global (in almost all contexts).

* make sure unit test has a config

* Make failing word list more visible

* Only use Healthz from index.ts

Not really sure how useful it is anyways?
2022-08-09 11:29:27 +01:00
Gnuxie 121d4cf98f Mjolnir would apply stale ACL to rooms during batching (#331)
* banListTest would applyACL before rules appeared in `/state`.

Mjolnir will call applyServerAcls several times while a policy list is being updated, sometimes concurrently. This means a request to set a server ACL in a room which has old data can finish after a more recent recent request with the correct ACL. This means that the old ACL gets applied to the rooms (for a moment).

This is a follow up from https://github.com/matrix-org/mjolnir/pull/314/commits/551065815e65e6117d7e8105afd6f5da9b87c8af

* Only allow one invocation of applyServerAcls at a time as to not conflict with each other by using a promise chain.

We don't use the throttle queue because we don't want to be blocked by other background tasks.
We don't make another throttle queue because we don't want throttling and we don't want to delay the ACL application, which can happen even with throttle time of 0.
2022-08-09 10:57:38 +01:00
David Teller 829e1bd0aa Towards opinions in PolicyLists. (#336)
Towards opinions in PolicyLists.

This changeset is part of an ongoing effort to implement "opinions"
within policy lists, as per MSC3847.

For the time being:
- we rename BanList into PolicyList;
- we cleanup a little dead code;
- we replace a few `string`s with `enum`;
- `ListRule` becomes an abstract class with two concrete subclasses `ListRuleBan` and `ListRuleOpinion`.
2022-07-26 21:47:26 +02:00
DeepBlueV7.X 9f872f78e1 Use stable prefixes for policy recommendations (#329)
They have been in the spec for ~3 years now and most mjolnirs should be
able to handle them. Let's use the stable endpoint now, so that other
moderation tools don't need to implement the legacy identifier to handle
new bans at some point.

Signed-off-by: Nicolas Werner <nicolas.werner@hotmail.de>
2022-07-11 14:28:57 +01:00
Gnuxie 941cc32ddd Add !mjolnir rules matching <entity> to search watched lists. (#307)
* Add `!mjolnir rules matching <entity> to search watched lists.

Lists all the rules that will match the entity.
2022-07-07 13:03:03 +01:00
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 CirilloandDavid Teller 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 Tellerandgnuxie 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