VAITP Dataset

← Back to the dataset

CVE-2022-2634

Python file upload and execution via web app due to weak access controls

  • CVSS 9.8
  • CWE-250 Execution with Unnecessary Privileges
  • Input Validation and Sanitization
  • Remote

An attacker may be able to execute malicious actions due to the lack of device access protections and device permissions when using the web application. This could lead to uploading python files which can be later executed.

CVSS base score
9.8
Published
2022-08-10
OWASP
A05 Security Misconfiguration
Orthogonal defect classification
Checking
Code defect classification
Missing Check
Category
Input Validation and Sanitization
Subcategory
Insecure Direct Object References (IDOR)
Accessibility scope
Remote
Impact
Arbitrary Code Execution
Affected component
Python

Solution

Implement proper access controls and permissions.

Vulnerable code sample

from flask import Flask, request

app = Flask(__name__)

@app.route('/upload', methods=['POST'])
def upload_file():
    if 'file' not in request.files:
        return 'No file part', 400
    
    file = request.files['file']
    
    if file.filename == '':
        return 'No selected file', 400
    
    # Directly save the uploaded file without checking its type
    file.save(f'/path/to/upload/{file.filename}')
    return 'File successfully uploaded', 200

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

Patched code sample

from flask import Flask, request, abort
import os

app = Flask(__name__)

# Define allowed file extensions
ALLOWED_EXTENSIONS = {'txt', 'jpg', 'jpeg', 'png', 'gif'}

def allowed_file(filename):
    return '.' in filename and filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS

@app.route('/upload', methods=['POST'])
def upload_file():
    if 'file' not in request.files:
        abort(400, 'No file part')
    
    file = request.files['file']
    
    if file.filename == '':
        abort(400, 'No selected file')
    
    if file and allowed_file(file.filename):
        # Securely save the file
        filename = secure_filename(file.filename)
        file.save(os.path.join('/path/to/upload', filename))
        return 'File successfully uploaded', 200
    else:
        abort(400, 'File type not allowed')

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

Cite this entry

@misc{vaitp:cve20222634,
  title        = {{Python file upload and execution via web app due to weak access controls}},
  author       = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
  year         = {2022},
  note         = {VAITP Python Vulnerability Dataset, entry CVE-2022-2634},
  howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2022-2634/}}
}

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.