Skip to content

fix: string literals are injectable on MySQL when backslash escapes (\\') are used.#1754

Merged
igalklebanov merged 2 commits intomasterfrom
fix-mysql-backslash-literal-injection
Mar 20, 2026
Merged

fix: string literals are injectable on MySQL when backslash escapes (\\') are used.#1754
igalklebanov merged 2 commits intomasterfrom
fix-mysql-backslash-literal-injection

Conversation

@igalklebanov
Copy link
Copy Markdown
Member

Hey 👋

MySQL treats backslashes as escapes in string literals via a system setting by default.

PostgreSQL treats backslashes in string literals as regular characters via system setting by default. Other databases do the same and don't provide a system setting.

This PR denies a SQL injection vector for MySQL users who use sql.lit(string) or similar or Kysely<any>/ignoring compilation errors when using eb.ref(column, '->$').key(injection).

A clever attacker could detect doubling of ' to prevent standard literal string SQL injections, and could escape his ' with a backslash turning the doubling of ' into introduction of a single ' and enabling malicious text to be "queryable" after it.

@igalklebanov igalklebanov added bug Something isn't working built-in dialect Related to a built-in dialect mysql Related to MySQL security labels Mar 20, 2026
@vercel
Copy link
Copy Markdown

vercel Bot commented Mar 20, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
kysely Ready Ready Preview, Comment Mar 20, 2026 7:30am

Request Review

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Mar 20, 2026

✅ ⏱️ No benchmark changes detected following cae1f5a.

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Mar 20, 2026

commit: cae1f5a

@igalklebanov igalklebanov merged commit e63ceb9 into master Mar 20, 2026
32 checks passed
@igalklebanov igalklebanov deleted the fix-mysql-backslash-literal-injection branch March 20, 2026 08:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working built-in dialect Related to a built-in dialect mysql Related to MySQL security

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant