/

CVE-2026-33468

Severity:

HIGH RISK

(8.1)

SQL Injection in Kysely MySQL Query Compilation

CVE-2026-33468

Analyzed

Vulnerability type

Category:

SQL Injection

CWE:

CWE-89

Impact:

Arbitrary SQL Injection in MySQL Backends

Severity:

HIGH RISK

(8.1)

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

Kysely's MySQL query compiler previously escaped only single quotes in string literals and failed to correctly handle backslashes, leaving generated SQL vulnerable to injection.

In environments where MySQL's NO_BACKSLASH_ESCAPES is disabled (the default), an attacker controlling values used in certain schema-building APIs could break out of string literals and inject arbitrary SQL during index or view creation.

Affected context

This vulnerability affects applications using Kysely with:

  • The MySQL dialect (or compatible engines honoring MySQL backslash escapes)
  • Default MySQL configuration where NO_BACKSLASH_ESCAPES is OFF
  • Code paths that rely on ImmediateValueTransformer to inline values into SQL,

particularly:

  • CreateIndexBuilder.where()
  • CreateViewBuilder.as()

The issue becomes relevant when untrusted or partially trusted data can influence string values passed into these builders, and the resulting SQL is executed against a MySQL database.

Exploit preconditions

  • Attack surface: Application code that generates DDL or schema-related SQL through Kysely, especially index predicates and view definitions.
  • Required access: Ability for an attacker to supply or influence string values that are passed into APIs ultimately handled by ImmediateValueTransformer and compiled by DefaultQueryCompiler.sanitizeStringLiteral().
  • Trigger point: Execution of SQL statements that inline attacker-controlled values into MySQL string literals without correctly escaping backslashes.
  • Why exploitation is possible: The sanitizer doubles single quotes but leaves backslashes unescaped. In MySQL with NO_BACKSLASH_ESCAPES turned OFF, a backslash can escape the closing quote of a string literal, causing the rest of the attacker-controlled input to be interpreted as SQL syntax rather than data.

Why this happens

The core issue is incomplete server-side escaping of string literals in SQL generated by Kysely's MySQL compiler.

Specifically, DefaultQueryCompiler.sanitizeStringLiteral() performs quote escaping (' → '') but does not account for MySQL's use of the backslash as an escape character when NO_BACKSLASH_ESCAPES is OFF.

This maps to CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection'), where user-controlled input is inlined into SQL without robust neutralization of all special characters relevant to the target database dialect.

Because ImmediateValueTransformer chooses to inline certain values directly into the query string instead of using parameterized placeholders, unsafe escaping of backslashes allows attacker-controlled content to alter the intended SQL structure.

Potential impact

  • Attackers could inject arbitrary SQL fragments into index predicates or view definitions.
  • Malicious SQL could modify or drop tables, indexes, or views, impacting database integrity.
  • Crafted injections could expose sensitive data through expanded view definitions or side-channel queries.
  • Persistent schema-level changes may facilitate further abuse, such as logic manipulation or privilege escalation in the application's data layer.

General mitigation guidance

Effective mitigation focuses on eliminating unsafe string inlining and ensuring dialect-aware escaping:

  • Favor parameterized queries or bind parameters wherever possible, avoiding direct inlining of user-controlled values into SQL.
  • When literals must be inlined, use escaping routines that are explicitly designed for the specific SQL dialect, covering all special characters, including backslashes for MySQL in default configurations.
  • Restrict untrusted input from influencing schema-building APIs such as index or view builders; confine those APIs to static, code-defined values.
  • Consider enforcing safer MySQL modes (such as enabling NO_BACKSLASH_ESCAPES) as a defense-in-depth measure, while not relying solely on server configuration for security.
  • Apply the principle of least privilege to database accounts so that, even if injection occurs, the executing role cannot perform destructive schema operations.

How teams detect issues like this

Organizations can detect this class of issue through a combination of code and behavior analysis:

  • Static analysis and code review:
  • Flag manual string concatenation or inlining of variables into SQL fragments, particularly in schema-building code.
  • Identify uses of query builders that inline values rather than using parameters, especially around MySQL-specific compilation paths.
  • Review escaping utilities to confirm that they are dialect-aware and uniformly applied.
  • Policy and tooling:
  • Add linting or custom static-analysis rules to disallow direct construction of SQL literals with unescaped or partially escaped user input.
  • Use automated code review tools to highlight uses of lower-level compiler hooks or transformers that bypass parameterization.
  • Runtime monitoring:
  • Enable SQL logging and alert on anomalous DDL statements or unexpected index/view definitions originating from application paths that normally perform read or simple write operations.
  • Monitor for repeated schema changes or unusual query patterns that may indicate abuse of injection primitives.

Sources

SourceLink
github.comgithub.com/kysely-org/kysely/security/advisories/GHSA-8cpq-38p9-67gx

Frequently asked

questions

It can be, if an external user can influence the string values used in Kysely's affected builders and those values are ultimately executed against a MySQL database with backslash escapes enabled. The exploitability depends on how the application exposes these code paths.

The attacker needs the ability to supply or manipulate data that is passed into APIs that use ImmediateValueTransformer for MySQL query compilation. This could range from crafted HTTP requests in a web app to tampering with configuration or metadata that the application uses to construct schema-related SQL.

The most robust fix is to avoid inlining user-controlled values in SQL and rely on parameterized queries. Where literals are unavoidable, use a thoroughly tested, dialect-aware escaping mechanism that neutralizes all special characters relevant to the database, and confine schema-building constructs to static, developer-controlled inputs.

Establish secure coding guidelines that mandate parameterization, enforce dialect-specific escaping for any remaining literals, and prohibit untrusted input from influencing schema or query structure. Back this with automated checks in CI, regular security-focused code reviews for query construction code, and a preference for high-level APIs that are secure-by-default.

Find out what's already
exploitable in your codebase.