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
[P1][security] Restore runs statements serially with no transaction wrapper; mid-file errors leave DB half-populated #359
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
Create test dump with intentional column-count mismatch mid-file
Restore against empty DB with stopOnError=true
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).
Fixed, but not with the transaction the issue asks for — that one cannot work, and here is the check.
START TRANSACTION;
CREATETABLEa (id INT);
INSERT INTO a VALUES (1);
ROLLBACK;
On MySQL 8.0.46 this leaves both the table and the row. MySQL commits the open transaction before every CREATE, DROP and ALTER; there is no client-side switch for it. So the acceptance criterion — "a dump with one mid-file error restored against an empty DB results in zero tables created" — is not reachable by any client, and a wrapper that appeared to promise it would be worse than none.
The restore moved to the backend and runs on one connection. It used to read the whole file into the renderer, split it there, and send back one statement per call — each on whichever pooled connection it landed on, so the USE that opened the database was not guaranteed to apply to the next statement, and neither would any SET SESSION or START TRANSACTION. That is the deeper version of what this issue found: not only was there no transaction, there was no session for one to live in.
The transaction is there, and it is honest about its reach. A data-only file is now all-or-nothing — there is a test that fails a third INSERT and checks the first two are gone. A file with DDL cannot be, so the summary carries partiallyApplied and the dialog says which of these is true:
"Rolled back — the database is as it was."
"Rolled back, but part of the file had already been applied: MySQL commits before every CREATE, DROP or ALTER, so the structural changes stand."
The old dialog said "Restore completed with N error(s)" and left the user to guess.
FOREIGN_KEY_CHECKS and UNIQUE_CHECKS go off for the restoring session and back on when it ends, which is the other half of your proposed fix and the part that does work. A file whose tables are in the wrong order now loads; there is a test for that, and another that asks every connection in the pool afterwards whether its checks are back on, because leaving one off would silently accept orphans for every later query on it.
Eleven live-server tests, passing on MySQL 8.0.46 and MariaDB 11.8.
Activity
feat(backup): stream the dump and the restore, in the backend (#652)
EVWorth commentedon Sep 12, 2026
Fixed, but not with the transaction the issue asks for — that one cannot work, and here is the check.
On MySQL 8.0.46 this leaves both the table and the row. MySQL commits the open transaction before every
CREATE,DROPandALTER; there is no client-side switch for it. So the acceptance criterion — "a dump with one mid-file error restored against an empty DB results in zero tables created" — is not reachable by any client, and a wrapper that appeared to promise it would be worse than none.What #652 does instead:
The restore moved to the backend and runs on one connection. It used to read the whole file into the renderer, split it there, and send back one statement per call — each on whichever pooled connection it landed on, so the
USEthat opened the database was not guaranteed to apply to the next statement, and neither would anySET SESSIONorSTART TRANSACTION. That is the deeper version of what this issue found: not only was there no transaction, there was no session for one to live in.The transaction is there, and it is honest about its reach. A data-only file is now all-or-nothing — there is a test that fails a third INSERT and checks the first two are gone. A file with DDL cannot be, so the summary carries
partiallyAppliedand the dialog says which of these is true:The old dialog said "Restore completed with N error(s)" and left the user to guess.
FOREIGN_KEY_CHECKSandUNIQUE_CHECKSgo off for the restoring session and back on when it ends, which is the other half of your proposed fix and the part that does work. A file whose tables are in the wrong order now loads; there is a test for that, and another that asks every connection in the pool afterwards whether its checks are back on, because leaving one off would silently accept orphans for every later query on it.Eleven live-server tests, passing on MySQL 8.0.46 and MariaDB 11.8.