VAITP Dataset

← Back to the dataset

CVE-2024-9774

Unary operators don't escape non-Expression in python-sql.

  • CVSS 6.5
  • CWE-150
  • Input Validation and Sanitization
  • Remote

A vulnerability was found in python-sql where unary operators do not escape non-Expression.

CVSS base score
6.5
Published
2024-12-27
OWASP
A01 Broken Access Control
Orthogonal defect classification
Algorithm
Code defect classification
Incorrect Functionality
Category
Input Validation and Sanitization
Subcategory
SQL Injection
Accessibility scope
Remote
Impact
Arbitrary Code Execution
Affected component
python-sql
Fixed by upgrading
Yes

Solution

Upgrade to python-sql >= 0.4.9.

Vulnerable code sample

from sql import SQL
from sql.conditionals import Expression

class User:
    def __init__(self, name, age):
        self.name = name
        self.age = age

sql_obj = SQL()

user1 = User("Alice", 30)
user2 = User("Bob", 25)

users_query = sql_obj.select("*").from_("users").where(+user1) 

print(users_query.get_query())

Patched code sample

from sql import SQL
from sql.conditionals import Expression

class User:
    def __init__(self, name, age):
        self.name = name
        self.age = age

    def to_query_conditions(self):
        return Expression(self.name, '=', self.name).and_(Expression(self.age, '=', self.age))

sql_obj = SQL()

user1 = User("Alice", 30)
user2 = User("Bob", 25)

users_query = sql_obj.select("*").from_("users").where(user1.to_query_conditions())

print(users_query.get_query())

Payload

`SELECT -'1';`

Cite this entry

@misc{vaitp:cve20249774,
  title        = {{Unary operators don't escape non-Expression in python-sql.
}},
  author       = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
  year         = {2024},
  note         = {VAITP Python Vulnerability Dataset, entry CVE-2024-9774},
  howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2024-9774/}}
}
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 ::