-
-
Notifications
You must be signed in to change notification settings - Fork 41
fix: Ensure the bookmarks service will only delete messages in DMs #979
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
Conversation
Reviewer's GuideThis PR refines the on_raw_reaction_add handler to prevent unauthorized bookmark removals by enforcing that removal reactions occur only in direct message channels and only on messages originally sent by the bot. Sequence diagram for bookmark removal reaction handling in DMssequenceDiagram
participant User
participant Discord
participant Bot
participant BookmarksService
User->>Discord: Reacts with remove bookmark emoji on a message
Discord->>Bot: on_raw_reaction_add event
Bot->>BookmarksService: on_raw_reaction_add(payload)
BookmarksService->>BookmarksService: Check if channel is DMChannel
alt Not a DMChannel
BookmarksService-->>Bot: Return (do nothing)
else Is DMChannel
BookmarksService->>BookmarksService: Check if message.author is bot user
alt Message author is bot
BookmarksService->>BookmarksService: remove_bookmark(message)
else Message author is not bot
BookmarksService-->>Bot: Return (do nothing)
end
end
Class diagram for updated bookmark removal logicclassDiagram
class BookmarksService {
+on_raw_reaction_add(payload)
+add_bookmark(user, message)
+remove_bookmark(message)
}
class discord.DMChannel
class discord.Message {
+author
}
class discord.RawReactionActionEvent {
+emoji
+channel_id
+message_id
+user_id
}
BookmarksService --|> discord.RawReactionActionEvent
BookmarksService ..> discord.DMChannel : checks instance
BookmarksService ..> discord.Message : checks author
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @cherryl1k - I've reviewed your changes - here's some feedback:
- Consider using an elif for the remove-bookmark branch instead of two separate ifs so you don’t perform the DM guard check after the add-bookmark logic.
- Use == rather than is when comparing message.author to self.bot.user to avoid potential identity issues with discord.py model instances.
- Correct the comment typo to “Ensures we’re in a user’s DMs before removing…” for clarity.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consider using an elif for the remove-bookmark branch instead of two separate ifs so you don’t perform the DM guard check after the add-bookmark logic.
- Use == rather than is when comparing message.author to self.bot.user to avoid potential identity issues with discord.py model instances.
- Correct the comment typo to “Ensures we’re in a user’s DMs before removing…” for clarity.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Description
Added some additional checks to ensure only messages from Tux can only be deleted in DMs. previously it was possible for any user (even without elevated permissions) to delete any message in the server that the bot was active in.
Guidelines
My code follows the style guidelines of this project (formatted with Ruff)
I have performed a self-review of my own code
I have commented my code, particularly in hard-to-understand areas
I have made corresponding changes to the documentation if needed
My changes generate no new warnings
I have tested this change
Any dependent changes have been merged and published in downstream modules
I have added all appropriate labels to this PR
I have followed all of these guidelines.
How Has This Been Tested? (if applicable)
I tested both on an account who owned the server and one without any permissions and made sure both could delete the Tux DM messages
Summary by Sourcery
Restrict bookmark removal to direct messages and bot-authored messages by adding channel type and author checks.
Bug Fixes: