VAITP Dataset

← Back to the dataset

CVE-2022-31571

Path traversal vulnerability in akashtalole/python-flask-restful-api on GitHub before 2019-09-16 due to unsafe use of Flask's send_file function

  • CVSS 9.3
  • CWE-22 Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')
  • Input Validation and Sanitization
  • Remote

The akashtalole/python-flask-restful-api repository through 2019-09-16 on GitHub allows absolute path traversal because the Flask send_file function is used unsafely.

CVSS base score
9.3
Published
2022-07-11
OWASP
A05 Security Misconfiguration
Orthogonal defect classification
Function
Code defect classification
Incorrect Functionality
Category
Input Validation and Sanitization
Subcategory
Path Traversal
Accessibility scope
Remote
Impact
Information Disclosure
Affected component
Python
Fixed by upgrading
Yes

Solution

Update Flask to version 1.1.0 or higher.

Vulnerable code sample

from flask import Flask, send_file

app = Flask(__name__)

@app.route('/download/<path:filename>')
def download_file(filename):
    # Unsafe use of send_file allowing absolute path traversal
    return send_file(filename)

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

Patched code sample

from flask import Flask, send_file, abort
import os

app = Flask(__name__)

@app.route('/download/<path:filename>')
def download_file(filename):
    # Secure the file path to prevent absolute path traversal
    safe_base_path = '/safe/directory/'
    safe_path = os.path.join(safe_base_path, filename)

    # Ensure the safe_path is within the safe_base_path
    if not os.path.abspath(safe_path).startswith(os.path.abspath(safe_base_path)):
        abort(403)  # Forbidden

    return send_file(safe_path)

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

Cite this entry

@misc{vaitp:cve202231571,
  title        = {{Path traversal vulnerability in akashtalole/python-flask-restful-api on GitHub before 2019-09-16 due to unsafe use of Flask's send_file function}},
  author       = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
  year         = {2022},
  note         = {VAITP Python Vulnerability Dataset, entry CVE-2022-31571},
  howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2022-31571/}}
}

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.