ORMAR · CVE-2026-26198 · Package
FIX → 0.23.0
The ormar Python ORM passes the column name given to its min() and max() aggregate methods straight into raw SQL without validation. An attacker who can control that column name can run arbitrary subqueries and read any table in the database, including tables the API never exposes.
first public Feb 22, 2026 · 2 sources
Check it with your coding agent
It reads this page and tells you if your code or app is affected.
Applications that use ormar's min() or max() queries with a column name taken from user input, such as a query-string parameter. Applications that only pass fixed column names in code, or that do not use these aggregate methods, are not exposed through this path. unknown whether other ormar query paths are affected.
Not affected if fixed-column-names, no-min-max-calls, pre-0.9.9
Who cares fastapi, ormar, postgresql, python, sqlite
pip show ormar or pip freeze | grep -i ormar; versions from 0.9.9 up to but not including 0.23.0 are affected..min( or .max( on an ormar QuerySet where the column argument comes from a request parameter.When performing aggregate queries, Ormar ORM constructs SQL expressions by passing user-supplied column names directly into sqlalchemy.text() without any validation or sanitization. The min() and max() methods in the QuerySet class accept arbitrary string input as the column parameter. While sum() and avg() are partially protected by an is_numeric type check that rejects non-existent fields, min() and max() skip this validation entirely. As a result, an attacker-controlled string is embedded as raw SQL inside the aggregate function call. Any unauthorized user can exploit this vulnerability to read the entire database contents, including tables unrelated to the queried model, by injecting a subquery as the column parameter.
Are you affected?
Ask from here. InfraStack checks the affected versions against your stack and answers in your inbox.
InfraStack checks the affected versions against your stack and answers in Slack, with the evidence and the fix.
InfraStack checks it against your stack and answers on your report, with the evidence and the fix.
Upgrade to 0.23.0
ormar 0.23.0 (fixed version per the product data)0.9.9 - 0.12.2
0.20.0b1 - 0.22.0 (latest)
The vulnerable SelectAction.get_text_clause() method and the min()/max() aggregate functions were introduced together in commit ff9d412 (March 12, 2021) and first released in version 0.9.9. The vulnerable code has never been modified since — get_text_clause() is identical in every subsequent version through the latest 0.21.0.
Versions prior to 0.9.9 do not contain the min()/max() aggregate feature and are not affected.
The following uses the latest ormar 0.21.0 as an example to illustrate the attack.
When performing an aggregate query, the QuerySet.max() method (line 721, queryset.py) passes user input to _query_aggr_function(). This method creates a SelectAction object for each column name. The column string is split by __ and the last part becomes self.field_name — with no validation against the model's actual fields.
The critical vulnerability is in SelectAction.get_text_clause() (line 41-43, select_action.py), which directly passes self.field_name into sqlalchemy.text():
#select_action.py line 41-43
def get_text_clause(self) -> sqlalchemy.sql.expression.TextClause:
alias = f"{self.table_prefix}_" if self.table_prefix else ""
return sqlalchemy.text(f"{alias}{self.field_name}") # unsanitised user input!
The apply_func() method then wraps this raw text clause inside func.max(), producing SQL like max(<attacker_input>). Since sqlalchemy.text() treats its argument as literal SQL, any subquery or SQL expression injected through the column name will be executed by the database engine.
The _query_aggr_function() method (line 704-719, queryset.py) only validates field types for sum and avg, leaving min and max completely unprotected:
#queryset.py line 704-719
async def _query_aggr_function(self, func_name: str, columns: List) -> Any:
func = getattr(sqlalchemy.func, func_name)
select_actions = [
SelectAction(select_str=column, model_cls=self.model) for column in columns
]
if func_name in ["sum", "avg"]: # <-- only sum/avg are checked!
if any(not x.is_numeric for x in select_actions):
raise QueryDefinitionError(...)
select_columns = [x.apply_func(func, use_label=True) for x in select_actions]
expr = self.build_select_expression().alias(f"subquery_for_{func_name}")
expr = sqlalchemy.select(*select_columns).select_from(expr)
result = await self.database.fetch_one(expr)
return dict(result) if len(result) > 1 else result[0]
To reproduce the attack, you can follow the steps below, using a FastAPI application with SQLite as an example.
Note: The PoC consists of two files provided in the attachments — poc_server.py (the vulnerable server) and poc_attacker.py (the HTTP-based attacker script).
@app.get("/items/stats") async def item_stats( metric: str = Query("max", description="max or min"), column: str = Query("price", description="Column to aggregate"), ): """Return aggregate statistics for items.""" if metric == "max": result = await Item.objects.max(column) elif metric == "min": result = await Item.objects.min(column) else: return {"error": "Unsupported metric"} return {"metric": metric, "column": column, "result": result} </code></pre>
| Table | Data |
|---|---|
| categories | Electronics |
| items | Laptop ($999.99), Phone ($699.99), Tablet ($449.99), Monitor ($329.99) |
| admin_users | root / Sup3r$ecretP@ss! / ak-9f8e7d6c5b4a3210-prod |
| deploy-bot / ghp_Tx7KmR29vLp4QzN1bWcA3sYjDf80Ue5Xoi / ak-1a2b3c4d5e6f7890-ci |
This page as .md · .json · CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H
GitHub Advisory Database, CC-BY 4.0 · NVD data is provided by NIST and is public domain. Posts quoted belong to their authors.