---
title: "CAPEC-109: Object Relational Mapping Injection"
url: https://radicalnotion.ai/capec/capec-109
type: capec
description: "An attacker leverages a weakness present in the database access layer code generated with an Object Relational Mapping (ORM) tool or a weakness in the way that a developer used a persistence framework to inject their own SQL commands to be executed against the underlying database. The attack here is similar to plain SQL injection, except that the application does not use JDBC to directly talk to the database, but instead it uses a data access layer generated by an ORM tool or framework (e.g. Hibernate). While most of the time code generated by an ORM tool contains safe access methods that are immune to SQL injection, sometimes either due to some weakness in the generated code or due to the fact that the developer failed to use the generated access methods properly, SQL injection is still possible."
updated: 2026-06-01
source: RadicalNotion.AI
license: CC BY-NC 4.0 (https://creativecommons.org/licenses/by-nc/4.0/)
---

# CAPEC-109: Object Relational Mapping Injection

- **Abstraction:** Detailed
- **Status:** Draft
- **Typical severity:** High
- **Likelihood of attack:** Low
- **CAPEC catalog version:** 3.9

## Description

An attacker leverages a weakness present in the database access layer code generated with an Object Relational Mapping (ORM) tool or a weakness in the way that a developer used a persistence framework to inject their own SQL commands to be executed against the underlying database. The attack here is similar to plain SQL injection, except that the application does not use JDBC to directly talk to the database, but instead it uses a data access layer generated by an ORM tool or framework (e.g. Hibernate). While most of the time code generated by an ORM tool contains safe access methods that are immune to SQL injection, sometimes either due to some weakness in the generated code or due to the fact that the developer failed to use the generated access methods properly, SQL injection is still possible.

## Execution flow

### Step 1: Explore

\[Determine Persistence Framework Used\] An attacker tries to determine what persistence framework is used by the application in order to leverage a weakness in the generated data access layer code or a weakness in a way that the data access layer may have been used by the developer.

- An attacker provides input to the application in an attempt to induce an error screen that reveals a stack trace that gives an indication of the automated data access layer used. Or an attacker may simply make some educated guesses and assume, for instance, that Hibernate is used and try to craft an attack from there.

### Step 2: Explore

\[Probe for ORM Injection vulnerabilities\] The attacker injects ORM syntax into user-controllable data inputs of the application to determine if it is possible modify data query structure and content.

### Step 3: Exploit

\[Perform SQL Injection through the generated data access layer\] An attacker proceeds to exploit a weakness in the generated data access methods that does not properly separate control plane from the data plan, or potentially a particular way in which developer might have misused the generated code, to modify the structure of the executed SQL queries and/or inject entirely new SQL queries.

- An attacker uses normal SQL injection techniques and adjusts them to reflect the type of data access layer generation framework used by the application.

## Prerequisites

- An application uses data access layer generated by an ORM tool or framework
- An application uses user supplied data in queries executed against the database
- The separation between data plane and control plane is not ensured, through either developer error or an underlying weakness in the data access layer code generation framework

## Skills required

- **Medium:** Knowledge of general SQL injection techniques and subtleties of the ORM framework is needed

## Resources required

- None: No specialized resources are required to execute this type of attack.

## Consequences

| Scope | Impact | Note |
| --- | --- | --- |
| Integrity | Modify Data | - |
| Availability | Unreliable Execution | - |
| Confidentiality | Read Data | - |
| Confidentiality, Access Control, Authorization | Gain Privileges | - |
| Confidentiality, Integrity, Availability | Execute Unauthorized Commands | Run Arbitrary Code |

## Mitigations

- Remember to understand how to use the data access methods generated by the ORM tool / framework properly in a way that would leverage the built-in security mechanisms of the framework
- Ensure to keep up to date with security relevant updates to the persistence framework used within your application.

## Example instances

When using Hibernate, it is possible to use the session.find() method to run queries against the database. This is an overloaded method that provides facilities to perform binding between the supplied user data and place holders in the statically defined query. However, it is also possible to use the session.find() method without using any of these query binding overloads, hence effectively concatenating the user supplied data with rest of the SQL query, resulting in a possibility for SQL injection. While the framework may provide mechanisms to use methods immune to SQL injections, it may also contain ways that are not immune that may be chosen by the developer.

## Related weaknesses (CWE)

- [CWE-20](https://radicalnotion.ai/cwe/cwe-20): Improper Input Validation
- [CWE-89](https://radicalnotion.ai/cwe/cwe-89): Improper Neutralization of Special Elements used in an SQL Command
- [CWE-564](https://radicalnotion.ai/cwe/cwe-564): Use of Hibernate with HQL/SQL Query String Containing External Input

## Related attack patterns

| Relationship | CAPEC | Name |
| --- | --- | --- |
| Parent | [CAPEC-66](https://radicalnotion.ai/capec/capec-66) | SQL Injection |

## Frequently asked questions

### What is CAPEC-109?

An attacker leverages a weakness present in the database access layer code generated with an Object Relational Mapping (ORM) tool or a weakness in the way that a developer used a persistence framework to inject their own SQL commands to be executed against the underlying database. The attack here is similar to plain SQL injection, except that the application does not use JDBC to directly talk to the database, but instead it uses a data access layer generated by an ORM tool or framework (e.g. Hibernate). While most of the time code generated by an ORM tool contains safe access methods that are immune to SQL injection, sometimes either due to some weakness in the generated code or due to the fact that the developer failed to use the generated access methods properly, SQL injection is still possible.

### How does a Object Relational Mapping Injection attack work?

It typically unfolds over 3 phases. It begins with: \[Determine Persistence Framework Used\] An attacker tries to determine what persistence framework is used by the application in order to leverage a weakness in the generated data access layer code or a weakness in a way that the data access layer may have been used by the developer.

### How do you prevent CAPEC-109?

Remember to understand how to use the data access methods generated by the ORM tool / framework properly in a way that would leverage the built-in security mechanisms of the framework

### What weaknesses does CAPEC-109 target?

CAPEC-109 exploits 3 CWE weaknesses: CWE-20 (Improper Input Validation), CWE-89 (Improper Neutralization of Special Elements used in an SQL Command) and CWE-564 (Use of Hibernate with HQL/SQL Query String Containing External Input).

### How severe is CAPEC-109?

MITRE rates CAPEC-109 as High severity with low likelihood of attack.

Primary source: [MITRE CAPEC](https://capec.mitre.org/data/definitions/109.html)

---

Source: [RadicalNotion.AI](https://radicalnotion.ai/capec/capec-109). Licensed CC BY-NC 4.0; attribute RadicalNotion.AI and link the source page when you reuse this data.
