VAITP Dataset

← Back to the dataset

CVE-2024-23334

Directory traversal vulnerability in aiohttp when follow_symlinks is True.

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

aiohttp is an asynchronous HTTP client/server framework for asyncio and Python. When using aiohttp as a web server and configuring static routes, it is necessary to specify the root path for static files. Additionally, the option 'follow_symlinks' can be used to determine whether to follow symbolic links outside the static root directory. When 'follow_symlinks' is set to True, there is no validation to check if reading a file is within the root directory. This can lead to directory traversal vulnerabilities, resulting in unauthorized access to arbitrary files on the system, even when symlinks are not present. Disabling follow_symlinks and using a reverse proxy are encouraged mitigations. Version 3.9.2 fixes this issue.

CVSS base score
7.5
Published
2024-01-29
OWASP
A05 Security Misconfiguration
Orthogonal defect classification
Checking
Code defect classification
Incorrect Check
Category
Input Validation and Sanitization
Subcategory
Path Traversal
Accessibility scope
Remote
Impact
Unauthorized Access
Affected component
aiohttp
Fixed by upgrading
Yes

Solution

Upgrade to aiohttp version 3.9.2 or later and disable follow_symlinks.

Vulnerable code sample

from aiohttp import web

async def handle(request):
    return web.FileResponse('./static' + request.match_info['filename'])

app = web.Application()
app.router.add_get('/static/{filename:.*}', handle)

web.run_app(app)

Patched code sample

from aiohttp import web
from pathlib import Path

STATIC_DIR = Path('./static').resolve()

async def handle(request):
    filename = request.match_info['filename']
    requested_path = (STATIC_DIR / filename).resolve()

    if not str(requested_path).startswith(str(STATIC_DIR)) or not requested_path.is_file():
        return web.Response(status=403, text="Access denied")

    return web.FileResponse(requested_path)

app = web.Application()
app.router.add_get('/static/{filename:.*}', handle)

web.run_app(app)

Payload

GET /static/../../../../etc/passwd HTTP/1.1
Host: vulnerable-server.com

Cite this entry

@misc{vaitp:cve202423334,
  title        = {{Directory traversal vulnerability in aiohttp when follow_symlinks is True.}},
  author       = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
  year         = {2024},
  note         = {VAITP Python Vulnerability Dataset, entry CVE-2024-23334},
  howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2024-23334/}}
}
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 ::