Repository navigation
fix(routine): close the parameter injection, and put DROP behind the gate - #543
Merged
Merged
Conversation
…gate Closes #393, #397, #398. ## The injection (#397) Routine arguments were escaped by replacing ' with \', leaving backslashes alone. MySQL treats a backslash as an escape inside a string literal unless NO_BACKSLASH_ESCAPES is set, and it is off by default, so an argument of \' OR 1=1 -- became '\\' OR 1=1 -- ' — the one-character string \ followed by live SQL. Demonstrated against MySQL 8, comparing the two escapings on the same input: old: SELECT COUNT(*) FROM (SELECT 1) t WHERE '\\' OR 1=1 -- ' = 'x' -> 1 row. The injected predicate ran. new: ... WHERE '\\\' OR 1=1 -- ' = 'x' -> 0 rows. One string literal, compared and not matched. Values now go through quoteStringLiteral, which escapes backslashes first so the ones it introduces are not re-escaped. Same helper that fixed the identical bug in admin. ## The DROP (#393) handleDrop called api.executeQuery directly. The production-safety check lives in the result store, so going straight to the IPC layer skipped it: dropping a routine on a connection marked production was one unstyled window.confirm away, with no app-level confirmation at all. It now runs through the store, which raises the real dialog. The tab stays open while that dialog is waiting, since closing it would remove what the dialog is asking about. Identifiers in DROP, CALL and the function SELECT go through quoteIdentifier, which doubles an embedded backtick rather than letting it end the quoting. Parameter names are checked against a plain-identifier pattern instead: SET @name takes the name unquoted, so there is nothing to escape with, and refusing is the only safe answer. ## Silent coercion (#398) A non-numeric argument for a numeric parameter fell through to the string branch, so an INT parameter given "abc" was sent as 'abc' — which MySQL accepts and coerces to 0, running the routine with a number nobody typed. Same silent-wrong-value shape as the boolean cell in #421. Unparseable values are now refused and named. "1e999" is refused too: it survived isNaN as Infinity and stringified to "Infinity". BIGINT and DECIMAL keep their digits as text, so a large id does not lose its last digit on the way through Number(). The SQL building moves to src/lib/routine-sql.ts, where it can be tested without a component. 15 unit tests on the builders, 3 on the drop path. The two drop tests that assert new behaviour fail against the previous component; the third guards the tab-closing case and passes either way. Not addressed here, deliberately: #394's transaction proposal, which rests on a false premise. See the issue comment. Co-Authored-By: Claude Opus 5 <[email protected]>
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.
Closes #393, #397, #398.
The injection — #397
Routine arguments were escaped by replacing
'with\', leaving backslashes alone. MySQL treats a backslash as an escape inside a string literal unlessNO_BACKSLASH_ESCAPESis set, and it is off by default — so an argument of\' OR 1=1 --became'\\' OR 1=1 -- ': the one-character string\followed by live SQL.Demonstrated against MySQL 8, same input through both escapings:
The old form returns a row: the injected predicate ran. The new form is one string literal, compared and not matched.
Values now go through
quoteStringLiteral, which escapes backslashes first so the ones it introduces aren't re-escaped — the same helper that fixed the identical bug in admin.The DROP — #393
handleDropcalledapi.executeQuerydirectly. The production-safety check lives in the result store, so going straight to the IPC layer skipped it: dropping a routine on a connection marked production was one unstyledwindow.confirmaway, with no app-level confirmation at all.It runs through the store now, which raises the real dialog. The tab stays open while that dialog is waiting — closing it would remove what the dialog is asking about.
Identifiers in
DROP,CALLand the functionSELECTgo throughquoteIdentifier, which doubles an embedded backtick rather than letting it end the quoting. Parameter names get a different treatment:SET @nametakes the name unquoted, so there is nothing to escape with, and they're checked against a plain-identifier pattern instead.Silent coercion — #398
A non-numeric argument for a numeric parameter fell through to the string branch, so an
INTparameter givenabcwas sent as'abc'— which MySQL accepts and coerces to 0, running the routine with a number nobody typed. Same shape as the boolean cell in #421. Unparseable values are refused and named now.1e999is refused too: it survivedisNaNasInfinityand stringified to"Infinity". BIGINT and DECIMAL keep their digits as text so a large id doesn't lose its last one.Structure
SQL building moves to
src/lib/routine-sql.ts, where it can be tested without a component. 15 unit tests on the builders, 3 on the drop path — the two asserting new drop behaviour fail against the previous component; the third guards the tab-closing case and passes either way.1718 unit + 298 browser green, tsc/dprint/eslint clean.
What I did not do, and why
#394's transaction proposal rests on a false premise, so I left it alone rather than implementing something that would look like a fix. Session variables are not transactional — verified on MySQL 8,
SET @a=1; START TRANSACTION; SET @a=2; ROLLBACK; SELECT @areturns 2. Wrapping the batch in a transaction cannot deliver its stated acceptance criterion. Full write-up left on #394, including two narrower things that are genuinely left: partial apply on a failingCALL, and the fact thatCALLisn't inisDestructiveStatement, so a procedure that deletes rows runs on production with no prompt. That second one is a product decision, so I haven't made it unilaterally.🤖 Generated with Claude Code