Skip to content

Set MSC4293 flag when autoredacting users #612

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 12, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions src/ProtectedRoomsSet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -481,14 +481,23 @@ export class ProtectedRoomsSet {
await this.managementRoomOutput.logMessage(
LogLevel.WARN,
"ApplyBan",
`Attempted
to ban ${member.userId} but this is a member of the management room, skipping.`,
`Attempted to ban ${member.userId} but this is a member of the management room, skipping.`,
);
continue;
}
await this.client.banUser(member.userId, roomId, memberAccess.rule!.reason);

if (this.automaticRedactGlobs.find((g) => g.test(reason.toLowerCase()))) {
// Use MSC4293 and still fall back later
// See https://github.com/matrix-org/matrix-spec-proposals/pull/4293
await this.client.sendStateEvent(roomId, "m.room.member", member.userId, {
"membership": "ban",
"org.matrix.msc4293.redact_events": true,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was reason intentionally omitted here?

});

// Fallback
this.redactUser(member.userId, roomId);
Comment on lines +490 to 498
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a risk here if Mjolnir fails to redact events in the fallback. This can happen if there are more events in the timeline than the pagination limit, or if a call to /redact fails. Trying to workaround by using !mjolnir redact will no longer work in this room because Mjolnir will no longer receive unredacted events from /messages due to the behavior of MSC4293.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Receiving redacted events might be fine though? The logic could probably inspect the reason if it wanted too.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's true, It could be fine, but only because mjolnir doesn't exclude the redacted events from being called with /redact again

mjolnir/src/utils.ts

Lines 102 to 121 in 41a0ca2

await getMessagesByUserIn(client, userIdOrGlob, targetRoomId, limit, async (eventsToRedact) => {
for (const targetEvent of eventsToRedact) {
await managementRoom.logMessage(
LogLevel.DEBUG,
"utils#redactUserMessagesIn",
`Redacting ${targetEvent["event_id"]} in ${targetRoomId}`,
targetRoomId,
);
if (!noop) {
await client.redactEvent(targetRoomId, targetEvent["event_id"]);
} else {
await managementRoom.logMessage(
LogLevel.WARN,
"utils#redactUserMessagesIn",
`Tried to redact ${targetEvent["event_id"]} in ${targetRoomId} but Mjolnir is running in no-op mode`,
targetRoomId,
);
}
}
});

} else {
await this.client.banUser(member.userId, roomId, memberAccess.rule!.reason);
}
} else {
await this.managementRoomOutput.logMessage(
Expand Down
Loading