Skip to content

[P0][security] SyncPreview handleExecute runs each statement independently — no transaction, no escaping, no production safety, no read-only #369

Closed

Description

@EVWorth

Context

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).

Files

  • src/components/compare/SyncPreview.tsx:62-84 (handleExecute)
  • src/components/compare/SyncPreview.tsx:74 (USE ${targetDatabase} concat)

Repro

  1. Open SQLPilot, connect two databases
  2. Open a Schema Compare tab
  3. Pick source with 5 routine differences and target with one of the routines missing
  4. Click Execute, select all 5 statements
  5. 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.

Needs human verify

yes

Activity

  1. added
    audit
    severity/p0
    kind/security
    area/compare
    on Jul 31, 2026
  2. EVWorth commented on Sep 9, 2026

    @EVWorth
    OwnerAuthor

    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 compare editor tab type, and the menu, title-bar and toolbar entry points.

  3. added a commit that references this issue on Sep 9, 2026
    d8b46ae
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/compareauditkind/securityseverity/p0

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions