VAITP Dataset

← Back to the dataset

CVE-2021-41250

Bypassing token filter with non-blacklisted URL

  • CVSS 4.3
  • CWE-20 Improper Input Validation
  • Input Validation and Sanitization
  • Remote

Python discord bot is the community bot for the Python Discord community. In affected versions when a non-blacklisted URL and an otherwise triggering filter token is included in the same message the token filter does not trigger. This means that by including any non-blacklisted URL moderation filters can be bypassed. This issue has been resolved in commit 67390298852513d13e0213870e50fb3cff1424e0

CVSS base score
4.3
Published
2021-11-05
OWASP
A05 Security Misconfiguration
Orthogonal defect classification
Function
Code defect classification
Incorrect Functionality
Category
Input Validation and Sanitization
Subcategory
Insecure Parsing or Deserialization
Accessibility scope
Remote
Impact
Unauthorized Access
Fixed by upgrading
Yes

Solution

Update Python Discord bot to version with commit 67390298852513d13e0213870e50fb3cff1424e0 or higher.

Vulnerable code sample

import re

BLACKLISTED_URLS = ["http://example.com", "http://example2.com"]

def is_blacklisted_url(url):
    return url in BLACKLISTED_URLS

def filter_message(message):
    filter_tokens = ["badword", "trigger"]
    
    if any(token in message for token in filter_tokens):
        return "Message contains a triggering filter token."

    if any(is_blacklisted_url(url) for url in re.findall(r'http[s]?://\S+', message)):
        return "Message contains a blacklisted URL."

    return "Message is clean."

message_with_url_and_token = "Check this link http://example.com and this badword."
print(filter_message(message_with_url_and_token))

Patched code sample

import re
import os

BLACKLISTED_URLS = os.getenv('BLACKLISTED_URLS', '').split(',')
FILTER_TOKENS = os.getenv('FILTER_TOKENS', '').split(',')

def is_blacklisted_url(url):
    url = url.strip().lower()
    return url in BLACKLISTED_URLS

def filter_message(message):
    if not isinstance(message, str):
        return "Message is invalid."

    if any(token.lower() in message.lower() for token in FILTER_TOKENS):
        return "Message contains a triggering filter token."

    urls = re.findall(r'https?://[a-zA-Z0-9-_.]+(?:/[a-zA-Z0-9-_.]*)*', message)
    
    if any(is_blacklisted_url(url) for url in urls):
        return "Message contains a blacklisted URL."

    return "Message is clean."

message_with_url_and_token = "Check this link http://example.com and this badword."
print(filter_message(message_with_url_and_token))

Cite this entry

@misc{vaitp:cve202141250,
  title        = {{Bypassing token filter with non-blacklisted URL}},
  author       = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
  year         = {2021},
  note         = {VAITP Python Vulnerability Dataset, entry CVE-2021-41250},
  howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2021-41250/}}
}
Introducing the "VAITP dataset": a specialized repository of Python vulnerabilities and patches, meticulously compiled for the use of the security research community. As Python's prominence grows, understanding and addressing potential security vulnerabilities become crucial. Crafted by and for the cybersecurity community, this dataset offers a valuable resource for researchers, analysts, and developers to analyze and mitigate the security risks associated with Python. Through the comprehensive exploration of vulnerabilities and corresponding patches, the VAITP dataset fosters a safer and more resilient Python ecosystem, encouraging collaborative advancements in programming security.

The supreme art of war is to subdue the enemy without fighting.

Sun Tzu – “The Art of War”

:: Shaping the future through research and ingenuity ::