VAITP Dataset

← Back to the dataset

CVE-2024-52804

Tornado's cookie parsing algorithm can lead to excessive CPU usage.

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

Tornado is a Python web framework and asynchronous networking library. The algorithm used for parsing HTTP cookies in Tornado versions prior to 6.4.2 sometimes has quadratic complexity, leading to excessive CPU consumption when parsing maliciously-crafted cookie headers. This parsing occurs in the event loop thread and may block the processing of other requests. Version 6.4.2 fixes the issue.

CVSS base score
7.5
Published
2024-11-22
OWASP
A06 Security Misconfiguration
Orthogonal defect classification
Algorithm
Code defect classification
Incorrect Algorithm
Category
Resource Management
Subcategory
Resource Exhaustion
Accessibility scope
Remote
Impact
Denial of Service (DoS)
Affected component
Tornado
Fixed by upgrading
Yes

Solution

Upgrade to Tornado version 6.4.2 or later.

Vulnerable code sample

import tornado.web
import tornado.ioloop

class MainHandler(tornado.web.RequestHandler):
    def get(self):
        cookie_header = "cookie=" + "a" * 1000000
        self.request.headers['Cookie'] = cookie_header
        parsed_cookies = self.get_cookies(self.request.headers['Cookie'])
        self.write("Parsed cookies: {}".format(parsed_cookies))

    def get_cookies(self, cookie_header):
        cookies = {}
        for cookie in cookie_header.split(';'):
            key, value = cookie.split('=', 1)
            cookies[key.strip()] = value.strip()
        return cookies

def make_app():
    return tornado.web.Application([
        (r"/", MainHandler),
    ])

if __name__ == "__main__":
    app = make_app()
    app.listen(8888)
    tornado.ioloop.IOLoop.current().start()

Patched code sample

import tornado.web
import tornado.ioloop

MAX_COOKIE_HEADER_SIZE = 8192

class MainHandler(tornado.web.RequestHandler):
    def get(self):
        cookie_header = "cookie=" + "a" * 1000
        if len(cookie_header) > MAX_COOKIE_HEADER_SIZE:
            self.set_status(400)
            self.write("Cookie header too large.")
            return

        try:
            parsed_cookies = self.get_cookies(cookie_header)
        except ValueError:
            self.set_status(400)
            self.write("Malformed cookie.")
            return

        self.write("Parsed cookies: {}".format(parsed_cookies))

    def get_cookies(self, cookie_header):
        cookies = {}
        for cookie in cookie_header.split(';'):
            if '=' not in cookie:
                raise ValueError("Malformed cookie")
            key, value = cookie.split('=', 1)
            cookies[key.strip()] = value.strip()
        return cookies

def make_app():
    return tornado.web.Application([
        (r"/", MainHandler),
    ])

if __name__ == "__main__":
    app = make_app()
    app.listen(8888)
    tornado.ioloop.IOLoop.current().start()

Payload

malicious_cookie=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

Cite this entry

@misc{vaitp:cve202452804,
  title        = {{Tornado's cookie parsing algorithm can lead to excessive CPU usage.}},
  author       = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
  year         = {2024},
  note         = {VAITP Python Vulnerability Dataset, entry CVE-2024-52804},
  howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2024-52804/}}
}
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 ::