Commit Graph

52 Commits

Author SHA1 Message Date
Gnuxie 711b9b7413 tidy config properties (#724)
* Remove `syncOnStartup` option since it no longer does anything.

We always 'sync' on startup, not that we have a concept of syncing
anymore. https://github.com/the-draupnir-project/Draupnir/issues/504.

* remove `verboseLogging`.

yeah, cya later pal. https://github.com/the-draupnir-project/Draupnir/issues/504.
2025-02-06 13:43:00 +00:00
nexy7574 0e2f81e971 Fix the individual request rate-limit (#694)
* Fix the individual request rate-limit

This fixes the first problem raised in #693

---------

Signed-off-by: nexy7574 <git@nexy7574.co.uk>
Co-authored-by: Gnuxie <50846879+Gnuxie@users.noreply.github.com>
2025-01-19 18:32:55 +00:00
Gnuxie 039f1a8ef0 Improve the information we have about the management room. (#610)
We introduce a new interface `ManagementRoomDetail`, and our implementation of this has immediate access to the room members and room state. 

Immediately, this allows us to warn when the management room is public.

In the future, it gives us a nice place to decide things like decide whether membership of the management room is enough to be considered a moderator, introduce more redundancy in access control, and give capabilities a way to determine who is a moderator (and avoid enacting consequences against them).  

* Move management room to its own folder so we can start introspecting on it.

* Add ManagementRoomDetail.ts

This is just used to track who is a moderator and whether the
management room is public.

* Update ManagementRoomOutput to depend on ManagementRoomDetail.

This should allow us to implement the feature that warns when
the management room is public.

* Send a warning if the management room is public.

Fixes https://github.com/the-draupnir-project/Draupnir/issues/413.

* Update to MPS 1.7.0 so we can get the join rule event.
2024-10-10 13:37:42 +01:00
Marcel 8b03d6448e Update matrix-appservice-bridge and use our own alias for matrix-bot-sdk (#609)
* Update matrix-appservice-bridge and use our own alias for matrix-bot-sdk

* Bump node version to support matrix-appservice-bridge

* Bump node version in CI

* Fix comments

* Add changelog entry
2024-10-10 12:11:26 +02:00
Catalan Lover 9cc64074e1 Rename to Draupnir in Appropriate Places (#591)
* Rename to Draupnir in Appropriate Places

* Integrate Code review feedback on CHANGELOG.md
2024-10-04 20:32:10 +02:00
Gnuxie 10528943a6 request response was typed incorrectly leading to checks being omitted. (#492)
Issue was reported by @daedric7 in the support room.  https://matrix.to/#/%21IaWNErZAgQUhGqJXjX%3Amatrix.org/%24KJt2FOE9PLM2oqUgwTt5JxIAWbXPWZi03SlBZgwX7P8?via=matrix.org&via=envs.net&via=ubuntu.com
2024-07-26 10:31:29 +01:00
Gnuxie 337a6a3b76 Add reuse.software (#486)
We have a lot of verbose headers, and i think now is the best opportunity we have to become reuse compliant given that we just did two other similar maintenance changes (prettier, typescirpt5 & eslint9 & typescript-eslint).

* synapse_antispam resuse headers.

* delete old unused tslint.json.

* Add REUSE to pre-commit config.

* reuse info for config directory.
2024-07-25 10:58:40 +01:00
pre-commit-ci[bot] 3b2036c2db prettier all files 2024-07-22 19:13:57 +01:00
Gnuxie 8973db487b Migrate to eslint-9 flat config, typescript 5, typescript-eslint strictTypeChecked (#476)
* Migrate to eslint-9 strictTypeChecked & typescript 5.

* Update to MPS 0.23.0.

Required for strict type checks.

* Looks like we found a test that was complete garbage, amazing really.

* FIXUP

* Well, the command handler was bugged previously...

The command handler used to always only return the command
without the prefix due to an operator precedence bug.
This meant that when we made the order of operations explicit,
we were now including the prefix of the command in the copy.
So when we parsed arguments the code wasn't expecting the prefix
to be there.

* update to MPS 0.23.1.

MPS 0.23.0 was bugged because we didn't enable
`noUncheckedIndexedAccess` while upgrading to typescript 5.

* Make sure eslint runs on all ts files.

* eslint fixes.

* enable `noUncheckedIndexedAccess` & `exactOptionalPropertyTypes`.

* eslint ignores is clearly not understood by me.

* Update SuperCoolStream for eslint and ts5.

* stricter eslint done i thinks

* Whoops, added on .only somewhere.

* Update MPS.

* fix broken test realted things.

* Well I guess that part of getMessagesByUserIn was part of the interface.

* Fix redactionCommandTest.

* Account for escapeHTML in tests.

* Fix tests.

* stuff not matching with .editorconfig fixes.

* Fix appservice webAPI test.

* Update for MPS 0.23.3.
2024-07-22 16:54:04 +01:00
gnuxie 80ccb64330 Implement RoomStateBackingStore with BetterSqlite. 2024-04-06 20:03:38 +01:00
gnuxie d3618ea814 fix utils.ts for MPS. 2024-04-06 20:03:34 +01:00
Marcel f55d8a453d Add health endpoint to appservice and add metrics via prometheus (#70)
This adds a `/healthz` endpoint to the appservice which allows this to work more nicely in kubernetes.

It also adds some metrics for tracking the provisioning state.

Grafana result:
![image](https://github.com/Gnuxie/Draupnir/assets/1374914/9426c8e6-2c1c-469c-8902-1b9e2b6db529)

Note: The ts-ignore are sadly required since the `_getValue` method is not public :/ I didnt find another solution apart from tracking it maybe elsewhere.

* Add health endpoint to appservice and add metrics via prometheus

* Ensure that we dont have duplicate metrics when the appservice is registered multiple times

* Move gauge modifications to utils function

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Fix typo
2023-09-04 12:32:26 +01:00
Aminda Suomalainen e4c02b96cd Add pre-commit configuration (#34)
* add .pre-commit-config.yaml

Signed-off-by: Aminda Suomalainen <suomalainen+git@mikaela.info>

* .editorconfig: decrease indent size for text

* .pre-commit-config.yaml: remove prettier

Signed-off-by: Aminda Suomalainen <suomalainen+git@mikaela.info>

* .editorconfig consistency.

* .pre-commit-config.yaml: restore sample hooks

* .editorconfig: disable indent_size for LICENSE & NOTICE

* pre-commit run --all-files

* tsconfig.json: tabs to spaces

* .pre-commit-config.yaml: update editorconfig-checker to 2.7.2

* .editorconfig: disable indent_size for markdown

* mjolnir-entrypoint.sh: retab

* .editorconfig: also exclude json from indent checking

* test/nginx.conf: retab

* test/integration/commands/redactCommandTest.ts: remove leading space

* retab or remove leading whitespaces for the rest of the files

* src/appservice/datastore.ts remove newlines

* test/integration/commands/roomTest.ts: remove leading space.

---------

Signed-off-by: Aminda Suomalainen <suomalainen+git@mikaela.info>
Co-authored-by: gnuxie <Gnuxie@protonmail.com>
2023-08-29 13:38:00 +01:00
Gnuxie 9f43e1186b Incorperate Do not interrupt redact sequences due to error when backfilling (#50)
* Do not interrupt redact sequences due to error when backfilling

... Mainly timeouts.

* Change caught redaction error LogLevel from DEBUG to ERROR.

From matrix-org/mjolnir#479

---------

Co-authored-by: Marco Cirillo <marco.cirillo@aria-net.org>
2023-05-03 16:56:17 +01:00
gnuxie 72f554ef2e Improve HTTP Error handling.
So as a history lesson.
The Matrix Bot SDK uses the npm library "requests".
When there was a http error, matrix-bot-sdk
would literally throw the response object.
This would be a horrible 1000+line long thing to accidentally
be logged to the console via node's inspect.
Though it was inevitable since you can't be sure every catch
was handling the error correctly. Irregardless, the solution
developed at Element was to create an error object
that had concise details.
This was great, however, within the matrix-bot-sdk there is
[this](https://github.com/Half-Shot/matrix-bot-sdk/blob/f58d7ea6e24d1db8b9b8009dea4cd97cbff54d0c/src/http.ts#L66)
awful line of code which logs every http error as error using the
matrix-bot-sdk logger.
This wastes so much log space and causes alarm fatigue,
rather than muting the module, the action instead taken
was to redact stack traces from http errors.
This was not a good idea.
Eventually matrix-bot-sdk was updated to have a MatrixError type
when a request was performed via the client-server api that had an
error.
matrix-appservice-bridge depends upon this and so Mjolnir now needs
to be updated to throw MatrixError's.
We have gone a step further in this commit and also muted
the matrix-bot-sdk http module, to stop the alarm fatigue problem
https://github.com/turt2live/matrix-bot-sdk/pull/158
2023-01-31 19:57:56 +00:00
gnuxie 7a076033a3 Protect Draupnir from matrix-bot-sdk 2023-01-31 18:25:42 +00:00
gnuxie 9330e319ce Add new header to all files. 2023-01-02 16:54:50 +00:00
Gnuxie 704bb660c2 Refactor how we listen for matrix events. (#446)
* Refactor Matrix event listener in Mjolnir and ManagedMjolnir.

closes https://github.com/matrix-org/mjolnir/issues/411.

Issue #411 says that we have to be careful about room.join,
but this was before we figured how to make matrix-appservice-bridge
echo events sent by its own intents.

* Remove MatrixClientListener since it isn't actually needed.

* Protect which config values can be used for ManagedMjolnirs.

* Introduce MatrixSendClient

so listeners aren't accidentally added to a MatrixClient instead
of MatrixEmitter.

* doc

* Move provisioned mjolnir config to src/config.

This just aids maintance so whenever someone goes to change the config
of the bot they will see this and update it.

* doc for matrix intent listener.
2022-12-06 17:17:40 +00:00
David Teller 2915757b7d Very basic support for Sentry. (#398)
The Sentry package is very useful for monitoring runtime errors. With this PR,
we simply add the necessary mechanism to:

- log to sentry any uncaught error that reaches the toplevel, including startup errors.
2022-11-30 16:06:02 +01: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 10b7233e48 matrix.to urls for aliases don't need a via param (#348) 2022-08-18 09:37:30 +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 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
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 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
David Teller eb7f5f6b3e Reduce stackspam (#237)
This should cut a lot on the noise in logs.
2022-02-25 17:59:34 +01:00
Jess Porter a58c7d3f1a move LogProxy.logMessage to Mjolnir.logMessage (#194) 2022-02-15 15:44:41 +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
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
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
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
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
David Teller 2e22154870 Lint: Enabling 'strictNullChecks' 2021-07-22 08:40:29 +02:00
Travis Ralston ff4cbc018f Update matrix-bot-sdk and use request cleaning function 2021-07-01 15:11:27 -06: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 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 232a6e2bb9 Use room aliases in permission errors too 2020-04-15 08:12:42 -06:00
Travis Ralston f6a856ed4a Resolve room aliases in messages
Fixes https://github.com/matrix-org/mjolnir/issues/47
2020-04-15 08:12:42 -06:00
Travis Ralston 6f80a17558 Improve redaction handling 2020-04-14 16:49:20 -06:00
Travis Ralston 959162c4a3 Support automatically redacting users for certain ban reasons 2019-12-09 19:56:12 -07:00
Travis Ralston 6753e7f780 Allow the redact command to take globs 2019-12-09 19:43:41 -07:00
Travis Ralston bb6d457f98 Fix timeline filter 2019-10-18 16:38:27 +01:00