Summary
MikroORM's identifier-quoting and JSON-path helper APIs did not correctly escape special characters within SQL identifiers and JSON property keys, causing user-supplied values to be emitted into SQL in an unsafe way.
When application code forwards attacker-controlled strings into these ORM APIs as identifiers or JSON filters, an attacker can break out of the quoted context and inject arbitrary SQL, leading to data compromise or modification.
Affected context
This vulnerability affects Node.js applications using MikroORM's SQL-based drivers where:
- User-controlled or partially trusted values are passed into ORM methods that accept identifiers (e.g., table, column, or JSON-path segments).
- The application relies on MikroORM's Platform.quoteIdentifier and JSON-path helpers (such as getSearchJsonPropertyKey, quoteJsonKey) to safely construct SQL fragments.
- The database backend is a SQL engine (e.g., PostgreSQL, MSSQL) where identifiers and JSON keys are quoted using engine-specific delimiters.
In such contexts, incorrect escaping means crafted input can prematurely terminate the quoted identifier or string and inject additional SQL.
Exploit preconditions
- Attack surface: Application endpoints or interfaces that let users influence:
- Column or field names used in dynamic queries.
- JSON property names or JSON-path filters passed to MikroORM.
- Required access: Ability to send crafted requests or payloads to application code that directly or indirectly calls:
Platform.quoteIdentifieror its Postgres/MSSQL overrides.- JSON-path related helpers like
getSearchJsonPropertyKeyorquoteJsonKey. - Trigger point: Execution of a query where:
- A user-influenced identifier or JSON key is interpolated into SQL using the flawed quoting logic.
- Why exploitation is possible:
- The quoting helpers fail to escape characters that terminate SQL identifier or string contexts.
- As a result, attacker-controlled content can "break out" of the quoted segment, append additional SQL tokens, and influence the final query structure despite the apparent use of ORM-level escaping.
Why this happens
The underlying bug is an output-encoding failure in MikroORM's SQL generation layer, mapping to CWE-89 (Improper Neutralization of Special Elements used in an SQL Command).
Instead of treating identifiers and JSON keys as pure data and ensuring that all delimiter characters (such as double quotes, brackets, or JSON-path operators) are correctly escaped, the helper methods allowed special characters to appear unmodified inside quoted identifiers or string literals.
This broke the invariant that any value passed through these helpers would remain confined to a single identifier or literal, enabling crafted input to alter the surrounding SQL syntax.
Conceptually, this is the same pattern seen in many SQL injection issues: untrusted data is incorporated into a command without robust context-aware encoding or parameterization, allowing the data to be interpreted as part of the query's structure.
Potential impact
- An attacker could manipulate WHERE clauses to bypass authorization or data visibility checks.
- An attacker could modify, insert, or delete data within the database using the application's own privileges.
- An attacker could exfiltrate sensitive information by injecting additional SELECT statements or expanding result sets.
- In environments with powerful database privileges, an attacker could potentially alter schema objects (e.g., tables, indexes) or abuse database features to escalate their foothold.
- Log integrity and audit trails could be compromised if injected SQL affects logging tables or telemetry pipelines.
General mitigation guidance
Effective mitigation focuses on strict separation between untrusted input and SQL syntax, and on reducing the need to dynamically construct identifiers:
- Prefer parameterized queries or ORM-level parameter binding for all user-supplied values that belong in predicates, filters, or JSON content, keeping them out of SQL identifiers wherever possible.
- Avoid exposing arbitrary identifier selection to end users; instead, map user-facing options to a fixed, whitelisted set of column names, JSON properties, or query shapes.
- Where dynamic identifiers are unavoidable, treat them as configuration rather than request-level data, sourced from trusted or validated lists rather than raw user input.
- Apply context-aware escaping routines that:
- Properly escape delimiter characters for identifiers (such as
",], or backticks) before inserting them into SQL. - Correctly encode JSON-path segments so they cannot terminate the path context or introduce additional operators.
- Reduce the privileges of the database account used by the application so that, even if SQL injection occurs, the potential damage is limited to the minimum necessary operations.
These patterns help ensure that even flawed quoting logic is not directly exposed to untrusted data, substantially lowering the attack surface.
How teams detect issues like this
Detection typically combines code-centric analysis with runtime monitoring:
- Static analysis and code review:
- Search for call sites where user-derived values are passed into methods intended for identifiers or JSON-path construction (e.g., dynamic column names, dynamic property keys).
- Flag any instances where request parameters, query strings, or headers are used to form SQL fragments, even indirectly through ORM helpers.
- Enforce internal guidelines that forbid user input from influencing identifiers without passing through a strict whitelist and validation layer.
- Automated tooling:
- Configure static analysis tools or linters to detect:
- String concatenation or interpolation around ORM SQL helpers.
- Direct use of untrusted input in any API that influences SQL syntax (not just value placeholders).
- Integrate these checks into CI pipelines so that new unsafe patterns are blocked at review time.
- Runtime observability:
- Monitor query logs for unusual patterns such as:
- Identifiers containing user-supplied values or unexpected characters.
- Queries with duplicated or malformed quote characters around identifiers.
- Use anomaly detection to spot sudden increases in failed queries or syntax errors that may indicate probing for injection.
Combining these approaches helps catch both existing vulnerabilities and future regressions.

