Block CDN attachment scam #1293
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.



Summary
This extends the scam blocker to also detect CDN based attachment scam. That is, people posting discord-provided image links containing scam, such as:
We already had similiar logic but only for actual attachments. These are "just links" in the message and not technicially attachments from Discords perspective.
The new case is also covered by unit tests and was tested locally.
Details
The existing code for handling suspicious attachments was tweaked so it can also be used for this scenario. Therefore, we created a small wrapper for
Attachmentthat can now either represent an actual Discord attachment or just an URL. The logic then uses this wrapper instead.The URL analyse code received some rework, in particular the introduction of
AnalyseUrlResult. This allows us to hold additional details for each URL (for example the contained attachment, if any).These data classes received a couple of helper methods that mostly deal with string extraction (some
indexOfandsubstringfun).All this was done to keep the main flow of how the analyse works intact and not add a bunch of extra if-else branching just for this new edge case.
Config
No changes are required.
The host-whitelist addition
"cdn.discordapp.com"was already added to the TEST and PROD bots config.