r-anime / misato

💬 Mod bot for the /r/anime Discord
MIT License
6 stars 7 forks source link

ReDoS vulnerability when processing regular expressions #92

Open eritbh opened 3 years ago

eritbh commented 3 years ago

Regex patterns in filters are passed straight to the regexp constructor without any sort of filtering for malicious patterns. For trusted expressions (those on the /r/anime server) this is fine, but not the best solution long-term.

https://medium.com/@liran.tal/node-js-pitfalls-how-a-regex-can-bring-your-system-down-cbf1dc6c4e02

eritbh commented 3 years ago

This seems like a good remediation technique: https://www.josephkirwin.com/2016/03/12/nodejs_redos_mitigation/

For something like message filters which need to be executed for basically every messageCreate the bot receives, might be worth looking into an asynchronous method instead, depending on the performance hit incurred by using vm - needs further investigation