CVE-2021-29502 (published 2021-05-10T18:15Z)

WarnSystem is a cog (plugin) for the Red discord bot. A vulnerability has been found in the code that allows any user to access sensible informations by setting up a specific template which is not properly sanitized. The problem has been patched in version 1.3.18. Users should update and type `!warnsysteminfo` to check that their version is 1.3.18 or above. As a workaround users may unload the WarnSystem cog or disable the `!warnset description` command globally.

Severity: MEDIUM
CVSS v2 base score: 4.0 (AV:N/AC:L/Au:S/C:P/I:N/A:N)
CVSS v3 base score: 6.5, MEDIUM (CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:N/A:N)

Weakness information:
cwe_id: CWE-94
cwe_name: Improper Control of Generation of Code ('Code Injection')
description: The product constructs all or part of a code segment using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the syntax or behavior of the intended code segment.
extended_description: 
            When a product allows a user's input to contain code syntax, it might be possible for an attacker to craft the code in such a way that it will alter the intended control flow of the product. Such an alteration could lead to arbitrary code execution.
            Injection problems encompass a wide variety of issues -- all mitigated in very different ways. For this reason, the most effective way to discuss these weaknesses is to note the distinct features which classify them as injection weaknesses. The most important issue to note is that all injection problems share one thing in common -- i.e., they allow for the injection of control plane data into the user-controlled data plane. This means that the execution of the process may be altered by sending code in through legitimate data channels, using no other mechanism. While buffer overflows, and many other flaws, involve the use of some further issue to gain execution, injection problems need only for the data to be parsed. The most classic instantiations of this category of weakness are SQL injection and format string vulnerabilities.
         
         

Fix information:
repo_url: https://github.com/retke/Laggrons-Dumb-Cogs
commit_details: repo_url: https://github.com/retke/Laggrons-Dumb-Cogs
author: retke
author_date: 2021-05-09 18:51:55+02:00
msg: [WarnSystem] Safely format embed descriptions
repository: repo_url: https://github.com/retke/Laggrons-Dumb-Cogs
repo_name: visit repo url
description: visit repo url
repo_language: visit repo url
owner: retke
file_changes: filename: api.py
change_type: ModificationType.MODIFY
diff: @@ -29,6 +29,26 @@ _ = Translator("WarnSystem", __file__)
 id_pattern = re.compile(r"([0-9]{15,21})$")
 
 
+class SafeMember:
+    def __init__(self, member: discord.Member) -> None:
+        self.name = str(member.name)
+        self.display_name = str(member.display_name)
+        self.nick = str(member.nick)
+        self.id = str(member.id)
+        self.mention = str(member.mention)
+        self.discriminator = str(member.discriminator)
+        self.color = str(member.color)
+        self.colour = str(member.colour)
+        self.created_at = str(member.created_at)
+        self.joined_at = str(member.joined_at)
+
+    def __str__(self):
+        return self.name
+
+    def __getattr__(self, name):
+        return self
+
+
 class FakeRole:
     """
     We need to fake some attributes of roles for the class UnavailableMember
@@ -622,9 +642,22 @@ class API:
             duration = self._format_timedelta(time)
         else:
             duration = _("*[No time given]*")
-        format_description = lambda x: x.format(
-            invite=invite, member=member, mod=author, duration=duration, time=today
-        )
+
+        def format_description(text):
+            try:
+                return text.format(
+                    invite=invite,
+                    member=SafeMember(member),
+                    mod=SafeMember(author),
+                    duration=duration,
+                    time=today,
+                )
+            except Exception:
+                log.error(
+                    f"[Guild {guild.id}] Failed to format description in embed", exc_info=True
+                )
+                return "Failed to format field."
+
         link = re.search(r"(https?://)\S+\.(jpg|jpeg|png|gif|webm)", reason)
 
         # embed for the modlog

programming_language: Python
filename: warnsystem.py
change_type: ModificationType.MODIFY
diff: @@ -224,7 +224,7 @@ class WarnSystem(SettingsMixin, AutomodMixin, BaseCog, metaclass=CompositeMetaCl
 
         self.task: asyncio.Task
 
-    __version__ = "1.3.17"
+    __version__ = "1.3.18"
     __author__ = ["retke (El Laggron)"]
 
     # helpers

programming_language: Python