Repository navigation
mysql: quote column names and bind every WHERE value - #87
Merged
Merged
Conversation
insert(), update() and whereConditions() put object keys into the SQL as
column names, and those keys can come from a request payload. The Joi
schemas reject unknown keys today, so nothing reaches them, but the
builders relied on that. They now quote each column with escapeId.
update() takes its WHERE as an object of bound values; the stores passed
`nt_x_id=${id}`. A string WHERE still works for SQL whose placeholders
the caller binds. The group and user subgroup IN lists bind their ids.
Clears CodeQL js/sql-injection (alerts 15 and 28).
msimerson
force-pushed
the
mysql-escape-identifiers
branch
from
October 16, 2026 03:34
423adbb to
b3766ad
Compare
There was a problem hiding this comment.
🟢 Approval recommended
Static review found no blocking defects in the builders or migrated callers; database-backed tests were not run during review.
0 open findings
What changed in this PR
Hardens the shared MySQL builders and store callers against SQL injection without relying solely on route validation.
Changes:
- Quotes column identifiers and supports bound object-based UPDATE conditions.
- Binds store IDs and subgroup list values.
- Adds identifier-quoting and WHERE compatibility tests.
| File | Description |
|---|---|
| lib/zone/store/mysql.js | Binds zone update and delete IDs. |
| lib/zone_record/store/mysql.js | Binds record delete IDs. |
| lib/user/store/mysql.js | Binds user IDs and subgroup lists. |
| lib/session/store/mysql.js | Binds session update IDs. |
| lib/permission/store/mysql.js | Binds permission update and delete IDs. |
| lib/nameserver/store/mysql.js | Binds nameserver update and delete IDs. |
| lib/mysql.test.js | Tests quoting and both UPDATE condition forms. |
| lib/mysql.js | Quotes identifiers and binds object-based conditions. |
| lib/group/store/mysql.js | Binds group IDs and subgroup lists. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Mysql.insert(),update()andwhereConditions()put object keys into the SQL as column names, and those keys can come from a request payload (CodeQLjs/sql-injection, alerts 15 and 28). The routes' Joi schemas reject unknown keys, so nothing reaches them today, but the builders depended on that.escapeId, so a key such asis_admin=1,first_nameis one quoted identifier.update()takes its WHERE as an object of bound values. The stores passed\nt_x_id=${id}`; all 14 callers now pass{ nt_x_id: id }`. A string WHERE still works, for SQL whose placeholders the caller binds, as zone_record: PUT merges onto the stored record #77 does.IN (...)lists bind their ids.LIMIT/OFFSET stay interpolated; both are
Number.isInteger-guarded.Merge after #77, #84 and #86, then rebase: each rewrites some of the same
Mysql.updatecalls.lib/mysql.jsmerges cleanly with thetransaction()that #84 and #86 add.Tests pass on mysql (497), json (467) and toml (467).
lib/mysql.test.jscovers the quoting, both WHERE forms, and a hostile key ininsertandupdate.