Skip to content

[P1][security] Restore runs statements serially with no transaction wrapper; mid-file errors leave DB half-populated #359

Description

@EVWorth

Context

Restore feature — backup/restore feature (DESIGN_REQUIREMENTS FR-8). Per docs/audits/backup.md F3.

Problem

src/components/backup/RestoreDialog.tsx reads SQL file, splits via splitSqlStatements, runs each via api.executeQuery. Grep for BEGIN|COMMIT|ROLLBACK|FOREIGN_KEY_CHECKS in RestoreDialog returns zero hits. No START TRANSACTION wrapper, no SET FOREIGN_KEY_CHECKS=0. A dump with CREATE TABLE users (...) followed by INSERT INTO users VALUES (...) where INSERT fails leaves the DB with the new (empty) table but not the inserts — silent data loss.

Files

  • src/components/backup/RestoreDialog.tsx:65-385

Repro

  1. Create test dump with intentional column-count mismatch mid-file
  2. Restore against empty DB with stopOnError=true
  3. Observe first N-1 statements committed, dump aborted mid-way

Expected

Whole restore wrapped in transaction. On error, full rollback (when stopOnError=true).

Proposed fix

M: wrap whole restore in BEGIN...COMMIT/ROLLBACK block. Add SET FOREIGN_KEY_CHECKS=0/=1 prologue/epilogue. Surface partial-restore status explicitly.

Acceptance

Dump with one mid-file error restored against empty DB with stopOnError=true results in zero tables created (full rollback).

Needs human verify

yes

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/backupAudit areaauditTracks a feature-by-feature codebase audit findingkind/securityAudit finding categoryseverity/p1Audit finding severity

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions