[Audio/Core] MessagePredicate regex and escape chars #2788

Closed
opened 2019-06-22 03:16:38 +02:00 by aikaterna · 1 comment
aikaterna commented 2019-06-22 03:16:38 +02:00 (Migrated from github.com)

Command bugs

Command name

[p]playlist copy
https://github.com/Cog-Creators/Red-DiscordBot/blob/57d5c0870a2c704c8225af6c901bcda58c9a30bb/redbot/cogs/audio/audio.py#L1633

[p]playlist queue
https://github.com/Cog-Creators/Red-DiscordBot/blob/57d5c0870a2c704c8225af6c901bcda58c9a30bb/redbot/cogs/audio/audio.py#L1871

What cog is this command from?

Audio, but could be in any cog that uses the MessagePredicate regex to check for the bot's prefix

What were you expecting to happen?

A user with a prefix of \ to be able to use bot commands during the MessagePredicate active times.

What actually happened?

[2019-06-21 18:07:09] [ERROR] red: Exception in command 'playlist copy'
Traceback (most recent call last):
  File "c:\envs\3.1\lib\site-packages\discord\ext\commands\core.py", line 63, in wrapped
    ret = await coro(*args, **kwargs)
  File "c:\envs\3.1\lib\site-packages\redbot\cogs\audio\audio.py", line 1632, in _playlist_copy
    check=MessagePredicate.regex(fr"^(?!{ctx.prefix})", ctx),
  File "c:\program files (x86)\python37-32\Lib\asyncio\tasks.py", line 416, in wait_for
    return fut.result()
  File "c:\envs\3.1\lib\site-packages\discord\client.py", line 277, in dispatch
    result = condition(*args)
  File "c:\envs\3.1\lib\site-packages\redbot\core\utils\predicates.py", line 62, in __call__
    return self._pred(self, message)
  File "c:\envs\3.1\lib\site-packages\redbot\core\utils\predicates.py", line 793, in predicate
    pattern_obj = re.compile(pattern)
  File "c:\envs\3.1\lib\re.py", line 234, in compile
    return _compile(pattern, flags)
  File "c:\envs\3.1\lib\re.py", line 286, in _compile
    p = sre_compile.compile(pattern, flags)
  File "c:\envs\3.1\lib\sre_compile.py", line 764, in compile
    p = sre_parse.parse(p, flags)
  File "c:\envs\3.1\lib\sre_parse.py", line 930, in parse
    p = _parse_sub(source, pattern, flags & SRE_FLAG_VERBOSE, 0)
  File "c:\envs\3.1\lib\sre_parse.py", line 426, in _parse_sub
    not nested and not items))
  File "c:\envs\3.1\lib\sre_parse.py", line 742, in _parse
    source.tell() - start)
re.error: missing ), unterminated subpattern at position 1

How can we reproduce this issue?

Set a prefix of an escape character (\) or other possible troublesome regex-related character, use playlist copy with that prefix to copy a playlist that already has an existing target playlist of that name, and then when the bot asks you for a new playlist name to save the copy to, use any bot command with that prefix.

# Command bugs #### Command name [p]playlist copy <https://github.com/Cog-Creators/Red-DiscordBot/blob/57d5c0870a2c704c8225af6c901bcda58c9a30bb/redbot/cogs/audio/audio.py#L1633> [p]playlist queue <https://github.com/Cog-Creators/Red-DiscordBot/blob/57d5c0870a2c704c8225af6c901bcda58c9a30bb/redbot/cogs/audio/audio.py#L1871> #### What cog is this command from? Audio, but could be in any cog that uses the MessagePredicate regex to check for the bot's prefix #### What were you expecting to happen? A user with a prefix of `\` to be able to use bot commands during the MessagePredicate active times. #### What actually happened? ``` [2019-06-21 18:07:09] [ERROR] red: Exception in command 'playlist copy' Traceback (most recent call last): File "c:\envs\3.1\lib\site-packages\discord\ext\commands\core.py", line 63, in wrapped ret = await coro(*args, **kwargs) File "c:\envs\3.1\lib\site-packages\redbot\cogs\audio\audio.py", line 1632, in _playlist_copy check=MessagePredicate.regex(fr"^(?!{ctx.prefix})", ctx), File "c:\program files (x86)\python37-32\Lib\asyncio\tasks.py", line 416, in wait_for return fut.result() File "c:\envs\3.1\lib\site-packages\discord\client.py", line 277, in dispatch result = condition(*args) File "c:\envs\3.1\lib\site-packages\redbot\core\utils\predicates.py", line 62, in __call__ return self._pred(self, message) File "c:\envs\3.1\lib\site-packages\redbot\core\utils\predicates.py", line 793, in predicate pattern_obj = re.compile(pattern) File "c:\envs\3.1\lib\re.py", line 234, in compile return _compile(pattern, flags) File "c:\envs\3.1\lib\re.py", line 286, in _compile p = sre_compile.compile(pattern, flags) File "c:\envs\3.1\lib\sre_compile.py", line 764, in compile p = sre_parse.parse(p, flags) File "c:\envs\3.1\lib\sre_parse.py", line 930, in parse p = _parse_sub(source, pattern, flags & SRE_FLAG_VERBOSE, 0) File "c:\envs\3.1\lib\sre_parse.py", line 426, in _parse_sub not nested and not items)) File "c:\envs\3.1\lib\sre_parse.py", line 742, in _parse source.tell() - start) re.error: missing ), unterminated subpattern at position 1 ``` #### How can we reproduce this issue? Set a prefix of an escape character (`\`) or other possible troublesome regex-related character, use playlist copy with that prefix to copy a playlist that already has an existing target playlist of that name, and then when the bot asks you for a new playlist name to save the copy to, use any bot command with that prefix.
mikeshardmind commented 2019-06-22 03:19:48 +02:00 (Migrated from github.com)

I don't think this is actually a bug (in MessagePredicate, it is in audio)

The correct solution is to give it a proper regex (re.escape(ctx.prefix) to prevent the issue)

We can't escape for consumers, as we'd turn it into a string literal search.

I don't think this is actually a bug (in MessagePredicate, it is in audio) The correct solution is to give it a proper regex (`re.escape(ctx.prefix)` to prevent the issue) We can't escape for consumers, as we'd turn it into a string literal search.
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#2788
No description provided.