VAITP Dataset

← Back to the dataset

CVE-2022-31516

GitHub Harveyzyh/Python repo: Path traversal via Flask send_file

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

The Harveyzyh/Python repository through 2022-05-04 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
A10 Server-Side Request Forgery (SSRF)
Orthogonal defect classification
Function
Code defect classification
Incorrect Functionality
Category
Input Validation and Sanitization
Subcategory
Path Traversal
Accessibility scope
Remote
Impact
Unauthorized Access
Affected component
Python
Fixed by upgrading
Yes

Solution

Update Flask to version 2.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):
    # Vulnerable to 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/<filename>')
def download_file(filename):
    # Sanitize the filename to prevent absolute path traversal
    safe_filename = os.path.basename(filename)
    file_path = os.path.join('safe_directory', safe_filename)

    if os.path.isfile(file_path):
        return send_file(file_path)
    else:
        abort(404)

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

Cite this entry

@misc{vaitp:cve202231516,
  title        = {{GitHub Harveyzyh/Python repo: Path traversal via Flask send_file}},
  author       = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
  year         = {2022},
  note         = {VAITP Python Vulnerability Dataset, entry CVE-2022-31516},
  howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2022-31516/}}
}

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.