Commit Graph

448 Commits

Author SHA1 Message Date
gnuxie
efb4cebbd1 Refactor list creation 2022-11-15 17:05:30 +00:00
jesopo
9a49d29821 better name for policy room 2022-11-15 17:05:30 +00:00
jesopo
8ebe257146 warrior of light, use the echo 2022-11-15 17:05:30 +00:00
gnuxie
b075beed1a bleh yarn lock broke after rebase 2022-11-15 17:05:30 +00:00
jesopo
67557047c5 missing await on mjolnirManager.createNew 2022-11-15 17:05:30 +00:00
jesopo
ad6e787486 add /join endpoint to api backend 2022-11-15 17:05:30 +00:00
jesopo
039f64adb4 remove ratelimits from appservice mjolnirs 2022-11-15 17:05:30 +00:00
jesopo
f67f64e3cd shouldn't've changed this 2022-11-15 17:05:30 +00:00
jesopo
da006d74c5 use body-parser, bind api handlers 2022-11-15 17:05:30 +00:00
jesopo
caa079462a response statuses need bodies 2022-11-15 17:05:30 +00:00
jesopo
3c4eb5ffa3 update MjolnirManager for recent main changes 2022-11-15 17:05:30 +00:00
jesopo
93a1b7476f remove ability for user to specify custom management room 2022-11-15 17:05:30 +00:00
jesopo
4a9e5d422d resolve typing errors, run api when appservice runs 2022-11-15 17:05:30 +00:00
jesopo
be18613722 fix some linting, move all Intent related code to AppService.ts 2022-11-15 17:05:30 +00:00
jesopo
6d604190a4 add managementRoomId to provisionNewMjolnir 2022-11-15 17:05:30 +00:00
jesopo
c1d79a698b draft widget backend 2022-11-15 17:05:30 +00:00
gnuxie
b943a02cda update deps 2022-11-15 17:05:30 +00:00
gnuxie
f68b511256 move appservice bits 2022-11-15 17:05:30 +00:00
gnuxie
94040b00d6 AppService start 2022-11-15 17:05:30 +00:00
David Teller
81cd91c250
Unbitrotting ruleserver tests (#418) 2022-11-15 13:06:41 +01:00
Gnuxie
fb52e3dcb2
Improve the clarity of the unban command (#402)
Also fix a years long bug where the Flooding/Media protection wouldn't stop redacting users

Closes #393
Closes #394

* Warn about room level bans when using unban

https://github.com/matrix-org/mjolnir/issues/394

* Clear internal queues within protections when unban happens.

https://github.com/matrix-org/mjolnir/issues/393
2022-11-07 11:28:59 +00:00
Gnuxie
2c00ac4372
Always echo policy list changes (#401)
closes https://github.com/matrix-org/mjolnir/issues/392.
2022-11-07 11:27:54 +00:00
gnuxie
a970733d0b Update roomMemberTest for removal of mjolnir.protectedRooms object.
https://github.com/matrix-org/mjolnir/issues/370.
2022-10-19 15:21:51 +01:00
gnuxie
cfea765493 Fix list rooms command improperly iterating protected rooms. 2022-10-19 15:21:51 +01:00
gnuxie
c7ba745081 Stop ProtectedRoomsSet verifying permissions for unprotected rooms. 2022-10-19 15:21:51 +01:00
gnuxie
c537f2067e protected rooms config test
https://github.com/matrix-org/mjolnir/issues/370
2022-10-19 15:21:51 +01:00
gnuxie
cea6944c92 Status command can distinguish between protected and watched lists.
https://github.com/matrix-org/mjolnir/issues/370
2022-10-19 15:21:51 +01:00
gnuxie
5c2e4ab0bb Change list creation command to also protect the new room
https://github.com/matrix-org/mjolnir/issues/370
2022-10-19 15:21:51 +01:00
gnuxie
97673cdccb Make Mjolnir use ProtectedRoomsConfig
https://github.com/matrix-org/mjolnir/issues/370
2022-10-19 15:21:51 +01:00
gnuxie
58e36d4e23 Factor out protected rooms config management from Mjolnir.
The combination of `resyncJoinedRooms`, `unprotectedWatchedListRooms`,
`explicitlyProtectedRoomIds`, `protectedJoinedRoomIds` was incomprehensible.
https://github.com/matrix-org/mjolnir/issues/370

Separating out the management of `explicitlyProtectedRoomIds`, then
making sure all policy lists have to be explicitly protected
(in either setting of `config.protectAllJoinedRooms`) will make
this code much much simpler.
We will later change the `status` command to explicitly show
which lists are watched and which are watched and protected.
2022-10-19 15:21:51 +01:00
Gnuxie
da084328a9
Refactor list creation with MSC3784 support. (#386)
https://github.com/matrix-org/matrix-spec-proposals/pull/3784

This was extracted from the appservice mjolnir work to reduce review burden.
2022-10-19 10:33:12 +01:00
Gnuxie
5bd23ced9b
Access Control Unit (#378)
The ACL unit allows you to combine an policy lists and conveniently test users and servers against them.
The main motivation for this work is provide access control on who can provision and continue to use mjolnir instances in the appservice component.
We include a new recommendation type org.matrix.mjolnir.allow which can be used with user and server entity types to create allow lists.
We have also replaced the destructing of policy lists in applyServerACL and applyMemberBans (in ProtectedRooms.ts) with calls to the AccessControlUnit.
Adding commands to add/remove allowed entities is not something i want to do at the moment.
2022-10-18 16:28:11 +01:00
David Teller
7b0edadd17
Update tests and instructions to intercept reports also with v3 endpoint (#388)
In both our instructions and our tests, we use the r0 endpoint to intercept abuse reports. This endpoint is deprecated and not implemented by all clients. This PR updates the instructions and tests to the new endpoint.
2022-10-18 15:48:39 +02:00
mahdi1234
938b9fea8f
Fixed typo (#389) 2022-10-18 13:45:57 +01:00
David Teller
28265cec2e
CI: Let's try and cache mx-tester installs (#383) 2022-10-10 17:17:22 +02:00
Than Harrison
0379cc45fb
Fix small typo (#382)
* src/commands/CommandHandler.ts:
 - fix small typo that's bugging me in `!status` response.
   change "projection" -> "protection"

Signed-off-by: Than Harrison <infosecvoid@proton.me>

Signed-off-by: Than Harrison <infosecvoid@proton.me>
2022-10-10 12:35:35 +02:00
Gnuxie
77ad40e27a
Refactor protected rooms. (#371)
* Attempt to factor out protected rooms from Mjolnir.

This is useful to the appservice because it means we don't
have to wrap a Mjolnir that is designed to sync.

It's also useful if we later on want to have specific
settings per space.

It's also just a nice seperation between Mjolnir's needs while
syncing via client-server and the behaviour of syncing policy rooms.

 ### Things that have changed

- `ErrorCache` no longer a static class (phew), gets used by `ProtectedRooms`.
- `ManagementRoomOutput` class gets created to handle logging back to the management room.
- Responsibilities for syncing member bans and server ACL are handled by `ProtectedRooms`.
- Responsibilities for watched lists should be moved to `ProtectedRooms` if they haven't been.
- `EventRedactionQueue` is moved to `ProtectedRooms` since this needs to happen after
  member bans.
- ApplyServerAcls moved to `ProtectedRooms`
- ApplyMemberBans move to `ProtectedRooms`
- `logMessage` and `replaceRoomIdsWithPills` moved to `ManagementRoomOutput`.
- `resyncJoinedRooms` has been made a little more clear, though I am concerned about how often it does run because it does seem expensive.


* ProtectedRooms is not supposed to track joined rooms.

The reason is because it is supposed to represent a specific
set of rooms to protect, not do horrible logic
for working out what rooms mjolnir is supposed to protect.
2022-09-29 14:49:09 +01:00
Jess Porter
f108935d07
support compound consequences, switch WordList to consequences (#351) 2022-09-26 16:57:21 +01:00
Denis Lisov
89b7ec1a18
Add list shortcodes to status command output (#312) 2022-09-14 10:32:14 +01:00
Gnuxie
4d5447cb50
Rework the banning and unbanning of entities in PolicyLists. (#345)
* Rework the banning and unbanning of entities in PolicyLists.

1. We keep track of the event that created a list rule so that we
can remove the rule by having a way to determine the original state key for the rule.
This is because the state key of rules can be anything and should not be
relied on by Mjolnir to unban things (which it was doing).

2. The old scheme for producing a state key was causing for some entities to escape bans
https://github.com/matrix-org/mjolnir/issues/322.

We could have used a hash or something similar, but we know that
the reason for the `rule:${entity}` scheme existed was for ease of debugging
and finding rules in devtools. So instead we have followed a scheme simalar to
bridges where the first character of an mxid is replaced with an underscore.
Everything else just gets put into the state key. Since domains can't have '@'
and room ids, aliases can't either.

3. We have stopped the need for Mjolnir to wait for the next response from sync after banning,
unbanning an entity so that we can apply ACL's sooner.

* Use PolicyList's `banEntity` method to create imported rules.
2022-08-19 13:09:08 +01:00
Gnuxie
8bafa16495
Missing awaits on floating promises in tests. (#359)
If you add `"no-floating-promises": true` it's very easy
to find where this is done accidentally.
Not sure we can keep that on all the time yet though..
2022-08-18 13:09:03 +01:00
Erik Johnston
a2d919b57a
Fix example to have correct incantation (#358) 2022-08-18 11:25:07 +01:00
Jess Porter
10b7233e48
matrix.to urls for aliases don't need a via param (#348) 2022-08-18 09:37:30 +01:00
Jess Porter
625b62ce6d
use requested path to configs (#357) 2022-08-17 16:17:23 +01:00
Gnuxie
9bcb0b7a59
Replace acceptInvitesFromGroup with acceptInvitesFromSpace. (#338)
Replace acceptInvitesFromGroup with acceptInvitesFromSpace.

https://github.com/matrix-org/mjolnir/issues/125
https://github.com/matrix-org/mjolnir/issues/99

acceptInvitesFromGroup was implemented with an experimental api
that was a precursor to spaces which was refereed to
as either communities or groups.
Support for communities/groups ended in Synapse 1.61.0
https://github.com/matrix-org/synapse/releases/tag/v1.61.0.

To test we just edit the config dynamically which changes how the join room listener functions
though idk, shouldn't we have just made a new mjolnir instance
for this test, or changed the config before the test started somehow?


Co-authored-by: jesopo <github@lolnerd.net>
2022-08-17 10:05:23 +01:00
Gnuxie
f5a1a39861
audit yarn.lock (#356)
### Auditing the lock file

```
npm install --package-lock-only
npm audit fix
rm yarn.lock
yarn import
```

```
npm audit

json-schema  <0.4.0
Severity: critical
json-schema is vulnerable to Prototype Pollution - https://github.com/advisories/GHSA-896r-f27r-55mw
fix available via `npm audit fix`
node_modules/json-schema
  jsprim  0.3.0 - 1.4.1 || 2.0.0 - 2.0.1
  Depends on vulnerable versions of json-schema
  node_modules/jsprim

minimist  <1.2.6
Severity: critical
Prototype Pollution in minimist - https://github.com/advisories/GHSA-xvch-5gv4-984h
fix available via `npm audit fix`
node_modules/minimist

nanoid  3.0.0 - 3.1.30
Severity: moderate
Exposure of Sensitive Information to an Unauthorized Actor in nanoid - https://github.com/advisories/GHSA-qrpm-p2h7-hrv2
fix available via `npm audit fix`
node_modules/nanoid
node_modules/postcss/node_modules/nanoid
  mocha  8.2.0 - 9.1.4
  Depends on vulnerable versions of nanoid
  node_modules/mocha

5 vulnerabilities (2 moderate, 3 critical)

To address all issues, run:
  npm audit fix
```

### minimist

minimist@1.2.5
used by mocha, tslint and matrix-bot-sdk@0.5.19

via
```
MatrixClient::replyHtmlText
MatrixClient::replyHtmlNotice
MatrixClient::sendHtmlNotice
MatrixClient::sendHtmlTex
```

none of which we use.

### nanoid

As for nanoid this is used by mocha.
It's also used by postcss vis the bot sdk

```
├─┬ matrix-bot-sdk@0.5.19
│ └─┬ sanitize-html@2.7.1
│   └─┬ postcss@8.4.16
│     ├── nanoid@3.3.4

```
though unless i'm missing something nanoid@3.3.4 doesn't fit into the vulnerable versions  `3.0.0 - 3.1.30`


### json-schema

As for json-schema, it is used by jsprim@1.4.2 within 'validateJsonObjectJS'.
fortunately we depend on jsprim via the http-signatures@1.2.0 package which only use jsprim for rfc1123.
(which request depends upon in the matrix-bot-sdk).

```
├─┬ matrix-bot-sdk@0.5.19
│ ├─┬ request@2.88.2
│ │ ├─┬ http-signature@1.2.0
│ │ │ ├─┬ jsprim@1.4.2
│ │ │ │ ├── json-schema@0.4.0
2022-08-16 18:49:33 +01:00
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
gnuxie
899a8bd784 Reduce number of rooms involved in banListTest.ts
apparently this takes over 5 minutes on the little github acitons VM.
Starting to wonder if this is really a sustainable setup.
2022-08-16 12:55:50 +01:00
gnuxie
b9284f0167 Reduce the throttle test theshold even more.
The implementation is rubbish, as it doesn't avoid the exponential backoff

Remove default rate limit testing.

It doesn't work. No there really isn't more to say about it
you're welcome to dispute it if you're going to do the work investigating. I'm not.

We used to have a test here that tested whether Mjolnir was going to carry out a redact order the default limits in a reasonable time scale.
Now I think that's never going to happen without writing a new algorithm for respecting rate limiting.
Which is not something there is time for.

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

Synapse rate limits were broken and very permitting so that's why the current hack worked so well.
Now it is not broken, so our rate limit handling is.

b850e4554c

Honestly I don't think we can expect anyone to be able to use Mjolnir under default rate limits.

well, it's not quite simple as broken, but it is broken. With the default level in synapse (which is what matrix.org uses) it is struggling to redact 15 messages within 5 minutes. that means 5 messages over the burst count. This is ofc ontop mjolnir sending reactions / responding to replies (which isn't much but... enough to mess with the rate limiter since ofc, Synapse tells requests to wait x amount of time before trying again, but that doesn't help for concurrent requests since ofc there's only 1 slot available at that future time.  This means Synapse just wacks everything with exponentially longer shit without many (or any?) events going through
it used to be fine
because rate limiting in synapse used to be a lot more liberal because it was "broken" or something, that's not me saying it's broken that's just what synapse devs say which is probably true.
if all requests went into a queue then yeah you could eliminate one problem
but that's a lot of work and i don't think we should be doing it
cos no one uses mjolnir like this anyways
2022-08-16 12:55:30 +01:00