You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[P1][security] executeFunction constructs SELECT with raw identifier concat; formatParamValue uses backslash-escape #397
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.
With NO_BACKSLASH_ESCAPES sql_mode, MySQL rejects this
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.
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.
Activity
fix(routine): close the parameter injection, and put DROP behind the …
fix(import): one escape table, and say what a dump will drop (#579)
EVWorth commentedon Sep 12, 2026
Already fixed, and now verified rather than assumed.
Both halves were closed by the
sql-quotework:buildFunctionCallquotes the database and the routine name withquoteIdentifier, so a database calledweird`nameworks.formatParamValuedoubles the quote —don't→'don''t'— which is correct whetherNO_BACKSLASH_ESCAPESis 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')returnsfn:don't, and a procedure called witha' 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 ofx', 1); DROP TABLE victim; --in a SQLPilot dump dropped the table on restore underNO_BACKSLASH_ESCAPES. Fixed in #650. The instinct behind this issue was right; it was just worse in the other place.