Skip to content

Sanitization: Harden placeholder parsing - #218

Merged
no-itsbackpack merged 1 commit into
mainfrom
harden-placeholder-parsing
Sep 23, 2026
Merged

no-itsbackpack merged 1 commit into
mainfrom
harden-placeholder-parsing

Conversation

@no-itsbackpack

@no-itsbackpack no-itsbackpack commented Sep 23, 2026

Copy link
Copy Markdown
Contributor

What

  • Scan Vitess SQL lexical contexts before replacing positional or named placeholders, leaving markers inside quoted strings, identifiers, variable tokens, and non-executable comments unchanged.
  • Recognize // line comments and defensively treat form feed or vertical tab after -- as comment whitespace, preventing scanner desynchronization across tokenizer variants.
  • Format executable /*! ... */ comments while failing closed where Vitess 23 and 24 tokenize the body differently. Split injected /* and */ pairs across adjacent literals, including overlapping delimiters.
  • Preserve token boundaries around variables, version prefixes, and adjacent SQL tokens. Require AS before quoted select-list aliases whose text could concatenate with a quoted value.
  • Escape apostrophes with SQL quote doubling, and reject empty arrays and non-finite numbers rather than emitting missing or identifier-like values.
  • Cover the reported injection paths and tokenizer edge cases with regression tests.

Why

Blind placeholder replacement can consume markers from SQL literals, comments, or variable names and then place attacker-controlled values into executable SQL. It can also change the tokenization of a valid bind marker when the formatted value touches a comment version, variable, alias, or operator. The formatter must follow the supported Vitess lexical boundaries and reject cases whose meaning cannot be preserved safely.

Scan SQL lexical context before substituting placeholders so markers
inside literals and non-executable comments are left alone, and reject
values that cannot be formatted safely.

Co-authored-by: Cursor <cursoragent@cursor.com>
@no-itsbackpack
no-itsbackpack requested review from a team and mattrobenolt as code owners September 23, 2026 16:49
@no-itsbackpack
no-itsbackpack merged commit 12ae0f7 into main Sep 23, 2026
9 checks passed
@no-itsbackpack
no-itsbackpack deleted the harden-placeholder-parsing branch September 23, 2026 17:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants