[V3] ctx.send modifications and other output sanitization #1942

Merged
mikeshardmind merged 6 commits from V3/mass-mention-avoidance into V3/develop 2018-08-24 15:50:38 +02:00
mikeshardmind commented 2018-07-17 02:42:25 +02:00 (Migrated from github.com)

Type

  • Bugfix
  • Enhancement
  • New feature

Description of the changes

This modifies ctx.send to accept a filter, and provide a default filter which removes mass mentions

This also adds username sanitization to modlog's cases and mod's userinfo.

Also adds a convienience feature as bot.send_filtered (but more granular application of filtering is still advised)

See #1941 and the #mod-log channel on discord around August 4th for real world cases on this.

Alternatives I've considered:

  • Manually scrub most output
  • modifications to user.display_name to automatically include such a replacement
  • don't fix, and point people towards the display name filter in the builtin filter cog

What this doesn't fix:

  • Sending to a channel or user directly is not fixed here, I'm not patching discord.abc.Messageable unless discussion about overriding more of discord.py happens to prompt this.

(manually sanitizing using the added filters works for this)

### Type - [ ] Bugfix - [X] Enhancement - [ ] New feature ### Description of the changes This modifies `ctx.send` to accept a filter, and provide a default filter which removes mass mentions This also adds username sanitization to modlog's cases and mod's userinfo. Also adds a convienience feature as `bot.send_filtered` (but more granular application of filtering is still advised) See #1941 and the #mod-log channel on discord around August 4th for real world cases on this. ### Alternatives I've considered: * Manually scrub most output * modifications to `user.display_name` to automatically include such a replacement * don't fix, and point people towards the display name filter in the builtin filter cog ### What this doesn't fix: * Sending to a channel or user directly is not fixed here, I'm not patching `discord.abc.Messageable` unless discussion about overriding more of discord.py happens to prompt this. (manually sanitizing using the added filters works for this)
palmtree5 (Migrated from github.com) reviewed 2018-07-17 02:42:25 +02:00
tekulvw (Migrated from github.com) reviewed 2018-07-17 02:42:25 +02:00
Twentysix26 (Migrated from github.com) reviewed 2018-07-17 02:42:25 +02:00
mikeshardmind commented 2018-07-17 08:20:13 +02:00 (Migrated from github.com)

I like the way this functions in practice enough that I've gone ahead and PR'd it upstream more robustly. I'd say using this here is safe under the same considerations mentioned in that PR (i.e. don't use this to redact accidental token leaks in things like eval, as that should be done in other ways to prevent user input guess & check)

We can use this solution safely until something like that is (if) merged upstream if we want

I like the way this functions in practice enough that I've gone ahead and PR'd it upstream more robustly. I'd say using this here is safe under the same considerations mentioned in that PR (i.e. don't use this to redact accidental token leaks in things like eval, as that should be done in other ways to prevent user input guess & check) We can use this solution safely until something like that is (if) merged upstream if we want
officiallyemma commented 2018-08-01 22:47:13 +02:00 (Migrated from github.com)

bump, I've added these changes in manually to my install but the majority of servers right now are still vulnerable. In a server of 10k people this really isn't something we can risk, and I see a lot of other server owners feeling the same way.

@Twentysix26 and other maintainers, please look into this.

bump, I've added these changes in manually to my install but the majority of servers right now are still vulnerable. In a server of 10k people this really isn't something we can risk, and I see a lot of other server owners feeling the same way. @Twentysix26 and other maintainers, please look into this.
Twentysix26 commented 2018-08-01 23:00:27 +02:00 (Migrated from github.com)

@qwazwsx This PR is being considered, however, I'd argue that in a 10k people server the bot shouldn't have permissions to mass mention to begin with :)

@qwazwsx This PR is being considered, however, I'd argue that in a 10k people server the bot shouldn't have permissions to mass mention to begin with :)
mikeshardmind commented 2018-08-02 00:36:19 +02:00 (Migrated from github.com)

I strongly disagree that a 10k person bot shouldn't be able to have mass mention perms. There may be announcements which actually should require it in any community. While the opportunity for them is few and far between in most well-run communities, whether a bot having those permissions makes sense is ultimately up to those communities to decide.

I strongly disagree that a 10k person bot shouldn't be able to have mass mention perms. There may be announcements which actually should require it in any community. While the opportunity for them is few and far between in most well-run communities, whether a bot having those permissions makes sense is ultimately up to those communities to decide.
Twentysix26 commented 2018-08-02 10:39:54 +02:00 (Migrated from github.com)

I'm aware of legitimate uses for mass mentions on big servers, however I was attempting to point out that there are plenty of ways to prevent unwanted mass mentions, even without touching any code.
For announcements, for example, is possible to give the bot mass mention permissions in one single channel (announcement channels are common), avoiding the risk of users triggering a mass mention in others.
@qwazwsx 's message sounded urgent, so I provided a ready solution.

