VAITP Dataset

← Back to the dataset

CVE-2022-31575

GitHub repository duducosmos/livro_python: Absolute 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 duducosmos/livro_python repository through 2018-06-06 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
A01 Broken Access Control
Orthogonal defect classification
Interface
Code defect classification
Incorrect Interface
Category
Input Validation and Sanitization
Subcategory
Path Traversal
Accessibility scope
Remote
Impact
Information Disclosure
Affected component
Flask
Fixed by upgrading
Yes

Solution

Fix by updating Flask and the duducosmos/livro_python repository to the latest versions

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 that allows absolute path traversal
    return send_file(filename)

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

Patched code sample

from flask import Flask, send_file, abort, safe_join, send_from_directory
import os

app = Flask(__name__)

@app.route('/download/<path:filename>')
def download_file(filename):
    # Define a safe directory to serve files from
    safe_directory = '/path/to/safe/directory'
    
    # Use safe_join to prevent absolute path traversal
    safe_path = safe_join(safe_directory, filename)

    # Check if the file exists and is within the safe directory
    if os.path.isfile(safe_path):
        return send_file(safe_path)
    else:
        abort(404)

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

Cite this entry

@misc{vaitp:cve202231575,
  title        = {{GitHub repository duducosmos/livro_python: Absolute 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-31575},
  howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2022-31575/}}
}

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.