/

CVE-2026-44635

Severity:

HIGH RISK

(7.5)

Improper Input Handling in JSON/SQL Path Construction

CVE-2026-44635

Deferred

Vulnerability type

Category:

Improper Input Handling in JSON/SQL Path Construction

CWE:

CWE-22, CWE-89, CWE-915, CWE-1284

Impact:

Unauthorized Data Access and Modification within JSON Columns

Severity:

HIGH RISK

(7.5)

CVSS version:

3.1

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

Summary

A JSON-path traversal vulnerability in Kysely's DefaultQueryCompiler allows attacker-controlled JSON keys to be inserted into SQL JSON-path expressions without proper escaping.

When untrusted input flows into methods like eb.ref(col, '->$').key(input) or .at(input), attackers can inject path separators (such as . or [*]) to traverse into sibling or child fields, gaining read and, in update statements, write access to JSON sub-fields outside the developer's intended scope across MySQL, PostgreSQL, and SQLite.

Affected context

This issue affects applications using Kysely (versions 0.26.0 to 0.28.16) that build JSON-path queries from values influenced by user or external input.

It is especially relevant where:

  • eb.ref(col, '->$').key(input) or .at(input) are used with untrusted data
  • JSON columns are typed like Record<string, T> so that K extends string is inferred and perceived as "safe"
  • Query logic relies on JSON-path segments to restrict which JSON sub-fields can be read or written

In these situations, JSON-path metacharacters within the key are not escaped, allowing the effective path to extend beyond the intended field boundary.

Exploit preconditions

  • Attack surface: Any API or feature that allows clients (or other untrusted sources) to influence JSON key names or path segments passed into Kysely's .key() or .at() helpers.
  • Required access: Ability to supply or manipulate JSON field names, filters, or selectors used in query construction (for example, request parameters, configuration values, or tenant-controlled schema-like metadata).
  • Trigger point: Execution of a Kysely query where DefaultQueryCompiler.visitJSONPathLeg renders a JSON-path expression using the attacker-controlled key without escaping metacharacters (., [, ], *, **, ?).
  • Why exploitation is possible: The compiler treats the key as a raw path leg, so metacharacters are interpreted by the underlying database JSON-path engine as additional navigation steps instead of literal characters, enabling traversal to unintended sibling or nested JSON fields.

Why this happens

The vulnerability stems from constructing JSON-path expressions by concatenating user-influenced strings directly into the path without escaping JSON-path metacharacters.

In DefaultQueryCompiler.visitJSONPathLeg, Kysely assumes the provided JSON key is a single, safe path leg, but does not encode characters like ., [, ], *, **, and ? that have special meaning in JSON-path dialects used by MySQL, PostgreSQL (->/->>), and SQLite.

This maps to CWE-1284: Improper Validation of Specified Indices or Index Ranges and is closely related to path traversal patterns (CWE-22) and query construction flaws (CWE-89): path segments act as implicit selectors, and failing to constrain or sanitize them lets attackers expand their access surface across the JSON document beyond what the surrounding code intends.

Potential impact

  • Attackers may read JSON sub-fields that should be hidden, such as internal flags, access-control data, or sensitive nested attributes.
  • Attackers may modify or overwrite unintended JSON sub-fields during update or patch operations, potentially corrupting business-critical state.
  • Logical authorization boundaries that rely on per-key isolation within a JSON column can be bypassed, enabling cross-tenant or cross-entity data exposure where multiple entities share a single JSON blob.
  • Auditing, logging, or integrity checks that assume only specific JSON paths are touched can be silently circumvented.

General mitigation guidance

Effective mitigation focuses on treating JSON-path segments as untrusted input and enforcing strict boundaries around what can become part of a path:

  • Prefer fixed, hard-coded JSON paths for sensitive fields instead of accepting arbitrary paths or keys from callers.
  • Where dynamic keys are required, validate them against an explicit allowlist of expected identifiers (e.g., a closed set of field names) before passing them into .key() or .at().
  • Implement a robust escaping or encoding layer for JSON-path segments so that characters like ., [, ], *, **, and ? are treated as literals, not navigational operators.
  • Architect data models so that security-critical distinctions (such as tenant boundaries or authorization scopes) do not rely solely on different keys within a single JSON column.
  • Apply least-privilege principles at the query level by constructing narrowly scoped projections and updates that only reference explicitly intended JSON paths.

How teams detect issues like this

Detection typically involves examining how JSON paths are built and where user input flows:

  • Static analysis: Flag calls to eb.ref(...).key(x) or .at(x) where x originates from request data, query parameters, or other untrusted sources, especially when passed through without validation or escaping.
  • Code review: Look for patterns where JSON keys are treated as "safe" purely because they are typed, such as Record<string, T>, and verify that the run-time data is constrained to an expected set of field names.
  • Query inspection: Review generated SQL (or logs of executed statements) for JSON-path expressions containing unvalidated user-supplied segments, including suspicious metacharacters in path components.
  • Policy enforcement: Incorporate automated checks in CI/CD that search for dynamic JSON-path construction without accompanying validation/encoding utilities, using lint rules or security-focused scanning tools.

Sources

SourceLink
github.comgithub.com/kysely-org/kysely/security/advisories/GHSA-pv5w-4p9q-p3v2

Frequently asked

questions

Exploitability depends on where JSON keys or selectors originate. If API clients or other untrusted parties can influence values passed into .key() or .at() without strict validation, they can typically exploit the issue to access or modify unintended JSON sub-fields. If all keys are derived from fixed, internal constants, the practical risk is lower.

No. Attackers only need a way to influence the JSON key or path segment used in Kysely's query builder. The vulnerable behavior occurs when Kysely generates SQL on the application's behalf, so the attack is usually carried out over the normal application interface (e.g., HTTP API) without direct DB credentials.

The safest pattern is to avoid directly passing untrusted strings into JSON-path helpers. Use fixed paths wherever possible, and when dynamic keys are unavoidable, restrict them to a vetted allowlist and/or pass them through a dedicated escaping function that neutralizes JSON-path metacharacters before constructing the query.

Treat all path-like and query-like strings (JSON paths, SQL fragments, field selectors) as potentially dangerous, even when they are type-checked. Design APIs that separate "what field is allowed" from "how the underlying path is constructed," enforce validation at the boundaries, and include security reviews for any new abstraction that builds structured query paths from run-time data.

Find out what's already
exploitable in your codebase.