Add RegExps support for Mjolnir's WordList protection
Well it did not take long for the spammers to side-step my word-list...
So here's a patch that actually allows you to enable regular expression support with Mjolnir's WordList protection! Making it substantially more powerful. :sunglasses:
I've tested this patch out and it appears to work flawlessly. Happy to revise it and re-test if needed.
Fixes https://github.com/matrix-org/mjolnir/issues/547
Testing (enabledRegExps=true)
With this feature enabled I tested all of the following with this wordlist, it all worked fine:
words:
- (https?:\/\/)?t\.me\/(\+)?[a-zA-Z0-9_-]+
- cashapp
- "apple pay"
- "paypal"
- a regular word, lower cases
cashapp
- a regular word, capital letters
CASHAPP
- a t.me link with https
https://t.me/+32cFzLuOiacxZmMe
- a t.me link without https
t.me/+32cFzLuOiacxZmMe
- with surrounding text:
Visit t.me/channel for more info! (t.me/channel)
Testing (enabledRegExps=false)
Now to test it with this new feature disabled and the same wordlist, to ensure that all the previous functionality still works.
- a regular word, lower cases
cashapp
- a regular word, capital letters
CASHAPP
- a t.me link with https (it's not triggered here):
https://t.me/+32cFzLuOiacxZmMe
It's been stated that:
i think at one point mjolnir fixed a bug where an empty word in the list would match every single message, and that was when the original regex support stopped working so i’m a little curious, what happens if you use an empty string with your implementation :p
Just tested this out and nope, it seems fine. With this word list:
matrix_bot_mjolnir_configuration_extension_yaml: |
# Configuration specific to certain toggle-able protections
protections:
wordlist:
enableRegExps: true
words:
- (https?:\/\/)?t\.me\/(\+)?[a-zA-Z0-9_-]+
- ""
-
minutesBeforeTrusting: 10080
The entry that's - "" doesn't seem to impact functionality at all.
While the truly blank entry at the end (when added after) seems to stop the WordList feature from working entirely. (Which is a separate issue this PR isn't meant to address really)
This is a fix for https://github.com/matrix-org/mjolnir/issues/547
I unfortunately don't have any time to create unit/integration tests for this. Maybe during the holiday season at the end of the year, but no promises.
If someone could help create these tests to help get this patch through that would be great.
What would unit tests for something like this look like? Just some manual test-cases?