You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[P0][security] SyncPreview handleExecute runs each statement independently — no transaction, no escaping, no production safety, no read-only #369
SyncPreview (Schema Compare & Sync) is the one-way sync mechanism. User picks source/target databases, sees diff, clicks Execute to apply N statements on the target.
Problem
src/components/compare/SyncPreview.tsx:62-84 (handleExecute) sends each statement via api.executeQuery(targetConnectionId, cleanSql) one-by-one. If statement 5 of 10 fails (constraint violation, duplicate key, FK mismatch), statements 1-4 are already committed on the target. The opening USE ${targetDatabase} is built with raw string concatenation — no escapeId call (compare F4 covers the escape; this F covers the atomicity). Flow bypasses resultStore.executeQuery's DESTRUCTIVE_PATTERN production confirm, read_only profile flag (admin F1 pattern), query_timeout_secs (editor F3 column exists but never enforced), and statement row-limit (no limit arg, so INSERT INTO big SELECT * returns all rows).
Pick source with 5 routine differences and target with one of the routines missing
Click Execute, select all 5 statements
Imagine the 3rd statement fails (e.g., target routine has dependent objects)
Expected
Either all 5 statements apply or none do. Database name is escaped. Production connection requires explicit confirmation.
Proposed fix
Add a dedicated execute_sync_preview(connection_id, target_database, statements: Vec<{ sql, type }>) Tauri command (new mas-sync crate or commands/mod.rs) that (1) opens a sqlx::Transaction, (2) executes each statement via sqlx::query().execute(&mut *tx), (3) commits only if all succeed (rollback on first error), (4) checks ConnectionManager::get_profile(connection_id).read_only and rejects with CoreError::ReadOnlyViolation. Frontend handleExecute calls this single command. Use escapeId(targetDatabase) for the USE statement. Pre-validate destructiveCount > 0 against profile.environment === "production". Scope: L.
Acceptance
A 5-statement sync where statement 3 fails leaves the target with zero changes (full rollback). A sync against read_only=true is rejected with a clear error. A targetDatabase = "weird`name" test value produces USE weird``name and runs without injection.
Schema compare could not back the claim it made — foreign keys were absent from the snapshot entirely, DDL was compared after lowercasing and collapsing whitespace, and column order was ignored — while the sync half could leave a target half-migrated. A compare tool that is quietly wrong is worse than none, because people act on its answer.
Fixing that properly is a real piece of work, most of it a genuine DDL comparison rather than string normalisation, and the feature is not part of how this project is used. Removed rather than carried: the history has it if someone wants it back.
Removed in the PR closing this issue: SchemaCompare, SyncPreview, schema-diff, sync-sql-generator, their tests, the compare editor tab type, and the menu, title-bar and toolbar entry points.
Activity
EVWorth commentedon Sep 9, 2026
Closed by removing the feature.
Schema compare could not back the claim it made — foreign keys were absent from the snapshot entirely, DDL was compared after lowercasing and collapsing whitespace, and column order was ignored — while the sync half could leave a target half-migrated. A compare tool that is quietly wrong is worse than none, because people act on its answer.
Fixing that properly is a real piece of work, most of it a genuine DDL comparison rather than string normalisation, and the feature is not part of how this project is used. Removed rather than carried: the history has it if someone wants it back.
Removed in the PR closing this issue: SchemaCompare, SyncPreview, schema-diff, sync-sql-generator, their tests, the
compareeditor tab type, and the menu, title-bar and toolbar entry points.feat: remove schema compare (#577)