Commit Graph

709 Commits

Author SHA1 Message Date
Gnuxie ff4f78ee65 RedactionSynchronisationProtection invite retraction (#788)
- The _Redaction Synchronisation Protection_ has been improved in a few ways:
  - Invitations in protected rooms will be rejected as part of the redaction
    process when they are sent from users being redacted (e.g. as a brigading
    tactic).
  - User redaction will now be triggered on bans and the reason will be scanned
    for `automaticallyRedactForReasons` from Draupnir's config.

* Update RedactionSynchronisation for new protection apis.

* Rerwrite redaction synchronisation protection

* Reject invitations on ban.

* Add renderer and simulated redaction synchornisation capability.

* Reduce dependencies of redaction synchronisation protection.

* Allow RedactionSynchronisation to be unit tested.

* Update to MPS 3.1.0.

---------

Signed-off-by: Rory& <root@rory.gay>
Co-authored-by: Rory& <root@rory.gay>
2025-03-28 17:48:57 +00:00
Gnuxie 64de51496c Fixes to the new room takedown protection (#782)
* Take room pill out of takedown notice.

* Fix missing configSchema in RoomTakedownProtection.

It was always there... just not plumbed in.

* Fix RoomTakedownConfig schema was wrong.

Properties that default to undefined need to be optional because of
the way defaulting works.

* Fix missing name on RoomTakedownProtectionSettings.

* Fix joined_members missing from RoomBasicDetails.

Important because it's used for the threshold.

* Improve rendering of room discovery.

* Add SimulatedRoomTakedownCapability.

https://github.com/the-draupnir-project/planning/issues/41#issuecomment-2755447714

* Change renderer to include protection name.

For some reason addOneLiner does this but addMessage does not?

Something to look into there mare...
2025-03-27 21:52:59 +00:00
Gnuxie ec6e0c6836 Fix roomStateBackingStore legacy migration. (#781)
This stuff got mixed up while applying a patch in the RoomTakedown protection drive.

Co-authored-by: Bea <20361868+enbea@users.noreply.github.com>
2025-03-27 20:33:52 +00:00
Gnuxie 986eba55d4 Update documentation & README for server admin features. (#778) 2025-03-26 17:22:51 +00:00
gnuxie f556f3e39a Add BlockInvitationOnServer protection. 2025-03-26 11:57:25 +00:00
Gnuxie a086768b01 Merge pull request #761 from the-draupnir-project/gnuxie/room-takedown
Support for room policies with hashed entity  and `org.matrix.msc4204.takedown` recommendation in Synapse

Story: https://github.com/the-draupnir-project/planning/issues/41
documentation: https://the-draupnir-project.github.io/draupnir-documentation/protections/room-takedown-protection

This PR introduces room takedown functionality into Draupnir.
A new `draupnir takedown` command is added similar to the ban command, but marks entities to be taken down. Because the content is illegal or intolerable. To begin with we only allow takedown of rooms. These takedown policies are sharable with policy lists just like normal bans.

Draupnir responds to takedown policies on Synapse by calling the [room shutdown](https://element-hq.github.io/synapse/latest/admin_api/rooms.html#version-2-new-version) API with the options `block` and `purge`.

The policies that are created by the takedown command are hashed, and this is in order to prevent the room id's being shared directly, and so that we do not create a directory of intolerable content. To be able to use the policies, draupnir therefore needs to be aware of all the rooms that the homeserver is participating in, in order to calculate their hashes and find matching policies, and then takedown the marked rooms.

As part of this process, Draupnir has to "discover" the rooms your server is participating in. This is done via the [synapse-http-antispam](https://the-draupnir-project.github.io/draupnir-documentation/bot/synapse-http-antispam) recently added to draupnir. When draupnir discovers rooms, it will prompt the management room with a notification with some details of the title, room description, and creator. This functionality will be toggleable but will be strongly recommended for servers that have public registration
2025-03-24 19:52:30 +00:00
gnuxie 903a7b6dbc Passthrough all events for check_event_for_spam.
We realise the PDU rate for most homeservers will not be
significant...  and if it is they can just disable the callback.
2025-03-24 19:47:38 +00:00
gnuxie e033d53127 Add store management to integration test fixtures. 2025-03-24 19:47:38 +00:00
gnuxie 9f3afce02c Fix RoomDiscovery.
Two problems:

1. the batcher was being initialised before the slot for the listener
was.

2. That item batch interface with void is sketch and using flat would
make an array of [roomID, undefined, roomID, undefined...], not good.
2025-03-22 22:25:36 +00:00
gnuxie 99cb3b317b Split SynapseHTTPAntispam from webapis.
Webapis need to depend on the callback handler and the callback
handler needs to be created per draupnir instance.
2025-03-22 21:47:58 +00:00
gnuxie 0bce47d487 Room Takedown needs to be aware of all rules that are literal. 2025-03-22 16:21:38 +00:00
gnuxie 2928b2ffd7 RoomTakedownProtection was missing from DraupnirProtectionsIndex.ts 2025-03-22 13:46:53 +00:00
gnuxie 45c8189dbc Add option to send takedown for plain-text entities. 2025-03-22 13:46:29 +00:00
gnuxie d8dc0facdf Clarify error in takedown command while fetching room details. 2025-03-22 13:46:05 +00:00
gnuxie aea1d1d36e Plumb in SynapseAdminRoomTakedownCapability.
Was missing registration.  It sucks that the factory for capability
providers doesn't let us return a Result type??
2025-03-22 11:37:10 +00:00
gnuxie 6168669fff Update Draupnir for reworked hash reversal.
We introduced a new PolicyRuleChangeType enum with a variant for
revealed literals.  And we changed our mind about where reversal will
happen, it'll happen in the room state manager factory.
2025-03-22 11:35:57 +00:00
gnuxie 15c1bf23a9 Rework hash store to support storing details about all entities. 2025-03-21 16:19:09 +00:00
gnuxie 1d0feb724a Update Draupnir for new PolicyListRevision API.
We should probably have just accepted multiple recommendations in all
these methods.
2025-03-21 16:19:09 +00:00
gnuxie fa3bce12d6 Include policy entity in the takedown audit log policy info. 2025-03-21 16:19:09 +00:00
gnuxie f92d18662c getTakedownDetails query improvements.
Co-authored-by: Bea <20361868+enbea@users.noreply.github.com>
2025-03-21 16:19:09 +00:00
gnuxie 862ed5c500 Remove duplicated hasEnded variables in BetterSqliteStore.
`db.open` has the same purpose.

Co-authored-by: Bea <20361868+enbea@users.noreply.github.com>
2025-03-21 16:19:09 +00:00
gnuxie b5e3ebb53a Explicitly choose the setting of temp_store in better sqlite.
Memory isn't the default.

Co-authored-by: Bea <20361868+enbea@users.noreply.github.com>
2025-03-21 16:19:09 +00:00
gnuxie 522eae6ce2 Be explicit when returning ROWID after INSERT in audit log.
Co-authored-by: Bea <20361868+enbea@users.noreply.github.com>
2025-03-21 16:19:09 +00:00
gnuxie a17cd51763 Clean up queries in hash store.
Co-authored-by: Bea <20361868+enbea@users.noreply.github.com>
2025-03-21 16:19:09 +00:00
gnuxie 6203171c71 Fix delete room/all rooms in RoomStateBackingStore.
Co-authored-by: Bea <20361868+enbea@users.noreply.github.com>
2025-03-21 16:19:09 +00:00
gnuxie 377917f6f4 Improve Sqlite wrapper Schema migration.
This cleans up all of the code surrounding schema migration and allows
the migration procedure to be transactional so that people can
downgrade draupnir if something explodes.

Co-authored-by: Bea <20361868+enbea@users.noreply.github.com>
2025-03-21 16:19:09 +00:00
gnuxie ef592a95e4 Plumb takedown command into room discovery. 2025-03-21 16:19:09 +00:00
gnuxie 8cf7e4b638 Add initial draft of takedown command.
Now we need to hook in discovery when the command is run.
2025-03-21 16:19:09 +00:00
gnuxie 19a78d670c Some shite that didn't get comitted to do with messing up hash store. 2025-03-21 16:19:09 +00:00
gnuxie a6b6508af1 Update unban code for unmasked hashed entities.
We will need to work harder to remove masked hashed entities...
2025-03-21 16:19:09 +00:00
gnuxie 0de853b413 Update Draupnir policy handling code for hashed entities. 2025-03-21 16:19:09 +00:00
gnuxie 2909464d36 Store user and server in room hash store too. 2025-03-21 16:19:09 +00:00
gnuxie 9d5e19514a Store details about the room at takedown in the audit log.
We need to do this because they will be impossible to obtain once the
room has been blocked on the server.

We also need to make sure we now include the server the room was
created on, and the creator in the room hash store.
2025-03-21 16:19:09 +00:00
gnuxie 7f0a8da41f Flesh out RoomDiscovery some more.
I really need to move the room details to the audit log, it's there
so we can see what the rooms are that have been takendown.
2025-03-21 16:19:09 +00:00
gnuxie 4fdb142ac2 Only audit takedown when capabilities are not simulated. 2025-03-21 16:19:09 +00:00
gnuxie 003410d41a Change the order of checking the audit log. 2025-03-21 16:19:09 +00:00
gnuxie b80a503ea0 Improve hash store replace query a little.
I'm after realising this whole thing is a mess but there's no time to fix it.
2025-03-21 16:19:08 +00:00
gnuxie 1e581d7394 Test room takedown service and add thoughts to FIXME. 2025-03-21 16:19:08 +00:00
gnuxie d15322dff6 Test and fix the hash store. 2025-03-21 16:19:08 +00:00
gnuxie 442b930d89 Unit test and fix sqlite room audit log. 2025-03-21 16:19:08 +00:00
gnuxie 3f00346ae6 Plumb in SynapseHTTPAntispam to RoomTakedownProtection room discovery. 2025-03-21 16:19:08 +00:00
gnuxie 7b212d75aa Fix typo in SynapseHTTPAntispam UserMayJoinRoom handle. 2025-03-21 16:19:08 +00:00
gnuxie 15f94bc2b2 Export request body types from SynapseHTTPAntispam. 2025-03-21 16:19:08 +00:00
gnuxie 62079457e9 Move roomStateBackingStore into TopLevelStores abstraction. 2025-03-21 16:19:08 +00:00
gnuxie 4ae5e5f63a Begin process of creating top level stores.
We now need to move the roomStateBackingStore into this thingy.
2025-03-21 16:19:08 +00:00
gnuxie 25f39e20d0 Start plumbing up RoomTakedownProtection into Draupnir.
There are a couple of FIXME's to address. Such as plumbing
up the stores into draupnir and how to poll for new rooms.
2025-03-21 16:19:08 +00:00
gnuxie b8bf6c5692 Add RoomTakedownCapability and SynapseAdmin implementation. 2025-03-21 16:19:08 +00:00
gnuxie 7282374caf Clean up better-sqlite store so that we can test stores with in memeory dbs. 2025-03-21 16:19:08 +00:00
gnuxie b7b9cc78c9 Initial RoomTakedown "service".
I want to change the APIs a little bit so that we can get a takedown
reporter like the audit log but for message rendering and testing.

I also want to make the BetterSqliteStore concrete not depend
on where the database came from so that we can use in memory
databases for unit testing stores.

There are a couple other FIXME's littered around so be sure to check
those before merging.
2025-03-21 16:19:08 +00:00
Aminda Suomalainen ⚧ adb886419a BasicFlooding.ts: fix search & replace fail (#762)
It probably didn't mean what it said
2025-03-21 12:00:18 +00:00