I'm aware of legitimate uses for mass mentions on big servers, however I was attempting to point out that there are plenty of ways to prevent unwanted mass mentions, even without touching any code. For announcements, for example, is possible to give the bot mass mention permissions in one single channel (announcement channels are common), avoiding the risk of users triggering a mass mention in others. @qwazwsx 's message sounded urgent, so I provided a ready solution.
mikeshardmind commented 2018-08-09 08:02:20 +02:00 (Migrated from github.com)

I've done another pass over the various places we take in user input in any form, specifically for anything which could mass mention unintentionally. Searching for places we potentially take in links is a lot more intensive since even in embedded content, invite links need sanitization or discord will render an invite. The good news is, mentions inside of embeds don't actually ping users.

I consider the mass mentions the more important nuisance to kill (both would be ideal.) I feel this is ready enough for public use at this point as a solution, but I'm not sure I've covered everywhere this needs handling when it comes to filtering (specifically invite links from) embeds.

This can be 100% covered by automatically re-constructing all embed objects, but I felt this was too much a performance drain in practice on even a 200 user server that tried to help me break it. What it will come down to is applying selective filtering to content before placing it in an embed if from an untrusted source.

I've done another pass over the various places we take in user input in any form, specifically for anything which could mass mention unintentionally. Searching for places we potentially take in links is a lot more intensive since even in embedded content, invite links need sanitization or discord will render an invite. The good news is, mentions inside of embeds don't actually ping users. I consider the mass mentions the more important nuisance to kill (both would be ideal.) I feel this is ready enough for public use at this point as a solution, but I'm not sure I've covered everywhere this needs handling when it comes to filtering (specifically invite links from) embeds. This can be 100% covered by automatically re-constructing all embed objects, but I felt this was too much a performance drain in practice on even a 200 user server that tried to help me break it. What it will come down to is applying selective filtering to content before placing it in an embed if from an untrusted source.
mikeshardmind commented 2018-08-16 21:36:52 +02:00 (Migrated from github.com)

A note on behavior in embeds. It seems at some point after the August 4th raiding incident, discord Changed the behavior of invites to not be rendered in embeds. They are still rendered when in code blocks, and in a modlog entry we probably shouldn't be advertising servers just because someone having a mod action done to them was named as an invite. This leaves verifying all of the other locations for this behavior at a much lower priority, but still able to be changed as needed at a later date.

A note on behavior in embeds. It seems at some point after the August 4th raiding incident, discord Changed the behavior of invites to not be rendered in embeds. They are still rendered when in code blocks, and in a modlog entry we probably shouldn't be advertising servers just because someone having a mod action done to them was named as an invite. This leaves verifying all of the other locations for this behavior at a much lower priority, but still able to be changed as needed at a later date.
Tobotimus (Migrated from github.com) approved these changes 2018-08-24 15:45:50 +02:00
Sign in to join this conversation.
No labels
Automated PR
Blocked
Blocked By: Damage Control
Blocked By: Dependency
Blocked By: Other PR
Breaking Change
Category: CI
Category: Cogs - Admin
Category: Cogs - Alias
Category: Cogs - Audio
Category: Cogs - Bank
Category: Cogs - Cleanup
Category: Cogs - CustomCommands
Category: Cogs - Dev
Category: Cogs - Downloader
Category: Cogs - Economy
Category: Cogs - Filter
Category: Cogs - General
Category: Cogs - Image
Category: Cogs - Mod
Category: Cogs - Modlog
Category: Cogs - Mutes
Category: Cogs - Permissions
Category: Cogs - Reports
Category: Cogs - Streams
Category: Cogs - Trivia
Category: Cogs - Trivia - Lists
Category: Cogs - Warnings
Category: Core - API - App Commands Package
Category: Core - API - Audio
Category: Core - API - Bank
Category: Core - API - Commands Package
Category: Core - API - Config
Category: Core - API - Other
Category: Core - API - Utils Package
Category: Core - Bot Class
Category: Core - Bot Commands
Category: Core - Command-line Interfaces
Category: Core - Downloader
Category: Core - Help
Category: Core - i18n
Category: Core - Modlog
Category: Core - Other Internals
Category: Core - RPC/ZMQ
Category: Docker
Category: Docs - Changelogs
Category: Docs - For Developers
Category: Docs - Install Guides
Category: Docs - Other
Category: Docs - User Guides
Category: Meta
Category: RPC/ZMQ methods
Category: Vendored Packages
Changelog Entry: Added
Changelog Entry: Pending
Changelog Entry: Skipped
Closed: Duplicate
Closed: External
Closed: Invalid
Closed: User Error
Closed: Won't Fix
Complex Issue
Docs-only
Feature Branch
Good First Issue
Help Wanted
High Priority
Needs Backport To stable-docs
No Activity
No Repro
QA: Bypassed
QA: Changes Requested
QA: Passed
Release Blocker
Status: Accepted
Status: Frozen
Status: In Progress
Status: Needs Discussion
Status: Needs Info
Status: Needs Triage
Status: PRs Welcome
Type: Bug
Type: Dependency Update
Type: Deprecation
Type: Enhancement
Type: Feature
Type: Informational
Type: Merge
Type: Optimisation
Type: Question
Type: Removal
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
Mrcoolgamer11/Red-DiscordBot!1942
No description provided.