The pre-patch visitJSONPathLeg was three lines.
The entire JSON-path-leg emission in src/query-compiler/default-query-compiler.ts at v0.28.11 was:
protected override visitJSONPathLeg(node: JSONPathLegNode): void {
const isArrayLocation = node.type === 'ArrayLocation'
this.append(isArrayLocation ? '[' : '.')
this.append(String(node.value))
if (isArrayLocation) {
this.append(']')
}
}
node.value is the string | number the caller passed to .key() or .at(). The leg sits inside a containing visitJSONPath that frames the whole expression in apostrophes:
protected override visitJSONPath(node: JSONPathNode): void {
if (node.inOperator) {
this.visitNode(node.inOperator)
}
this.append("'$")
for (const pathLeg of node.pathLegs) {
this.visitNode(pathLeg)
}
this.append("'")
}
For a normal call against a known-shape column:
db.selectFrom('person_metadata')
.select(eb => eb.ref('profile', '->$').key('city').as('city'))
The emitted SQL on MySQL is:
select `profile`->'$.city' as `city` from `person_metadata`
The dot before city is the JSON path's path-leg separator. The $ is the path root. The whole path lives inside the SQL string literal '...'. The compiler concatenates the caller's key directly into that literal.
A chained call writes the same way. eb.ref('profile', '->$').key('address').key('city') produces '$.address.city'. Two visitJSONPathLeg invocations, each writing . and then a member name. The output is one continuous JSON path.
.key('address.city') produces the same string. The compiler ran visitJSONPathLeg exactly once. It wrote . and then address.city. The downstream database parser reads two path legs because there are two dots, and there is no way for the parser to tell from the SQL it received which dots the compiler wrote and which dots the caller did. The compiler decided that question by writing String(node.value).
The first fix was titled "is injectable." It escaped the wrong layer.
On March 4, 2026, commit 0a602bff landed in the same file. Title: fix: eb.ref(col, '->$').key(key) is injectable. The fix:
- this.append(String(node.value))
+ this.append(
+ typeof node.value === 'string'
+ ? this.sanitizeStringLiteral(node.value)
+ : String(node.value),
+ )
sanitizeStringLiteral replaces each ' in the value with ''. That closes the SQL injection the same commit's test demonstrates:
const injection =
`first' as ${identifierWrapper}first${identifierWrapper} from ${identifierWrapper}people${identifierWrapper}; drop table ${identifierWrapper}person${identifierWrapper} -- ` as never
const query = ctx.db
.with('people', () =>
ctx.db
.selectFrom('person')
.select(
sql<{ first: string }>`json_object('first', first_name)`.as('data'),
),
)
.selectFrom('people')
.select((eb) => eb.ref('data', '->$').key(injection).as('first'))
Without the escape, the ' in first' closes the apostrophe-bounded JSON path early, the tail of the string runs as appended SQL, and the test asserts that the resulting query attempts to drop the person table. With the escape, each ' becomes '' and the entire payload survives as one very long quoted JSON-path member name.
What the fix does not touch is anything inside the path. The dot was already there because the compiler wrote it. The dot inside the caller's value is never quoted, escaped, or rejected. The 0.28.12 release on the same day shipped the patch as the only meaningful change. The release notes describe it as the closed bug.
Sixty days later, on May 3, 2026, commit dbb54058 landed with the title feat: further harden JSON path .key(...) and .at(...) against SQL injections and exfiltrations. The class names in the second title are not the class names in the first. The first patch closed SQL injection. The second patch closed exfiltrations, plural, by way of dots, brackets, wildcards, and quote escapes that the apostrophe escape never saw. CVE-2026-44635 names the gap.
K extends string is what gets typed when the column is what .key() is for.
.key() in src/query-builder/json-path-builder.ts is typed:
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>
The comment in the conditional acknowledges the case directly. When the column is Record<string, T>, keyof NonNullable<O> is string, the existing-key branch falls through, and the return type degrades to T | null. What the comment does not say is what happens to K itself in that branch. K extends keyof NonNullable<O> & string is K extends string & string, which is K extends string. The TypeScript checker has nothing to refuse. Any string compiles.
The column shapes where this applies are not a corner. A preferences column whose contents are arbitrary user settings. A profile column the application accumulates field by field over years. A metadata column described in the schema as "string-keyed scalar values." A feature-flag column with no enumerated flag set. A settings column whose schema is "whatever the admin UI saves." The library's documentation tells the caller that K is bound to the column's key set. For columns whose key set is not knowable at compile time, and that is most JSON columns in any application that uses JSON columns for any practical reason, the bound is string.
The four exfiltration tests that landed with the May patch read off the bound:
const exfiltration = 'auth.login_count'
// emits: 'profile'->'$.auth.login_count'
// parses as: navigate $.auth, then $.auth.login_count
const exfiltration = 'auth"."login_count'
// emits: 'profile'->'$.auth"."login_count'
// breaks out of any per-leg quote wrap to reconstruct the dot path
const exfiltration = 'tags[0]'
// emits: 'profile'->'$.tags[0]'
// array-index access into a sibling key
const exfiltration = '*'
// emits: 'profile'->'$.*'
// every key at the current level
Each of those is a string. Each of those is the shape req.query.field takes in the route handlers that motivate .key() existing in the first place. Each of those, against a Record<string, T> column, the TypeScript checker accepts without as never. The tests had to write as never because the test's column was typed as { first: string } for SQL-injection demonstration purposes. The production code where the bug lives does not have that constraint.
The CVE description is explicit about the case: "including type-safe code where the JSON column is shaped like Record<string, T> so K extends string is the inferred type." The advisory writer named the gap. The type signature still says keyof NonNullable<O> & string after the patch. The patch did not touch the type.
The second patch wraps the key in quotes. .at() got an allowlist. .key() did not.
The 0.28.17 emission for member legs is:
if (isArrayLocation) {
this.append('[')
this.append(this.sanitizeStringLiteral(value))
this.append(']')
} else {
this.append('."')
this.append(this.sanitizeJSONPathMemberValue(value))
this.append('"')
}
.key('auth.login_count') now compiles to 'profile'->'$."auth.login_count"'. The dot lives inside the double-quoted key. The JSON path parser reads the whole quoted string as one member name, looks for a key literally named auth.login_count, fails to find it, and returns null. The four exfiltration tests all assert expect(result.exfiltrated).to.be.null.
The default sanitizeJSONPathMemberValue escapes the two characters that could close the quote wrap:
protected sanitizeJSONPathMemberValue(value: string): string {
return value.replace(JSON_PATH_MEMBER_WRAP_REGEX, (char) =>
char === "'" ? "''" : '\\"',
)
}
MySQL and SQLite override the method because the path string itself is wrapped in a SQL string literal whose backslash rules differ. MySQL needs \\\\ for a single literal backslash because the SQL string parser eats one pair and the JSON path parser eats the other. SQLite needs \\. Each dialect ships its own table.
.at() is handled differently. The same commit adds a runtime allowlist to JSONPathBuilder.at:
const HASH_NEGATIVE_INDEX_REGEX = /^#-\d+$/
at<...>(index: ...): TraversedJSONPathBuilder<S, O2> {
if (
(typeof index !== 'number' && typeof index !== 'string') ||
(typeof index === 'number' && !Number.isInteger(index)) ||
(typeof index === 'string' &&
index !== 'last' &&
!HASH_NEGATIVE_INDEX_REGEX.test(index))
) {
throw new Error(`Unexpected index value in .at(...): ${index}`)
}
return this.#createBuilderWithPathLeg('ArrayLocation', index)
}
The set of accepted values is an integer, the literal string 'last', or the pattern #-N. Three named cases. Anything else throws at the point the value enters the builder. That is a true allowlist.
.key() has no equivalent. The quote wrap is the gate. The set of accepted member-key values is whatever the database's quoted-key parser accepts inside "...", which today across MySQL, PostgreSQL ->$/->>$, and SQLite is any sequence of non-quote characters, including dots, brackets, wildcards, and the path-language question marks. The grammar happens to read those as literal characters inside a quoted key. The day the grammar changes, the day a future dialect adds path predicate syntax to its quoted-key parser, the day a maintainer needs to allow $."..".[?(@.x=='y')] style filters, the set of inputs .key() accepts opens for that grammar without touching JSONPathBuilder.
Convention is the allowlist.
Kysely is a type-safe TypeScript SQL query builder. The library's value proposition is that the type system tells you which columns exist, which keys those columns can hold, and which operations apply to which types. For fixed object shapes the type system delivers on every part of that promise. The literal-union constraint on K for a column typed { city: string; country: string } rejects .key('city.country') at compile time because the literal 'city.country' is not in the union. That is the case the documentation's examples illustrate. That is the case the maintainer's SQL-injection test had to opt out of by appending as never.
For the other case, the case where the schema declares the column as Record<string, T> because the keys are not knowable at the schema layer, the type collapses to string and the constraint resolves to "accepts anything." The runtime then concatenates the accepted-anything string into a JSON path expression whose own grammar treats five characters as structural. The TypeScript convention "this parameter is one property name" lives in the developer's reading of the type signature and in the docstring's examples. The code never installed it.
This is the Convention Is The Allowlist shape, on the type-system axis rather than the spec-RFC axis. Streamlink CVE-2026-44353 is the same shape on the URL-scheme axis: the m3u8 parser implemented what RFC 3986 grammar permits and trusted the convention that segment URIs are HTTP or HTTPS to do the constraining work. The convention did not. Kysely's .key() parameter is the same shape on the type-system axis: the type signature implemented what the conditional resolves to and trusted the convention that "a key" means one property name to do the constraining work. The convention did not.
The patch in each case narrows the implementation against the local context the maintainer can see today. Streamlink's patch installs a downgrade comparison against the playlist's own scheme. Kysely's patch wraps member keys in double quotes whose grammar today treats path metacharacters as literal. The set of accepted values for .key() is now whatever a future quoted-key parser accepts, on whatever dialect Kysely later adds. The convention that K is one property name remains in the type signature.
The 60 days between the March commit and the May commit are the part of the story the CVE record does not contain. The 0.28.12 release notes said "is injectable" because the maintainer's threat model at the time included SQL injection of the outer statement and did not include exfiltration through the inner path. The 0.28.17 release notes said "further harden against SQL injections and exfiltrations" because by then somebody had reported that the inner path was its own grammar. Two months of users running production code through eb.ref(col, '->$').key(req.query.field) against Record<string, T> columns sat between the two namings.
Advisory: GHSA-pv5w-4p9q-p3v2.