VAITP Dataset

← Back to the dataset

CVE-2024-10955

ReDoS in chuanhuchatgpt allows DoS via crafted regex pattern, consuming excessive CPU.

  • CVSS 6.5
  • CWE-1333
  • Design Defects
  • Remote

A Regular Expression Denial of Service (ReDoS) vulnerability exists in gaizhenbiao/chuanhuchatgpt, as of commit 20b2e02. The server uses the regex pattern `r']+>'` to parse user input. In Python's default regex engine, this pattern can take polynomial time to match certain crafted inputs. An attacker can exploit this by uploading a malicious JSON payload, causing the server to consume 100% CPU for an extended period. This can lead to a Denial of Service (DoS) condition, potentially affecting the entire server.

CVSS base score
6.5
Published
2025-03-20
OWASP
A03 Injection
Orthogonal defect classification
Algorithm
Code defect classification
Incorrect Algorithm
Category
Design Defects
Subcategory
Input Validation and Sanitization
Accessibility scope
Remote
Impact
Denial of Service (DoS)
Affected component
Python
Fixed by upgrading
Yes

Solution

Upgrade to a version with patched regex or implement a timeout for regex matching.

Vulnerable code sample

import re
import time

def process_input(user_input):
    """
    Processes user input using a vulnerable regular expression.
    """
    pattern = re.compile(r"']+>") # Vulnerable regex: r']+>'
    match = pattern.search(user_input)
    if match:
        print("Match found:", match.group(0))
    else:
        print("No match found.")

if __name__ == "__main__":
    # Example of a malicious input that can trigger ReDoS
    malicious_input = "'" * 50 + ">"  #Crafted input
    print("Processing malicious input...")
    start_time = time.time()
    process_input(malicious_input)
    end_time = time.time()
    print(f"Processing time: {end_time - start_time:.4f} seconds")

Patched code sample

import re

def sanitize_input(user_input):
    """
    Sanitizes user input to prevent ReDoS.

    Instead of directly using the vulnerable regex `r']+>'`, 
    this function limits the repetition and uses a more efficient pattern.
    It removes excessive repetitions of ']' characters before '>'.
    """
    # Limit the number of consecutive ']' characters to prevent exponential backtracking.
    sanitized_input = re.sub(r']{20,}', ']' * 20, user_input)  # Limit to 20 repetitions

    # Now apply a safer regex for the intended purpose. This regex avoids nested quantifiers 
    # and excessive backtracking potential.  Adjust the pattern based on the *actual*
    # data you are trying to extract or validate.  This is just a placeholder.
    #This is a safe version
    safe_pattern = r']+[>]'
    
    # This regex might work in some cases too
    #safe_pattern = r'][>]'
    
    match = re.search(safe_pattern, sanitized_input)
    if match:
        return match.group(0) #return the matching portion of the string

    return None

# Example usage (replace with your actual input handling)
def process_input(user_input):
    sanitized_input = sanitize_input(user_input)
    if sanitized_input:
        print("Processed input:", sanitized_input)
    else:
        print("Invalid input or no match found.")

# Demonstration with potentially malicious input:
#process_input("]" * 1000 + ">")  # Demonstrates the ReDoS vulnerability
#This may still be vulnerable to other attacks but greatly reduces risk.
#process_input("normal text][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][>]") #Demonstrates the limitation.
#This is the proper use:
#process_input("The quick brown fox jumps over the lazy dog][>]")

Payload

{
  "message": "]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]>"
}

Cite this entry

@misc{vaitp:cve202410955,
  title        = {{ReDoS in chuanhuchatgpt allows DoS via crafted regex pattern, consuming excessive CPU.
}},
  author       = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
  year         = {2025},
  note         = {VAITP Python Vulnerability Dataset, entry CVE-2024-10955},
  howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2024-10955/}}
}
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 ::