VAITP Dataset

← Back to the dataset

CVE-2023-41626

Gradio v3.27.0 /upload interface allows arbitrary file uploads, a severe security vulnerability

  • CVSS 4.8
  • CWE-434 Unrestricted Upload of File with Dangerous Type
  • Information Leakage
  • Remote

Gradio v3.27.0 was discovered to contain an arbitrary file upload vulnerability via the /upload interface.

CVSS base score
4.8
Published
2023-09-15
OWASP
A05 Security Misconfiguration
Orthogonal defect classification
Function
Code defect classification
Incorrect Functionality
Category
Information Leakage
Subcategory
Insecure Handling of Sensitive Data
Accessibility scope
Remote
Impact
Arbitrary Code Execution
Affected component
Gradio
Fixed by upgrading
Yes

Solution

Update Gradio to version 3.28.0 or higher.

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
    # Vulnerable code: directly saving the file without validation
    file.save('/path/to/save/' + file.filename)  # Potential for arbitrary file upload
    return 'File uploaded successfully', 200

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

Patched code sample

import os
from flask import Flask, request, jsonify

app = Flask(__name__)

# Define allowed file extensions
ALLOWED_EXTENSIONS = {'txt', 'pdf', 'png', 'jpg', 'jpeg', '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:
        return jsonify({'error': 'No file part'}), 400
    file = request.files['file']
    if file.filename == '':
        return jsonify({'error': 'No selected file'}), 400
    if file and allowed_file(file.filename):
        # Save the file securely
        safe_filename = secure_filename(file.filename)
        file.save(os.path.join('/path/to/save', safe_filename))
        return jsonify({'success': 'File uploaded successfully'}), 200
    else:
        return jsonify({'error': 'File type not allowed'}), 400

def secure_filename(filename):
    # Implement a function to sanitize the filename
    return filename.replace('/', '_').replace('\\', '_')

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

Cite this entry

@misc{vaitp:cve202341626,
  title        = {{Gradio v3.27.0 /upload interface allows arbitrary file uploads, a severe security vulnerability}},
  author       = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
  year         = {2023},
  note         = {VAITP Python Vulnerability Dataset, entry CVE-2023-41626},
  howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2023-41626/}}
}

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.