Repository navigation
fix: skip quoted SQL and comments when binding parameters - #93
Merged
Merged
Conversation
End # and -- comments only at \n. TiDB's lexer (startWithSharp, startWithDash) does not end them at \r, so ending them at \r let the template "SELECT ? -- c\r'\n, ' ? '" place the second value inside a string literal in TiDB's parse, where a quote-free value such as " OR 1=1 -- " changes the statement. Reject /*! */ and /*T![...] */ comments in queries with parameters. TiDB scans their contents as SQL, ends them at a */ token rather than at a */ inside a string literal, and runs /*T! only for features the server supports. The formatter cannot reproduce that, and "SELECT 1 /*! , '*/ ? ' */" produced the same injection. Queries without parameters are sent unchanged.
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.
Problem
The formatter replaces
?and:nameinside SQL string literals. The quotes added around a parameter can close the template's literal and place attacker-controlled text in SQL code position. For example, a question mark in'Are you sure?'consumes a parameter and permits the quote-free payloadOR 1=1 --to alter the statement.Changes
Scan the SQL template and replace placeholders only outside quoted strings, quoted identifiers, and comments. Preserve existing value formatting, duplicate named parameters, and missing-parameter behavior. Document unquoted placeholders and passing an entire LIKE pattern as a parameter.
Add regression coverage for the reported positional and named payloads, escaped and doubled quotes, comments, and the SQL body sent through the public connection API. This change targets placeholder context; it does not change value escaping or add SQL-mode negotiation.
Validation
npm test -- --runInBand: all 91 tests pass, including the build.npm run lintand ESLint on the changed test files pass.git diff --checkpasses.Requests were verified using mocked fetch; no live database was used.