Skip to content
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

Enhance media protections #516

Merged
merged 4 commits into from
Jul 29, 2024
Merged

Enhance media protections #516

merged 4 commits into from
Jul 29, 2024

Conversation

H-Shay
Copy link
Contributor

@H-Shay H-Shay commented Jul 25, 2024

As the title states.

Fixes #481

@H-Shay H-Shay requested a review from turt2live July 25, 2024 22:26
Copy link
Member

@turt2live turt2live left a comment

Choose a reason for hiding this comment

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

otherwise lgtm - thanks!

@@ -35,10 +35,11 @@ export class MessageIsMedia extends Protection {

public async handleEvent(mjolnir: Mjolnir, roomId: string, event: any): Promise<any> {
if (event['type'] === 'm.room.message') {
const content = event['content'] || {};
let content = event['content'] || {};
content = content?.["m.new_content"] ?? content;
Copy link
Member

Choose a reason for hiding this comment

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

we should probably also check m.relates_to to ensure we're actually looking at an edit here. The risk being that someone decides to send partially malformed events to trick Mjolnir into (dis)allowing something which is still rendered to users.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So we can assume it's an edit if there is both an m.new_content and an m.relates_to field?

Copy link
Member

Choose a reason for hiding this comment

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

m.relates_to can mean many things, but inspecting it should tell us if it's an edit. In practice this means ensuring the m.relates_to rel_type is m.replace, I think. There's a bunch of validity rules we should probably be checking too, but that might still have false negatives if the code isn't perfect (or someone finds a way to send something weird).

src/protections/MessageIsMedia.ts Outdated Show resolved Hide resolved
@H-Shay H-Shay requested a review from turt2live July 26, 2024 18:22
Copy link
Member

@turt2live turt2live left a comment

Choose a reason for hiding this comment

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

lgtm - thanks!

src/protections/MessageIsMedia.ts Outdated Show resolved Hide resolved
Co-authored-by: Travis Ralston <[email protected]>
@H-Shay H-Shay merged commit f526b97 into main Jul 29, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: MessageIsMedia does not check m.new_content
2 participants