Skip to content
Vol. 1 · Ed. 2026
CyberGlossary
Entry № 863

ORM Injection

Reviewed byCybersecurity entrepreneur & security researcher

What is ORM Injection?

ORM InjectionAn injection attack against applications using an Object-Relational Mapper that abuses dynamic queries, mass-assignment, or raw query escape hatches to manipulate data access.


ORM injection occurs when attacker-influenced input reaches an Object-Relational Mapper (Hibernate, Entity Framework, SQLAlchemy, ActiveRecord, Sequelize, Prisma, Django ORM) through APIs that build queries dynamically. Developers often assume the ORM parameterizes everything, but escape hatches re-introduce classic injection: HQL/JPQL string concatenation, ActiveRecord's where("... #{params} ..."), Sequelize Op.literal, SQLAlchemy text() with formatted strings, and unsafe ORDER BY/filter parameters taken straight from JSON APIs.

HQL injection (CWE-564, "SQL Injection: Hibernate") is a notable variant. HQL's restricted syntax is sometimes argued to be inherently safer, but SonarSource research demonstrated that attackers can break out of HQL into the underlying SQL by abusing DBMS functions and the HQL-to-SQL translation — including a pre-authentication HQL injection in LogicalDoc 8.3.2. Beyond data theft, injecting into an ORM can bypass authorization and escalate privileges when access controls are expressed as ORM query predicates. Mass-assignment is a related ORM flaw where unpermitted attributes are bound from a request body.

flowchart LR
  A["Untrusted input<br/>sort / filter / where"] --> B{"Query via<br/>escape hatch?"}
  B -->|"Raw HQL/SQL<br/>string concat"| C["ORM emits<br/>injected SQL"]
  C --> D["Data theft, auth bypass,<br/>privilege escalation"]
  B -->|"Parameterized builder<br/>+ field allow-list"| E["Input bound as a<br/>parameter: safe"]

Defences: prefer parameterized query builders and bound parameters; never concatenate input into HQL/JPQL/SQL; allow-list orderable and filterable field names; use explicit attribute permitting (strong parameters); and avoid raw-query escape hatches for untrusted input.

● Examples

  1. 01

    A Rails app calling User.where("name = '#{params[:q]}'") allowing SQL injection through the ORM.

  2. 02

    A Sequelize endpoint accepting attacker-controlled order parameters that pass through Op.literal.

● Frequently asked questions

What is ORM Injection?

An injection attack against applications using an Object-Relational Mapper that abuses dynamic queries, mass-assignment, or raw query escape hatches to manipulate data access. It belongs to the Attacks & Threats category of cybersecurity.

What does ORM Injection mean?

An injection attack against applications using an Object-Relational Mapper that abuses dynamic queries, mass-assignment, or raw query escape hatches to manipulate data access.

How do you defend against ORM Injection?

Defences for ORM Injection typically combine technical controls and operational practices, as detailed in the full definition above.

What are other names for ORM Injection?

Common alternative names include: HQL injection, JPQL injection.

● Related terms