Skip to content

Managed Mjolnirs are being informed of every event sent to the appservice #412

@Gnuxie

Description

@Gnuxie

The mjolnirs will still compare the event against their joined/protected rooms deeper in the chain, so they won't act on any events in rooms they're not joined to or protecting, but this still is problematic and we should have defence in depth.

mjolnir/src/Mjolnir.ts

Lines 533 to 558 in 818e4cf

private async handleEvent(roomId: string, event: any) {
// Check for UISI errors
if (roomId === this.managementRoomId) {
if (event['type'] === 'm.room.message' && event['content'] && event['content']['body']) {
if (event['content']['body'] === "** Unable to decrypt: The sender's device has not sent us the keys for this message. **") {
// UISI
await this.client.unstableApis.addReactionToEvent(roomId, event['event_id'], '⚠');
await this.client.unstableApis.addReactionToEvent(roomId, event['event_id'], 'UISI');
await this.client.unstableApis.addReactionToEvent(roomId, event['event_id'], '🚨');
}
}
}
// Check for updated ban lists before checking protected rooms - the ban lists might be protected
// themselves.
const policyList = this.policyLists.find(list => list.roomId === roomId);
if (policyList !== undefined) {
if (ALL_BAN_LIST_RULE_TYPES.includes(event['type']) || event['type'] === 'm.room.redaction') {
policyList.updateForEvent(event.event_id)
}
}
if (event.sender !== this.clientUserId) {
this.protectedRoomsTracker.handleEvent(roomId, event);
}
}

if (!this.protectedRooms.has(roomId)) {
return; // We're not protecting this room.
}

Inspiration should be taken from bridges on how they manage tracking of rooms. The thing is you shouldn't do this naively because it does duplicate effort. Mjolnir instance already track which rooms they are joined to and are protecting, we just don't have a way to map from a roomId to a set of Mjolnirs that are joined to that room.

public onEvent(request: Request<WeakEvent>, context: BridgeContext) {
// We honestly don't know how we're going to map from bridge to user
// https://github.com/matrix-org/matrix-appservice-bridge/blob/6046d31c54d461ad53e6d6e244ce2d944b62f890/src/components/room-bridge-store.ts
// looks like it might work, but we will ask, figure it out later.
[...this.mjolnirs.values()].forEach((mj: ManagedMjolnir) => mj.onEvent(request));
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-AppserviceS-CriticalPrevents work, causes data loss and/or has no workaroundT-TaskRefactoring, enabling or disabling functionality, other engineering tasksX-Release-BlockerThis issue must be resolved before the next release can be made

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions