Harden query execution and inline write safety - #43
Open
fcoury wants to merge 2 commits into
Open
Conversation
fcoury
marked this pull request as ready for review
July 10, 2026 01:28
fcoury
force-pushed
the
agent/harden-query-execution
branch
from
July 10, 2026 15:50
213dad5 to
52bfe22
Compare
Bound eligible Classic results before cursor materialization and add fail-closed write classification, destructive confirmations, and saved read-only connections with PostgreSQL session enforcement. Parameterize metadata lookups and preserve typed cell values while confirming generated update SQL before execution.
Run strict workspace linting, the Rust 1.88 compatibility check, and startup coverage in CI. Make database-backed tests fail when their required connection is missing. Update local hooks for the workspace layout and document saved read-only connection safeguards.
fcoury
force-pushed
the
agent/harden-query-execution
branch
from
July 14, 2026 06:05
52bfe22 to
9705e8c
Compare
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.
Why
After #44 landed, tsql streams unpageable simple-protocol results and preserves SQL
NULLidentity, but several safety gaps remain around server-side result bounds and writes against production-like connections. Large eligible queries can be constrained earlier, metadata lookups should not interpolate table names, and destructive or generated writes should be reviewable before execution.This change adds layered accident prevention without treating client-side checks as an authorization boundary: saved read-only PostgreSQL connections also enable the server's read-only transaction default, while the TUI fails closed when it cannot confidently classify a statement.
What Changed
SELECT,WITH,VALUES, andTABLEstatements—including joins, subqueries, and CTEs—through a capped cursor query, and cap direct DMLRETURNINGresults before they reach the simple-protocol result path.UPDATEorDELETEstatements without a matching top-levelWHERE; require confirmation for destructive Classic queries and direct destructive Notebook users to Classic for review.read_only_connectionsconfiguration for saved connections, block writes and unknown statement shapes locally, enabledefault_transaction_read_onlyfor PostgreSQL sessions, disable inline cell editing, and mark the active connection as[read-only]in the status line.Saved connections can be protected in
~/.tsql/connections.toml:This setting is an accident-prevention guard. Database roles without write privileges remain the security boundary.
How to Test
read_only_connections, connect through that saved entry, and confirm the status line includes[read-only]. Run aSELECTand verify it succeeds, then attempt anUPDATE,CALL, or malformed statement and verify tsql blocks it.UPDATEorDELETEwithout a top-levelWHERE. Confirm the destructive-write dialog shows the statement, cancel it, and verify no rows changed. Then run a scopedUPDATE ... WHERE ...and verify it follows the normal execution path.UPDATEbefore execution. Exercise a text column containingNULL,123, ortrueand verify the value remains text rather than being coerced.connection.max_rows, run a larger join or CTE in Classic mode, and verify the result stays within the configured cap while normal paging and result transforms remain usable.Targeted tests run for this change:
cargo test -p tsql query_safety --libcargo test -p tsql destructive_query_requests_confirmation --libcargo test -p tsql read_only_saved_connection_fails_closed_for_writes_and_unknown_sql --libcargo test -p tsql cell_update_confirmation_includes_generated_sql --libcargo test -p tsql test_build_update_where_clause_falls_back_to_ctid_match --libcargo test -p tsql --test startup_nonblockingTEST_DATABASE_URL=postgres://fcoury@localhost/postgres cargo test -p tsql --test integration_tests