
Cloud Vulnerability DB
A community-led vulnerabilities database
MikroORM builds SQL from templates that use ? and ?? as placeholders, and inlines the parameters on the client before the query is sent to the database. A ? that was already part of the template for another reason was read as one more placeholder, so the next parameter of the query was written into the wrong position, outside of the quoting it was meant for. A string value could end up being executed as SQL.
This happened in three places:
? was left as is,raw(), the sql tagged template, sub-queries) used inside a QueryBuilder, which were formatted with their own parameters and then scanned again as part of the outer query.QueryBuilder (v7 only), e.g. qb.where(sql`lower(name) = ${term}`). The application binds the value correctly. If the value contains ? and a later parameter of the same query is also request-derived, the later value is placed outside of its string literal. This applies to fragments passed to where / andWhere / orWhere, select / addSelect, orderBy and groupBy, to sub-queries used in joins or withSubQuery, and to update, delete and count queries built this way. No control over object keys is needed. With a single request-derived value the query only fails or returns wrong rows.em.find(Entity, { jsonCol: { [userKey]: value } }). JSON sub-keys cannot be validated against metadata.schema option (v7 only), em.fork({ schema }), qb.withSchema(name) and similar, when the schema name is request-derived.em.find / em.nativeUpdate / em.nativeDelete / qb.where / qb.update / qb.insert (v6 and v7). Where keys containing . or :: skip the metadata validation and reach the identifier quoting, and data keys of native updates and inserts are not validated. An application that forwards request-derived keys to these APIs already lets the caller filter on or write to any column of the entity, and this adds SQL injection on top of that. It is the same entry point as in GHSA-cfw5-68c4-ffqp, where the fix escaped the quote character but not ?.
Not affected: qb.where('lower(name) = ?', [term]) (a string with a params array), raw fragments used as keys or values of an em.find filter, and entity changes persisted through em.flush().where clause of an update or delete can be dropped, so it applies to every row.multipleStatements enabled, SQLite does not allow it.The code lives in the shared SQL layer, so all SQL drivers are affected. MongoDB is not affected.
| Line | Package | Affected versions |
|---|---|---|
| v7 | @mikro-orm/sql | >= 7.0.0, <= 7.2.10 |
| v6 | @mikro-orm/knex | <= 6.6.18 |
| The SQL layer is delivered transitively via the driver packages, which all depend on it. | ||
On v6 only the object key variant is affected. The JSON sub-key, schema and raw fragment variants fail with a query error there. |
Fixed in 7.2.11 (#8769) and 6.6.19 (#8774). In v7, question marks in identifiers, JSON path literals and embedded raw fragments are now escaped, so they are no longer read as placeholders. In v6, a query with more placeholders than parameters is rejected before it is executed.
QueryBuilder, pass request-derived values as qb.where('... ?', [value]) instead of through a raw fragment, or reject values containing ?.?.?, or check them against an allow-list.Source: NVD
Free Vulnerability Assessment
Evaluate your cloud security practices across 9 security domains to benchmark your risk level and identify gaps in your defenses.
Get a personalized demo
"Best User Experience I have ever seen, provides full visibility to cloud workloads."
"Wiz provides a single pane of glass to see what is going on in our cloud environments."
"We know that if Wiz identifies something as critical, it actually is."