fix(cli): reject multi-statement sql mcp queries#2811
Conversation
Merge ProtectionsYour pull request matches the following merge protections and will not be merged until they are valid. 🟢 require-ready-label-and-ciWonderful, this rule succeeded.
|
Greptile SummaryThis PR closes a second-order bypass in the MCP SQL read-only gate: a
Confidence Score: 5/5The change is safe to merge — it tightens the existing security gate without altering any passing behavior, and all four generated golden outputs are updated consistently. The new hasTrailingSQLStatement byte scanner is logically sound: it correctly tracks all five SQLite quoting contexts, the early-return on the first terminator-with-no-trailing-SQL is safe because stripLeadingSQLNoise (called as the trailing check) itself strips nested semicolons and noise, and the generator test now enforces both symbol presence and successful compilation of the emitted code. No files require special attention. Important Files Changed
|
Merge Queue Status
This pull request spent 26 minutes 53 seconds in the queue, including 22 minutes 13 seconds running CI. Required conditions to merge
|
Summary
Generated MCP
sqltools now reject SELECT-prefix multi-statement payloads before the read-only keyword allowlist runs. A query likeSELECT 1; ATTACH DATABASE ...no longer reaches SQLite, while legitimate single-statement reads still allow trailing terminators, trailing comments, and semicolons inside quoted SQL tokens.This keeps the
readOnlyHintcontract true for printed CLIs that expose SQL over the local SQLite store, including themodernc.org/sqlitecases whereATTACH DATABASEandVACUUM INTOcan write outside the primary read-only handle.Closes #2799
Verification
go test ./internal/generator -run '^TestGenerateMCPSQLToolUsesReadOnlyStore$'scripts/verify-generator-output.sh generate-golden-api generate-mcp-apigo test ./...scripts/golden.sh verify