VAITP Dataset

← Back to the dataset

CVE-2024-39903

Local File Inclusion vulnerability in Solara due to improper URI validation.

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

Solara is a pure Python, React-style framework for scaling Jupyter and web apps. A Local File Inclusion (LFI) vulnerability was identified in widgetti/solara, in version <1.35.1, which was fixed in version 1.35.1. This vulnerability arises from the application's failure to properly validate URI fragments for directory traversal sequences such as '../' when serving static files. An attacker can exploit this flaw by manipulating the fragment part of the URI to read arbitrary files on the local file system.

CVSS base score
7.5
Published
2024-07-12
OWASP
A05 Security Misconfiguration
Orthogonal defect classification
Checking
Code defect classification
Incorrect Check
Category
Input Validation and Sanitization
Subcategory
Local File Inclusion (LFI)
Accessibility scope
Remote
Impact
Information Disclosure
Affected component
Solara
Fixed by upgrading
Yes

Solution

Upgrade to version 1.35.1 or later.

Vulnerable code sample

import os
from urllib.parse import urlparse, unquote

def serve_static(uri: str) -> bytes:
    # VULNERABLE: no validation of path traversal in fragment
    parsed = urlparse(uri)
    rel_path = unquote(parsed.fragment)
    full_path = os.path.join("static", rel_path)
    with open(full_path, "rb") as f:
        return f.read()

Patched code sample

import os
from pathlib import Path
from urllib.parse import urlparse, unquote

def serve_static(uri: str) -> bytes:
    # FIX: normalize and restrict path to static directory
    parsed = urlparse(uri)
    rel_path = unquote(parsed.fragment)
    base = Path("static").resolve()
    target = (base / rel_path).resolve()
    if not str(target).startswith(str(base)):
        raise PermissionError("Invalid path")
    with open(target, "rb") as f:
        return f.read()

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.

  • fix: CVE followup, do not serve relative files (widgetti/solara)
    solara/server/cdn_helper.py, solara/server/cdn_helper.py · get_from_cache, solara/server/cdn_helper.py · get_path, solara/server/cdn_helper.py · put_in_cache, solara/server/flask.py, solara/server/flask.py · nbext, solara/server/starlette.py, solara/server/starlette.py · StaticNbFiles.lookup_path, solara/server/utils.py

Payload

/files/../../etc/passwd

Cite this entry

@misc{vaitp:cve202439903,
  title        = {{Local File Inclusion vulnerability in Solara due to improper URI validation.}},
  author       = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
  year         = {2024},
  note         = {VAITP Python Vulnerability Dataset, entry CVE-2024-39903},
  howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2024-39903/}}
}

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.