# 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: 1. **Identifiers can't be bound.** Prepared statements parameterize values, not column/table/schema names or `ORDER BY` directions. 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. 2. **Query-builder "raw" escape hatches.** Criteria arrays, formula trees, `:raw` keywords and `FromSqlRaw` take literal SQL by design; untrusted data reaching them is injected, not bound. 3. **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` / `sort` concatenation — Daptin (`sort`), free-fs (`orderBy` via MyBatis-Flex, boolean exfil with `CASE WHEN` subqueries), Omnispace Agora (`personsSort` → error-based `extractvalue`), Worklenz (`projects`/`status`). - Pagination identifiers — Kubeflow Pipelines `page_token` SQL identifier fields (cross-namespace reads). - Schema names — django-tenants: unescaped tenant schema name injected into `SET search_path` and schema DDL. - `GROUP BY` — pREST `_groupby`: `isSafeSQLExpression` gate fails to block nested subqueries/`UNION SELECT`; an *incomplete fix* vs. the stronger `sanitizeSelectField` used 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 ([[raw/blog.bms.ovh/a-september-sql-injection-fix-in-craft-missed-a-second-path-13566|Craft second path]]). - **Formula parse trees** — NocoDB reuses a client-influenced parsed formula tree without revalidation → arbitrary SQL / RCE on external Postgres; `DATETIME_FORMAT` format arg unescaped on MySQL. - **Perl `SQL::Abstract` < 2.000003 (CVE-2026-121265)** — with `array_datatypes` off (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 nested `where` values and `-func` guard bypass ([[raw/openwall.com/sql-abstract-perl-sql-injection-cves-oss-security-13215|oss-security]]). **Escaping/encoding bugs:** - **Trilogy MySQL adapter (GHSA-744p-w4gc-m3gh, CVSS 9.3)** — `escape` works 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 ([[raw/daily.dev/sql-injection-in-the-trilogy-mysql-adapter-13216|Trilogy]]). - **WordPress plugin binders** — Amelia Pro defeats `wp_magic_quotes` and the `Statement::execute` placeholder binder via overlapping `strtr()` substitution keys on `tag[]` array *keys* ([[raw/github.com/amelia-pro-booking-plugin-sql-injection-13570|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 — [[raw/projectblack.io/they-patched-their-saas-and-left-the-self-hosted-oss-version-vulnerabl-11481|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 ([[raw/snyk.io/preventing-sql-injection-in-c-with-entity-framework-9458|EF Core safe patterns]]). Keep ORM and DB driver patched (escaping-bug CVEs). Fix the shared sink, not individual call sites. ## Related - [[SQL Injection]] - [[NoSQL Injection]] - [[Second-Order SQL Injection]] - [[SQL Injection to RCE]] ## Sources - [[raw/blog.bms.ovh/a-september-sql-injection-fix-in-craft-missed-a-second-path-13566|A September SQL-injection fix in Craft missed a second path]] - [[raw/daily.dev/sql-injection-in-the-trilogy-mysql-adapter-13216|SQL injection in the Trilogy MySQL adapter]] - [[raw/openwall.com/sql-abstract-perl-sql-injection-cves-oss-security-13215|SQL-Abstract Perl SQL injection CVEs]] - [[raw/github.com/sql-abstract-before-2-000003-arrayref-column-sql-injection-13567|SQL::Abstract arrayref column SQL injection]] - [[raw/github.com/amelia-pro-booking-plugin-sql-injection-13570|Amelia Pro booking plugin SQL injection]] - [[raw/github.com/django-tenants-sql-injection-in-postgresql-backend-14912|django-tenants SQL injection in PostgreSQL backend]] - [[raw/github.com/prest-groupby-sql-injection-incomplete-fix-15501|pREST _groupby SQL injection (incomplete fix)]] - [[raw/github.com/nocodb-rce-via-formula-parsed-tree-sql-injection-15647|NocoDB RCE via formula parsed-tree SQL injection]] - [[raw/projectblack.io/they-patched-their-saas-and-left-the-self-hosted-oss-version-vulnerabl-11481|They patched their SaaS and left the self-hosted OSS version vulnerable (AppFlowy)]]