CVE-2024-5753
SQL injection in vanna v0.3.4 allows unauthorized file access.
- CVSS 7.5
- CWE-89
- Input Validation and Sanitization
- Remote
vanna-ai/vanna version v0.3.4 is vulnerable to SQL injection in some file-critical functions such as `pg_read_file()`. This vulnerability allows unauthenticated remote users to read arbitrary local files on the victim server, including sensitive files like `/etc/passwd`, by exploiting the exposed SQL queries via a Python Flask API.
- CWE
- CWE-89
- CVSS base score
- 7.5
- Published
- 2024-07-05
- OWASP
- A01 Injection
- Orthogonal defect classification
- Function
- Code defect classification
- Incorrect Functionality
- Category
- Input Validation and Sanitization
- Subcategory
- SQL Injection
- Accessibility scope
- Remote
- Impact
- Information Disclosure
- Affected component
- vanna
- Fixed by upgrading
- Yes
Solution
Upgrade to v0.3.5 or later, and implement parameterized queries to prevent SQL injection.
Vulnerable code sample
from flask import Flask, request
import psycopg2
app = Flask(__name__)
def get_db_connection():
"""Vulnerable function that demonstrates the security issue."""
return psycopg2.connect("dbname=test user=postgres password=secret")
@app.route('/read_file', methods=['GET'])
def read_file():
"""Vulnerable function that demonstrates the security issue."""
filename = request.args.get('filename')
with get_db_connection() as conn:
with conn.cursor() as cursor:
cursor.execute(f"SELECT pg_read_file('{filename}');")
file_content = cursor.fetchone()
return file_content if file_content else "File not found", 200
if __name__ == '__main__':
app.run()Patched code sample
from flask import Flask, request
import psycopg2
app = Flask(__name__)
def get_db_connection():
"""Secure function that fixes the vulnerability."""
# SECURE: This version prevents sql injection
return psycopg2.connect("dbname=test user=postgres password=secret")
@app.route('/read_file', methods=['GET'])
def read_file():
"""Secure function that fixes the vulnerability."""
filename = request.args.get('filename')
with get_db_connection() as conn:
with conn.cursor() as cursor:
cursor.execute("SELECT pg_read_file(%s);", (filename,))
file_content = cursor.fetchone()
return file_content if file_content else "File not found", 200
if __name__ == '__main__':
app.run()Payload
`/etc/passwd`
Cite this entry
@misc{vaitp:cve20245753,
title = {{SQL injection in vanna v0.3.4 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-5753},
howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2024-5753/}}
}
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 ::
