VAITP Dataset

← Back to the dataset

CVE-2021-21236

CairoSVG < 2.5.1: Vulnerable to SVG REDoS

  • CVSS 5.5
  • CWE-400 Uncontrolled Resource Consumption
  • Input Validation and Sanitization
  • Remote

CairoSVG is a Python (pypi) package. CairoSVG is an SVG converter based on Cairo. In CairoSVG before version 2.5.1, there is a regular expression denial of service (REDoS) vulnerability. When processing SVG files, the python package CairoSVG uses two regular expressions which are vulnerable to Regular Expression Denial of Service (REDoS). If an attacker provides a malicious SVG, it can make cairosvg get stuck processing the file for a very long time. This is fixed in version 2.5.1. See Referenced GitHub advisory for more information.

CVSS base score
5.5
Published
2021-01-06
OWASP
A06 Vulnerable and Outdated Components
Orthogonal defect classification
Function
Code defect classification
Incorrect Functionality
Category
Input Validation and Sanitization
Subcategory
Insecure Parsing or Deserialization
Accessibility scope
Remote
Impact
Denial of Service (DoS)
Affected component
CairoSVG
Fixed by upgrading
Yes

Solution

Update CairoSVG to version 2.5.1 or higher.

Vulnerable code sample

import re

# Example of vulnerable regular expressions that could lead to a REDoS attack
def vulnerable_svg_processing(svg_content):
    # Vulnerable regex patterns that can cause catastrophic backtracking
    vulnerable_regex = r'<svg.*>(.*?)</svg>'  # Greedy match for SVG content
    # Another example of a complex regex that could be vulnerable
    complex_regex = r'<path d="(.*?)" fill="(.*?)"'  # Potentially problematic regex
    matches = re.findall(vulnerable_regex, svg_content)
    return matches

# Example usage with a potentially malicious SVG input
malicious_svg_content = "<svg>" + "A" * 10000 + "</svg>"  # Example of a crafted input
processed_svg = vulnerable_svg_processing(malicious_svg_content)

Patched code sample

import re

# Example of a safer regular expression that avoids catastrophic backtracking
# This is a simplified representation and may not be the exact fix for CairoSVG
def safe_svg_processing(svg_content):
    # Avoiding complex nested quantifiers that lead to backtracking
    # This is a placeholder regex for demonstration purposes
    safe_regex = r'<svg.*?>(.*?)</svg>'  # Non-greedy match for SVG content
    matches = re.findall(safe_regex, svg_content)
    return matches

# Example usage
svg_content = "<svg>...</svg>"  # Replace with actual SVG content
processed_svg = safe_svg_processing(svg_content)

Published fix

Public sources link this CVE to the changes below. The code samples above were generated to illustrate the defect; these links lead to the code the project actually changed.

Cite this entry

@misc{vaitp:cve202121236,
  title        = {{CairoSVG < 2.5.1: Vulnerable to SVG REDoS}},
  author       = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
  year         = {2021},
  note         = {VAITP Python Vulnerability Dataset, entry CVE-2021-21236},
  howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2021-21236/}}
}

Download this entry as JSON Download the whole dataset

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 ::

Before you use the VAITP AI models

Please read and accept the following disclaimer:

By choosing "I understand and accept", you acknowledge that you understand and agree to these terms.