Repository navigation
fix(admin): quote passwords as string literals, and names as identifiers - #521
Merged
Merged
Conversation
Two functions in this codebase were both called `escapeIdentifier` and did
different things — backticks in backup-generator.ts, single quotes in
admin/userPrivileges.ts. That is not a hypothetical hazard. Reviewing this
area I read one and reasoned about the other, and spent a while convinced
that creating a user was broken. It was not; the admin one quotes correctly
for account names. But the name is doing real damage to anyone reading it.
They are now one module, `sql-quote.ts`, naming what each is for:
`quoteIdentifier` for names, `quoteStringLiteral` for values.
Splitting them exposed a bug the old admin helper had. It doubled single
quotes and left backslashes alone, but MySQL treats a backslash as an escape
inside a string literal unless NO_BACKSLASH_ESCAPES is set, which is off by
default. A password of `pa\ss` was written as 'pa\ss' and stored as `pass`,
because `\s` is not a recognised escape and collapses to `s`. The account was
created with a password the user never typed, the statement succeeded, and
the first anyone knew was a login failing. Verified against MySQL 8: with the
old escaping the account authenticates as `pass` and rejects `pa\ss`.
Also fixes the one place in admin that needed an identifier and had no helper
for it, so it hand-rolled backticks: `applyChanges` built the grant scope as
`` `${selectedDb}`.* `` with no doubling. MySQL permits a database named
``we`ird``, and the resulting GRANT does not parse. That call site is exactly
the confusion the shared naming is meant to prevent.
The round-trip is pinned by an integration test that creates a user with a
backslash in the password and asserts that the typed password authenticates
and the collapsed one does not — the kind of coverage #445 is about.
Refs #444
EVWorth
added a commit
that referenced
this pull request
Aug 29, 2026
…tself (#522) Two security holes in the admin area, both of the same shape: a protection that existed on paper and nowhere in the execution path. read_only was stored on the profile, carried onto the live connection, and checked in exactly one place — EXPLAIN ANALYZE. Every other path ignored it. A read-only production profile would still run DROP TABLE from the editor, create accounts from the admin panel, or grant SUPER to itself. The executor now refuses any statement that could change data, schema, privileges or server state, before the batch is assembled, so a script containing a write is rejected whole rather than half-run. Classifying by leading keyword would have left two ways through, both covered: `WITH doomed AS (...) DELETE` is a DELETE, and `EXPLAIN ANALYZE <write>` executes the write it measures — so run through the ordinary Run button, its leading EXPLAIN would have looked harmless. Plain EXPLAIN stays allowed whatever it plans, since it only plans. The verb list is an allowlist: an unrecognised statement is treated as a write and refused. kill_process had no notion of which sessions belonged to SQLPilot, and PROCESSLIST includes the connections the panel is using to read PROCESSLIST. Killing one worked; killing the last exhausted the pool and surfaced "pool timed out", which never told the user they had disconnected themselves. The pool now records each server thread it opens, kill_process refuses those, and the UI disables the button with a tooltip explaining why rather than letting the click fail. Other users' sessions stay killable. ERROR 1095 is translated into a message naming the privilege that is missing, since PROCESSLIST is visible to users who cannot act on it. Writes now carry the account they ran as in the log line, which is the audit trail #429 asks for. Two parts of #429 are deliberately not done. Parameterised SQL is not available for DDL — MySQL takes no placeholders for identifiers or privilege names, so correct quoting is the remedy, and that landed in #521. Wrapping GRANT/REVOKE in a transaction is impossible: they force an implicit commit, verified by a GRANT surviving ROLLBACK. That is recorded on #439. Refs #429, #433
This was referenced Aug 29, 2026
Closed
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.
Refs #444. Found while reviewing
area/admin.The name hazard, and what it hid
Two functions in this repo were both called
escapeIdentifierand did different things:src/lib/backup-generator.ts`name`src/components/admin/userPrivileges.ts'value'This is not a hypothetical hazard. Reviewing this area I read the first and reasoned about the second, and spent a while convinced that creating a user was broken. It wasn't — the admin one quotes account names correctly. But that's a decent demonstration of what the name costs a reader, and it's the case #444 makes.
They're now one module,
sql-quote.ts, named for what each is for:quoteIdentifierandquoteStringLiteral.The bug the split exposed
The admin helper doubled single quotes and left backslashes alone. MySQL treats a backslash as an escape inside a string literal unless
NO_BACKSLASH_ESCAPESis set — off by default. So a password ofpa\sswas written as'pa\ss'and stored aspass, since\sisn't a recognised escape and collapses tos.The statement succeeds. Nothing errors. The account is created with a password the user never typed, and the first anyone knows is a login failing.
Verified against MySQL 8 with the old escaping:
Also fixed
applyChangesneeded an identifier and admin had no helper for one, so it hand-rolled backticks with no doubling:MySQL permits a database named
we`ird, and the resultingGRANT ... ON \we`ird`.*doesn't parse (confirmed:ERROR 1046`). That call site is precisely the confusion the shared naming prevents — the correct helper didn't exist in the module it was reaching for.Tests
sql-quote.test.tscovers both quoters, including backslash-before-quote ordering so the escapes aren't re-escaped1633 frontend tests, 60 integration tests against MySQL 8 + MariaDB 11, clippy/tsc/dprint clean.
Note on #444
Leaving the issue open for the maintainer to close — the split it asks for is done, but it's worth deciding whether the remaining
escapeIdentifiername (now only inbackup-generator.tsasquoteIdentifier) satisfies it fully.🤖 Generated with Claude Code