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

Add protection for mention spam #524

Merged
merged 19 commits into from
Sep 20, 2024
Merged

Add protection for mention spam #524

merged 19 commits into from
Sep 20, 2024

Conversation

Half-Shot
Copy link
Contributor

@Half-Shot Half-Shot commented Sep 19, 2024

Fixes #309 #211

This protection checks whether a message contains a large number of mentions and redacts the message. It currently checks the mentions array, then the body and finally the formatted body. I've chosen 10 as a sensible max number of mentions before the message may be considered spam, although this is configurable via a setting.

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.

generally lgtm

import { NumberProtectionSetting } from "./ProtectionSettings";

export const DEFAULT_MAX_MENTIONS = 10;
const USER_ID_REGEX = /@[^:]*:.+/;
Copy link
Member

Choose a reason for hiding this comment

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

can we just limit this to number of @ symbols? (plus HTML encoded varient for htmlBody)

Choose a reason for hiding this comment

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

I think there are concrete chances of that reacting on somebody posting a snippet of code with some delimiter:

some = value
;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
next = section

Copy link
Member

Choose a reason for hiding this comment

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

"don't do that in my rooms" :p

@Half-Shot Half-Shot merged commit 5ecdb8d into main Sep 20, 2024
5 checks passed
if (typeof body === "string" && body.split('@').length - 1 > max) {
return true;
}
if (typeof htmlBody === "string" && htmlBody.split('%40').length - 1 > max) {
Copy link
Contributor

@Gnuxie Gnuxie Sep 20, 2024

Choose a reason for hiding this comment

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

@Half-Shot Just a heads up, I know this isn't supposed to be perfect, but I don't think all clients urlencode mxids properly in the anchor hrefs

Copy link

Choose a reason for hiding this comment

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

(famously element didnt in the past. Not sure if this has been fixed. I just remember other client devs implementing workarounds for this case)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

why even have standards 🔥

thanks, I'll address this one when I'm back if someone doesn't get to it first.

Gnuxie added a commit to the-draupnir-project/Draupnir that referenced this pull request Sep 20, 2024
…tection.

From matrix-org/mjolnir#524.
Co-authored-by: Half-Shot <will@half-shot.uk>
Gnuxie added a commit to the-draupnir-project/Draupnir that referenced this pull request Sep 20, 2024
…tection.

From matrix-org/mjolnir#524.

Co-authored-by: Half-Shot <will@half-shot.uk>
Gnuxie added a commit to the-draupnir-project/Draupnir that referenced this pull request Sep 20, 2024
…tection.

From matrix-org/mjolnir#524.

Co-authored-by: Half-Shot <will@half-shot.uk>
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.

Mention flood protection
5 participants