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 (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 (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 (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 (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.

Sources