Skip to content

[P1] [bug] escapeIdentifier misleading name — splits into quoteStringLiteral + quoteIdentifier #444

Closed

Description

@EVWorth

[P1] [bug] escapeIdentifier is a misleading name — it single-quote-escapes (correct for usernames in CREATE/ALTER USER) but is reused in parseGrantStatements/categorizeGrants for user@host parsing, mixing scopes

Context

escapeIdentifier (userPrivileges.ts:62-64) does MySQL string-literal escaping ('value' with '' doubling), correct for user/host/password in CREATE USER / ALTER USER / SHOW GRANTS FOR.

Problem

Per docs/audits/admin.md F16.

Helper name suggests it quotes SQL identifiers (which would be backticks). Re-using for SHOW GRANTS FOR ${escapeIdentifier(user)}@${escapeIdentifier(host)} is correct because SHOW GRANTS FOR expects single-quoted user/host literals — but the look is confusing. PrivilegesEditor builds dbScope = \${selectedDb}`.*(line 760) with raw backticks (no helper) — inconsistency. New contributors reach forescapeIdentifierand write`${escapeIdentifier(dbTable)}`because the name promises identifier escaping — produces invalid SQL like``db.table```.

Files

  • src/components/admin/userPrivileges.ts:62-64
  • src/components/admin/UserManagement.tsx:116, 429, 597, 660, 719, 760

Repro (if applicable)

Static analysis only.

Expected

quoteStringLiteral('foo') returns 'foo'; quoteIdentifier('foo') returns \foo`; quoteIdentifier('weird`name')returns`weird``name``. GRANT/REVOKE for weird-name tables don't break.

Proposed fix

Scope S. Rename escapeIdentifier → quoteStringLiteral (or split into quoteUser, quoteHost, quotePassword); add separate quoteIdentifier that backtick-escapes and doubles backticks. Update 7 call sites.

Acceptance

Identifier escaping helpers are unambiguous; weird-name tables don't break GRANT/REVOKE.

Needs human verify

No

Labels: audit, area/admin, severity/p1, kind/bug

Activity

  1. added
    audit
    severity/p1
    kind/bug
    area/admin
    on Jul 31, 2026
  2. EVWorth commented on Aug 29, 2026

    @EVWorth
    OwnerAuthor

    Done in #521. The two same-named functions are now one module, src/lib/sql-quote.ts, split into quoteIdentifier (backticks, for names) and quoteStringLiteral (quotes, for values).

    The split turned up a bug the naming was hiding. The admin helper doubled single quotes but left backslashes alone, and MySQL treats a backslash as an escape inside a string literal unless NO_BACKSLASH_ESCAPES is set — off by default. A password of pa\\ss was stored as pass; the statement succeeded and the account got a password the user never typed. Verified by authenticating: the typed password was rejected and the collapsed one accepted. An integration test now pins the round trip.

    Also fixed the one admin call site that needed an identifier and had no helper for it, so it hand-rolled backticks without doubling — a database named we\ird` made the GRANT fail to parse.

    Reopen if you would rather the remaining escapeIdentifier name in backup-generator.ts also change; it is now just a re-export of quoteIdentifier.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/adminauditkind/bugseverity/p1

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions