VAITP Dataset

← Back to the dataset

CVE-2024-49767

Werkzeug prior to 3.0.6 is vulnerable to resource exhaustion attacks.

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

Werkzeug is a Web Server Gateway Interface web application library. Applications using `werkzeug.formparser.MultiPartParser` corresponding to a version of Werkzeug prior to 3.0.6 to parse `multipart/form-data` requests (e.g. all flask applications) are vulnerable to a relatively simple but effective resource exhaustion (denial of service) attack. A specifically crafted form submission request can cause the parser to allocate and block 3 to 8 times the upload size in main memory. There is no upper limit; a single upload at 1 Gbit/s can exhaust 32 GB of RAM in less than 60 seconds. Werkzeug version 3.0.6 fixes this issue.

CVSS base score
6.9
Published
2024-10-25
OWASP
A05 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
Werkzeug
Fixed by upgrading
Yes

Solution

Upgrade Werkzeug to version 3.0.6 or later.

Vulnerable code sample

from flask import Flask, request

app = Flask(__name__)

@app.route('/upload', methods=['POST'])
def upload_file():
    file = request.files['file']
    file.save(f"./uploads/{file.filename}")
    return "File uploaded successfully", 200

if __name__ == '__main__':
    app.run()

Patched code sample

from flask import Flask, request

app = Flask(__name__)

@app.route('/upload', methods=['POST'])
def upload_file():
    if request.content_length > 16 * 1024 * 1024:
        return "File too large", 413
    file = request.files['file']
    file.save(f"./uploads/{file.filename}")
    return "File uploaded successfully", 200

if __name__ == '__main__':
    app.run()

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.

  • apply max_form_memory_size another level up in the parser (pallets/quart)
    src/quart/formparser.py, src/quart/formparser.py · MultiPartParser.parse
  • Support max_form_parts and max_form_memory_size (pallets/quart)
    src/quart/app.py, src/quart/app.py · Quart.log_exception, src/quart/formparser.py · FormDataParser._parse_multipart, src/quart/formparser.py · FormDataParser._parse_urlencoded, src/quart/formparser.py · FormDataParser.__init__, src/quart/formparser.py · MultiPartParser.parse, src/quart/formparser.py · MultiPartParser.__init__, src/quart/wrappers/base.py, src/quart/wrappers/request.py, src/quart/wrappers/request.py · Request.make_form_data_parser
  • apply max_form_memory_size another level up in the parser (pallets/werkzeug)
    src/werkzeug/formparser.py · MultiPartParser.parse, src/werkzeug/sansio/multipart.py · MultipartDecoder.receive_data
  • Refactor the Multipart parsing into a Sans-IO layer (pallets/werkzeug)
    setup.py, src/werkzeug/formparser.py, src/werkzeug/formparser.py · MultiPartParser.parse, src/werkzeug/formparser.py · MultiPartParser.start_file_streaming, src/werkzeug/formparser.py · MultiPartParser.__init__, src/werkzeug/formparser.py · parse_multipart_headers, src/werkzeug/test.py, src/werkzeug/test.py · stream_encode_multipart, src/werkzeug/_internal.py · _to_str#3

Payload

POST /upload HTTP/1.1
Host: vulnerable-app.com
Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Length: 1000000000

------WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="file"; filename="largefile.bin"
Content-Type: application/octet-stream

<binary data>
------WebKitFormBoundary7MA4YWxkTrZu0gW--

Cite this entry

@misc{vaitp:cve202449767,
  title        = {{Werkzeug prior to 3.0.6 is vulnerable to resource exhaustion attacks.}},
  author       = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
  year         = {2024},
  note         = {VAITP Python Vulnerability Dataset, entry CVE-2024-49767},
  howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2024-49767/}}
}

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.