Skip to content

[P1][security] executeFunction constructs SELECT with raw identifier concat; formatParamValue uses backslash-escape #397

Closed

Description

@EVWorth

Context

Routine Viewer function execute builds a SELECT statement to call a stored function.

Problem

src/components/routine/RoutineViewer.tsx:190-200 (executeFunction) builds SELECT with raw identifier concat, no escapeId. The args is built from formatParamValue (line 528-540) which escapes single quotes via backslash-escaping. MySQL default sql_mode accepts backslash escapes but with NO_BACKSLASH_ESCAPES enabled (common on hardened prod), this produces a SQL syntax error. Cross-standard escape is two single quotes (don't -> 'don''t'), always works.

Files

  • src/components/routine/RoutineViewer.tsx:190-200 (executeFunction)
  • src/components/routine/RoutineViewer.tsx:528-540 (formatParamValue)

Repro (test-only)

  1. formatParamValue("don't", "VARCHAR") returns "'don\'t'" — backslash escape
  2. With NO_BACKSLASH_ESCAPES sql_mode, MySQL rejects this
  3. Function execute with database = "weird`name" (test only) succeeds via escaped identifier

Expected

formatParamValue("don't", "VARCHAR") returns 'don''t'. Function execute with database = "weird`name" (test only) succeeds via escaped identifier.

Proposed fix

(1) Use escapeId(database) and escapeId(routineName) (or the new sql-quote.ts). (2) Replace value.replace(/'/g, "\'") with value.replace(/'/g, "''"). (3) Add a unit test for formatParamValue("don't", "VARCHAR") returning 'don''t'. Scope: S.

Acceptance

formatParamValue("don't", "VARCHAR") returns 'don''t'. Function execute with database = "weird`name" (test only) succeeds via escaped identifier.

Needs human verify

no

Doc drift

no

Activity

  1. added
    audit
    severity/p1
    kind/security
    area/routine
    on Jul 31, 2026
  2. EVWorth commented on Sep 12, 2026

    @EVWorth
    OwnerAuthor

    Already fixed, and now verified rather than assumed.

    Both halves were closed by the sql-quote work:

    • buildFunctionCall quotes the database and the routine name with quoteIdentifier, so a database called weird`name works.
    • formatParamValue doubles the quote — don't → 'don''t' — which is correct whether NO_BACKSLASH_ESCAPES is set or not, and it now refuses a value the parameter's type cannot hold rather than handing MySQL something it will coerce.

    Checked live on MySQL 8.0.46 and MariaDB 11.8 rather than taken on trust: f_in('don''t') returns fn:don't, and a procedure called with a' OR 1=1 -- receives and stores that as a string. #653 adds tests pinning both statement shapes, including one asserting the built SQL contains no \\'.

    Worth recording what checking this class of bug found elsewhere: the same \' escape in the backup generator was a reproduced injection — a row value of x', 1); DROP TABLE victim; -- in a SQLPilot dump dropped the table on restore under NO_BACKSLASH_ESCAPES. Fixed in #650. The instinct behind this issue was right; it was just worse in the other place.

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/routineauditkind/securityseverity/p1

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions