Repository navigation
fix(sql): read 'a\\' the way PostgreSQL and SQLite do in the splitter, MCP guard and destructive-query check - #1687
Merged
Conversation
…kslashes as the dialect does; splitter built on SqlLexicalScanner
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.
Found while checking a review of the lexers:
SqlStatementSplitterhad its own copy of the quote/comment loop and always treated\'as an escaped quote (MySQL).SqlLexicalScannerhas been dialect-aware since #1566. In PostgreSQL and SQLite a backslash is an ordinary character, so forSELECT 'a\'; SELECT pg_terminate_backend(1); --'the splitter and
stripCommentsAndStringssaw one statement with a long literal, while the server runs the second statement.Affected, all by reading the code (not reproduced against a live server):
McpSqlGuard(single_statement,_forbiddenFunctions,isMutatingSqlStatement): the first layer could be passed by text hidden after such a literal. The read-only session is the second layer and stays; it does not stop functions likepg_terminate_backend.DestructiveSqlDetector.inspect(the confirm dialog before a destructive query) and the SQL workspace's statement ranges.Change
SqlStatementSplitter.spansis built onSqlLexicalScanner.segments(a;only counts in code segments), which removes the duplicated loop. NewbackslashEscapesparameter, defaulttrue: MySQL and unknown dialects behave exactly as before.DestructiveSqlDetector.splitStatements / stripCommentsAndStrings / inspect,isMutatingSqlStatementandcontainsMutatingSqltake the same parameter;E'...'strings keep their escape in every dialect.SqlDialect.backslashEscapesQuotessays it once; the MCP guard and the SQL workspace pass it.Not covered:
auditSqlExecution(mutation_audit_recorder.dart) still callscontainsMutatingSqlwithout a dialect, so a hidden mutation may be missing from the audit trail; it needs the connection type mapped to a dialect and is a follow-up.Tests: the sample above for the splitter, the guard (PostgreSQL and SQLite refused; MySQL one literal;
E'...'allowed), the destructive check and the classifier, plus a script over the isolate threshold splitting the same throughspansAsync.