Kysely: JSON-path traversal injection via unsanitized path-leg metacharacters in `JSONPathBuilder.key()` / `.at()`
Kysely is a type-safe TypeScript SQL query builder. From 0.26.0 to 0.28.16, DefaultQueryCompiler.visitJSONPathLeg does not escape JSON-path metacharacters (., [, ], *, **, ?). When attacker-controlled input flows into eb.ref(col, '->$').key(input) or .at(input) — including type-safe code where the JSON column is shaped like Record<string, T> so K extends string is the inferred type — every dot becomes a path-leg separator, letting an attacker traverse from the intended key into sibling and child fields the developer never meant to expose. The result is read access (and, in update statements, write access) to JSON sub-fields outside the intended scope across MySQL, PostgreSQL ->$/->>$, and SQLite. This vulnerability is fixed in 0.28.17.
Problem Types
| Type | CWE ID | Description |
|---|
| CWE | CWE-22 | CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal') |
| CWE | CWE-89 | CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') |
| CWE | CWE-915 | CWE-915: Improperly Controlled Modification of Dynamically-Determined Object Attributes |
| CWE | CWE-1284 | CWE-1284: Improper Validation of Specified Quantity in Input |
Type: CWE
Description: CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')
Type: CWE
Description: CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
Type: CWE
Description: CWE-915: Improperly Controlled Modification of Dynamically-Determined Object Attributes
Type: CWE
Description: CWE-1284: Improper Validation of Specified Quantity in Input
Metrics
| Version | Base score | Base severity | Vector |
|---|
| 3.1 | 7.5 | HIGH | CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N |
Version: 3.1
Base score: 7.5
Base severity: HIGH
Vector: CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N