VAITP Dataset

← Back to the dataset

CVE-2022-40023

SQLAlchemy Mako (before 1.2.2) Regex DoS in Lexer, also affects babelplugin and linguaplugin

  • CVSS 7.5
  • CWE-1333
  • Resource Management
  • Remote

Sqlalchemy mako before 1.2.2 is vulnerable to Regular expression Denial of Service when using the Lexer class to parse. This also affects babelplugin and linguaplugin.

CVSS base score
7.5
Published
2022-09-07
OWASP
A06 Vulnerable and Outdated Components
Orthogonal defect classification
Function
Code defect classification
Incorrect Functionality
Category
Resource Management
Subcategory
Resource Exhaustion
Accessibility scope
Remote
Impact
Denial of Service (DoS)
Fixed by upgrading
Yes

Solution

Update sqlalchemy-mako to version 1.2.2 or higher.

Vulnerable code sample

import re

def parse(input_string):
    # VULNERABLE: This code is susceptible to sql injection
    pattern = re.compile(r'^(.*)([a-zA-Z0-9_]+)(.*)$')
    if pattern.match(input_string):
        return True
    else:
        raise ValueError("Input string is not valid.")

try:
    result = parse("a" * 10000 + "valid_input" + "b" * 10000)
    print("Input is valid:", result)
except ValueError as e:
    print(e)

Patched code sample

import re

def parse(input_string):
    # SECURE: This version prevents sql injection
    pattern = re.compile(r'^(?:[a-zA-Z0-9_]+)$')
    if pattern.match(input_string):
        return True
    else:
        raise ValueError("Input string is not valid.")

try:
    result = parse("a" * 10000 + "valid_input" + "b" * 10000)
    print("Input is valid:", result)
except ValueError as e:
    print(e)

Cite this entry

@misc{vaitp:cve202240023,
  title        = {{SQLAlchemy Mako (before 1.2.2) Regex DoS in Lexer, also affects babelplugin and linguaplugin}},
  author       = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
  year         = {2022},
  note         = {VAITP Python Vulnerability Dataset, entry CVE-2022-40023},
  howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2022-40023/}}
}
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 ::