Summary
MikroORM versions prior to 6.6.10 and 7.0.6 contain a SQL injection vulnerability where specially crafted objects passed into query-building APIs can be misinterpreted as raw SQL fragments.
In applications that treat user-controlled data as part of these objects, an attacker may inject arbitrary SQL into database queries, potentially leading to full data compromise or modification.
Affected context
This vulnerability arises in Node.js applications using MikroORM's TypeScript API for building queries, where object parameters are accepted and internally transformed into SQL.
The issue is relevant when:
- Application code passes complex or loosely validated objects into MikroORM query methods, filters, or criteria builders, and
- Those objects can originate from, or be influenced by, user-controlled input, and
- The ORM logic interprets specific object shapes or markers as "raw SQL" fragments to be spliced into generated queries.
It does not inherently affect all MikroORM usage, but is most risky when developers rely on automatic query composition from objects without strict separation between data and SQL expressions.
Exploit preconditions
- Attack surface: Application endpoints or interfaces that accept external input (HTTP APIs, GraphQL resolvers, CLI flags, background jobs fed by messages) and pass it into MikroORM query-building logic.
- Required access: Ability to control request parameters or payloads that are mapped into query criteria, filter objects, or other MikroORM options.
- Trigger point: Invocation of a MikroORM query (e.g.,
find,findOne, custom repository methods, or query builders) where the crafted object is interpreted as part of the SQL statement. - Why exploitation is possible: The ORM logic treats certain object forms as raw SQL, effectively bypassing parameterization and escaping, so user-supplied values can be injected directly into the query string.
Why this happens
The core issue is an improper separation between data and SQL code within MikroORM's query construction layer.
Certain object structures are designed to signal that a value should be treated as a raw SQL snippet rather than as a bound parameter.
When these same patterns can be reached using untrusted input, the ORM no longer enforces parameterization and escapes, leading to CWE-89: SQL Injection.
Abstractly, the bug class is:
- A query-building API that overloads data containers (objects) with "SQL expression" semantics, and
- Logic that trusts these semantics without verifying that the source is trusted or restricted to static code, allowing attacker-controlled objects to be interpreted as SQL.
Potential impact
- Read access to sensitive or confidential data stored in the database (user records, credentials, tokens, business data).
- Modification or deletion of database records, including tampering with application state or audit logs.
- Creation of new accounts or privilege escalation within application data models.
- Disruption of service via destructive operations (e.g., mass updates or deletes) that degrade integrity or availability.
- In some environments, execution of database-specific functions that may assist in further compromise or lateral movement.
General mitigation guidance
Effective mitigation centers on ensuring that SQL and data are never conflated and that only trusted code can introduce raw SQL constructs.
Pattern-based mitigations include:
- Prefer high-level MikroORM APIs that use parameterized queries and avoid raw SQL or expression "escape hatches" when possible.
- Treat any mechanism that accepts "raw SQL fragments" as privileged: keep these constructs confined to static, code-defined locations rather than user-derived input.
- Introduce strict typing and validation around query object parameters so that user-facing types cannot express raw SQL or special markers.
- Apply input validation and normalization at the boundary of the application to constrain values that feed into query objects, focusing on structure and type rather than just content.
- Enforce least-privilege database accounts so that even if a query is abused, the scope of permitted operations is limited.
- Use centralized helper functions or repositories for constructing queries, instead of letting arbitrary parts of the codebase assemble MikroORM criteria from raw request data.
How teams detect issues like this
Detection typically combines code-level inspection with automated checks:
- Static analysis: Search for MikroORM calls that accept dynamic objects originating from request bodies, query parameters, or other untrusted sources, especially where those objects can be interpreted as raw SQL.
- Code review signals:
- Places where developers bypass standard MikroORM parameterization in favor of raw expressions.
- Generic "pass-through" query utilities that accept arbitrary objects from callers and forward them directly to MikroORM.
- Repositories or services that map user input directly into complex criteria objects without structural validation.
- Policy enforcement: Establish internal guidelines or linters that flag the use of raw SQL constructs or special markers within user-influenced query parameters.
- Runtime monitoring: Enable database query logging and review for unexpected patterns, such as unbounded predicates, concatenated literals, or anomalies in SQL structure that correlate with attacker-controlled inputs.

