CVE-2026-26198: Ormar ORM SQL Injection Vulnerability via Aggregate Functions
Summary
CVE-2026-26198: ormar is vulnerable to SQL Injection through aggregate functions min() and max(). Affects ormar versions >= 0.9.9, < 0.23.0. Fixed in 0.23.0. How to fix ↓
Check if this vulnerability affects your application
Upload a manifest or SBOM and we'll show whether you're affected, plus every other risky package in the same scan.
No signup required · Results in about 60 seconds
Background
Ormar is an asynchronous ORM (Object-Relational Mapping) library for Python that simplifies database interactions by allowing developers to work with Python objects instead of SQL queries. It is built on top of SQLAlchemy and is designed to be user-friendly, providing features such as automatic schema generation, validation, and support for various database backends. However, a critical vulnerability has been identified in versions 0.9.9 to 0.22.0, which allows for SQL injection through the min() and max() aggregate functions, potentially exposing sensitive data.
Vulnerability Detail
The vulnerability arises from the way Ormar handles user-supplied input in aggregate queries. Specifically, the min() and max() methods accept arbitrary string input as column parameters without proper validation or sanitization. This allows an attacker to inject malicious SQL code, leading to unauthorized access to the database. The affected code constructs SQL expressions using sqlalchemy.text() directly with user input, making it susceptible to SQL injection attacks. As a result, attackers can execute arbitrary SQL queries, read sensitive data, and compromise the integrity of the database.
How To Fix
Latest published version: 0.26.0 as of 23 Oct 2026
pip install --upgrade "ormar==0.26.0"
Upgrading to it may include breaking changes; the version below is the minimum fixed release for this vulnerability.
If you need the minimum change
0.23.0
This is the first release that contains the fix.
pip install --upgrade "ormar==0.23.0"
Tip — Not sure which version your app runs? Vulert can match this fix to it. Scan free →
Workaround
As a temporary workaround, avoid using the min() and max() methods with user-controlled input. Instead, implement server-side validation to ensure that only valid column names are accepted. For example, you can create a whitelist of acceptable column names and check user input against this list before executing any aggregate queries.
Conclusion
The SQL injection vulnerability in Ormar ORM through the min() and max() aggregate functions poses a significant risk to applications using affected versions. It is crucial to update to the patched version 0.23.0 or later to safeguard against potential data breaches. Implementing input validation can serve as a temporary measure to mitigate risks until the update is applied.
See every vulnerability recorded for ormar →
FAQ
The CVSS score of this vulnerability is 9.8, indicating a critical level of severity.
Versions 0.9.9 to 0.22.0 of Ormar are affected by this SQL injection vulnerability.
You can use the Vulert playground at Vulert Scanner to check if your application is affected by this vulnerability without requiring any signup.
Exploitation of this vulnerability can lead to unauthorized access to sensitive data, including user credentials and other confidential information stored in the database.
Yes, you can implement server-side validation to restrict user input to known safe column names, effectively mitigating the risk of SQL injection.
References
Related vulnerabilities
Recent vulnerabilities recorded for ormar.