VAITP Dataset

← Back to the dataset

CVE-2021-43775

Path traversal vuln pre Aim 3.1.0: Unauth file system access

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

Aim is an open-source, self-hosted machine learning experiment tracking tool. Versions of Aim prior to 3.1.0 are vulnerable to a path traversal attack. By manipulating variables that reference files with “dot-dot-slash (../)� sequences and its variations or by using absolute file paths, it may be possible to access arbitrary files and directories stored on file system including application source code or configuration and critical system files. The vulnerability issue is resolved in Aim v3.1.0.

CVSS base score
8.6
Published
2021-11-23
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
Aim
Fixed by upgrading
Yes

Solution

Update Aim to version 3.1.0 or higher.

Vulnerable code sample

import os
from flask import Flask, request, send_file

app = Flask(__name__)

@app.route('/get-file', methods=['GET'])
def get_file():
    # Directly using user input to construct file path
    file_name = request.args.get('file')
    file_path = os.path.join('/some/directory', file_name)
    
    # This allows for potential path traversal attacks
    return send_file(file_path)

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

Patched code sample

import os
from flask import Flask, request, abort

app = Flask(__name__)

def safe_join(base_path, *paths):
    # Safely join the base path with the provided paths
    final_path = os.path.join(base_path, *paths)
    # Ensure the final path is within the base directory
    if not os.path.commonprefix([final_path, base_path]) == base_path:
        abort(403)  # Forbidden access
    return final_path

@app.route('/get-file', methods=['GET'])
def get_file():
    base_path = '/safe/directory'  # Set a safe base directory
    file_name = request.args.get('file')
    
    # Use safe_join to prevent path traversal
    safe_path = safe_join(base_path, file_name)
    
    if os.path.isfile(safe_path):
        return send_file(safe_path)
    else:
        abort(404)  # File not found

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

Published fix

Public sources link this CVE to the changes below. The code samples above were generated to illustrate the defect; these links lead to the code the project actually changed.

Cite this entry

@misc{vaitp:cve202143775,
  title        = {{Path traversal vuln pre Aim 3.1.0: Unauth file system access}},
  author       = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
  year         = {2021},
  note         = {VAITP Python Vulnerability Dataset, entry CVE-2021-43775},
  howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2021-43775/}}
}

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.