VAITP Dataset

← Back to the dataset

CVE-2024-32005

Local file inclusion vulnerability in NiceGUI allows unauthorized file access.

  • CVSS 8.2
  • CWE-22
  • Input Validation and Sanitization
  • Remote

NiceGUI is an easy-to-use, Python-based UI framework. A local file inclusion is present in the NiceUI leaflet component when requesting resource files under the `/_nicegui/{__version__}/resources/{key}/{path:path}` route. As a result any file on the backend filesystem which the web server has access to can be read by an attacker with access to the NiceUI leaflet website. This vulnerability has been addressed in version 1.4.21. Users are advised to upgrade. There are no known workarounds for this vulnerability.

CVSS base score
8.2
Published
2024-04-12
OWASP
A06 Security Misconfiguration
Orthogonal defect classification
Checking
Code defect classification
Incorrect Functionality
Category
Input Validation and Sanitization
Subcategory
Local File Inclusion (LFI)
Accessibility scope
Remote
Impact
Information Disclosure
Fixed by upgrading
Yes

Solution

Upgrade to NiceGUI version 1.4.21 or later.

Vulnerable code sample

from nicegui import ui

@ui.route('/_nicegui/{__version__}/resources/{key}/{path:path}')
def serve_resource(key, path):
    return ui.send_file(f'resources/{key}/{path}')

ui.run()

Patched code sample

from nicegui import ui
from fastapi.responses import FileResponse
from pathlib import Path

SAFE_BASE_DIR = Path('resources').resolve()
ALLOWED_EXTENSIONS = {'.txt', '.csv'}

@ui.route('/_nicegui/{__version__}/resources/{key}/{path:path}')
def serve_resource(key: str, path: str):
    requested_path = (SAFE_BASE_DIR / key / path).resolve()

    if not requested_path.is_file():
        return {'error': 'File not found'}

    if not str(requested_path).startswith(str(SAFE_BASE_DIR)):
        return {'error': 'Access denied'}

    if requested_path.suffix.lower() not in ALLOWED_EXTENSIONS:
        return {'error': 'Only .txt and .csv files are allowed'}

    return FileResponse(requested_path)

ui.run()

Payload

/_nicegui/1.4.20/resources/key/../../../../etc/passwd

Cite this entry

@misc{vaitp:cve202432005,
  title        = {{Local file inclusion vulnerability in NiceGUI allows unauthorized file access.}},
  author       = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
  year         = {2024},
  note         = {VAITP Python Vulnerability Dataset, entry CVE-2024-32005},
  howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2024-32005/}}
}
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 ::