ORM Injection
SQL injection that survives an ORM or query builder — because identifiers aren’t parameterizable, a builder feature re-opens raw SQL, or an escaping routine is subtly wrong.
How it works
ORMs are widely assumed to prevent SQLi, and for values bound through placeholders they do. The 2026 CVE record shows three recurring ways the guarantee leaks:
- Identifiers can’t be bound. Prepared statements parameterize values, not column/table/schema names or
ORDER BYdirections. Any feature that lets the client pick a sort key, column, schema or format string concatenates that identifier into SQL. This is the single most common source today. - Query-builder “raw” escape hatches. Criteria arrays, formula trees,
:rawkeywords andFromSqlRawtake literal SQL by design; untrusted data reaching them is injected, not bound. - Buggy escaping / encoding. Byte-wise escapers that mis-handle multibyte charsets, or
-func/arrayref features that treat input as SQL text.
Techniques / payloads (by failure mode)
Identifier / clause injection:
ORDER BY/sortconcatenation — Daptin (sort), free-fs (orderByvia MyBatis-Flex, boolean exfil withCASE WHENsubqueries), Omnispace Agora (personsSort→ error-basedextractvalue), Worklenz (projects/status).- Pagination identifiers — Kubeflow Pipelines
page_tokenSQL identifier fields (cross-namespace reads). - Schema names — django-tenants: unescaped tenant schema name injected into
SET search_pathand schema DDL. GROUP BY— pREST_groupby:isSafeSQLExpressiongate fails to block nested subqueries/UNION SELECT; an incomplete fix vs. the strongersanitizeSelectFieldused for_select.
Builder raw-SQL features:
- Yii criteria arrays — Craft
Element::findOne(): a criteria value shaped like a raw condition is treated as literal SQL by Yii’s builder; the September fix (GHSA-mjj9-pjh4-r48g) patched one call site, GHSA-cphx-cx67-jcqj found a second path into the same sink — fix the sink, not the call site (Craft second path). - Formula parse trees — NocoDB reuses a client-influenced parsed formula tree without revalidation → arbitrary SQL / RCE on external Postgres;
DATETIME_FORMATformat arg unescaped on MySQL. - Perl
SQL::Abstract< 2.000003 (CVE-2026-121265) — witharray_datatypesoff (default), an arrayref column value’s first element goes into SQL text unescaped; a JSON array or repeated form field decodes to such a value. Related CVE-2026-121007/8/9 cover nestedwherevalues and-funcguard bypass (oss-security).
Escaping/encoding bugs:
- Trilogy MySQL adapter (GHSA-744p-w4gc-m3gh, CVSS 9.3) —
escapeworks byte-by-byte and tags output with the input’s encoding, not the connection’s; in multibyte charsets (GBK, Shift_JIS, Big5) a trailing lead byte absorbs the backslash so the following quote breaks out, defeating Rails parameter validation. Fix re-encodes to the connection charset and rejects dangerous charsets (Trilogy). - WordPress plugin binders — Amelia Pro defeats
wp_magic_quotesand theStatement::executeplaceholder binder via overlappingstrtr()substitution keys ontag[]array keys (Amelia Pro).
Operator injection on ORMs (Prisma/Sequelize/TypeORM) is covered in NoSQL Injection.
Notable cases
LimeSurvey CE (Yii select builder mishandles persisted attribute names with parentheses), ILIAS ilPRGAssignmentFilter::toConditions() (stacked statements, overwrite root hash), AppFlowy self-hosted (search_term into JSON path query — patched in cloud, left vulnerable in OSS — SaaS patched, OSS not).
Defenses
Allow-list every identifier (sort/column/table/schema/format) against a fixed set — never interpolate. Avoid raw/criteria/formula escape hatches on untrusted input; prefer typed query APIs and FromSqlInterpolated/explicit parameters (EF Core safe patterns). Keep ORM and DB driver patched (escaping-bug CVEs). Fix the shared sink, not individual call sites.
Related
Sources
- A September SQL-injection fix in Craft missed a second path · original
- SQL injection in the Trilogy MySQL adapter · original
- SQL-Abstract Perl SQL injection CVEs · original
- SQL::Abstract arrayref column SQL injection · original
- Amelia Pro booking plugin SQL injection · original
- django-tenants SQL injection in PostgreSQL backend · original
- pREST _groupby SQL injection (incomplete fix) · original
- NocoDB RCE via formula parsed-tree SQL injection · original
- They patched their SaaS and left the self-hosted OSS version vulnerable (AppFlowy) · original