Skip to content

fix(security): stop lint and Ask Veloxy from running unconfirmed writes - #66

Open
abeni16 wants to merge 1 commit into
mainfrom
fix/lint-and-veloxy-autorun
Open

abeni16 wants to merge 1 commit into
mainfrom
fix/lint-and-veloxy-autorun

Conversation

@abeni16

@abeni16 abeni16 commented Oct 27, 2026

Copy link
Copy Markdown
Collaborator

Summary

Fixes two paths that could run data-modifying SQL with no confirmation from the user.

1. Editor lint ran SQL on every keystroke (High)

lint_sql sent EXPLAIN <sql> to Postgres through simple_query. The simple-query protocol runs every statement in the string, so editor content like SELECT 1; DELETE FROM users; ran the DELETE 280 ms after typing, with no Run click and none of run_query's write confirmation. sqlx's SQLite driver also runs multi-statement strings.

  • Lint now returns no diagnostics unless the input is exactly one statement, using the quote-aware split_sql_statements. This applies to all engines.
  • Postgres now validates with client.prepare(&sql) instead of EXPLAIN. Prepare parses and plans without executing, and Postgres rejects multiple commands in a prepared statement, so this holds even if the splitter miscounts.
  • Side benefit: Postgres error positions are now correct (they were offset by the EXPLAIN prefix), and statements like DDL can now be linted.

2. Ask Veloxy auto-ran SQL based on the model's self-reported intent (High)

The backend passed the model's intent field through unchanged, and the frontend auto-ran whenever intent === "select". A reply such as {"sql": "DELETE FROM orders WHERE id = 7", "intent": "select"} ran immediately.

  • veloxy.rs now always derives intent with classify_sql_intent(&sql).
  • useAppState.ts gates auto-run on isReadOnlySql(sql, engine), which also catches data-modifying WITH CTEs.

Reviewer notes

  • Trade-off: multi-statement scripts no longer get live lint diagnostics.
  • Not tested against a live Postgres. cargo check, cargo test --lib (115 passed), tsc, vitest (115 passed) and eslint are clean.
  • Known remaining gap, out of scope: isReadOnlySql treats every SELECT as read-only, so SELECT ... INTO and volatile function calls could still auto-run from Ask Veloxy.

🤖 Generated with Claude Code

The editor linter sent `EXPLAIN <sql>` to Postgres via the simple-query
protocol on every keystroke. Postgres executes every statement in a
simple query, so `SELECT 1; DELETE FROM users;` ran the DELETE with no
Run click or confirmation. Lint now skips multi-statement input for all
engines (sqlx SQLite has the same multi-statement behaviour) and
Postgres validates via prepare(), which parses and plans without
executing and rejects multiple commands. This also fixes Postgres error
positions, which were offset by the "EXPLAIN " prefix.

Ask Veloxy auto-ran generated SQL whenever the model reported
`intent: "select"`, regardless of the SQL itself. The backend now
derives intent from the SQL, and the frontend gates auto-run on
isReadOnlySql() so writes always require confirmation.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@sonarqubecloud

Copy link
Copy Markdown

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.

1 participant