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] [bug] applyChanges runs statements as separate awaits — partial failure corrupts DB #439
[P1] [bug] Privileges editor applyChanges runs each statement as a separate await — partial failure leaves DB inconsistent
Context
applyChanges (UserManagement.tsx:715-789) builds a statements: string[] (toRevoke, toGrant, GRANT OPTION, REVOKE GRANT OPTION, FLUSH PRIVILEGES) and runs sequentially with for (const sql of statements) await api.executeQuery(...).
Problem
Per docs/audits/admin.md F11.
If statement N fails, statements 1..N-1 have already executed, DB is partially updated. Worse: DROP USER mid-flow races with in-flight GRANT. Comments claim "preview before execution" (FR-7.1.5 acceptance) but the UI does not preview — user clicks Apply and sees the result. FLUSH PRIVILEGES on managed RDS variants just fails silently at the end.
Files
src/components/admin/UserManagement.tsx:715-789
Repro (if applicable)
Static analysis only.
Expected
A REVOKE that fails leaves DB unchanged; UI shows which statement failed and full SQL batch. Preview dialog requires explicit confirmation before any DCL runs.
Proposed fix
Scope M. (a) Wrap multi-statement batch in a single backend transaction: MasAdminService::apply_privilege_changes(connection_id, changes: Vec<PrivilegeStatement>). (b) Preview dialog before Apply shows full SQL batch in <pre>. (c) On backend error, render "Failed at statement 3 of 5 — — ".
Acceptance
REVOKE failure leaves DB unchanged; UI shows the failed statement index + full SQL batch.
Verified against MySQL 8: GRANT causes an implicit commit, so it cannot be rolled back.
START TRANSACTION;
GRANT SELECT ON *.* TO 'txprobe'@'%';
ROLLBACK;
SHOW GRANTS FOR 'txprobe'@'%';
→ GRANT SELECT ON *.* TO `txprobe`@`%`
The grant survives the rollback. Wrapping applyChanges in a transaction would change nothing — every GRANT/REVOKE/FLUSH PRIVILEGES commits as it executes.
The underlying problem stands: the loop for (const sql of statements) await api.executeQuery(...) leaves privileges half-applied when a middle statement fails, and the user sees only the error from the one that failed.
Since atomicity is off the table, the remedy has to be different:
Order the statements so a partial failure is least harmful — apply GRANTs before REVOKEs, so an interruption leaves the user with more access than intended rather than locked out mid-edit. (Or the reverse, if the safer default is judged to be least-privilege — worth an explicit decision either way, and a comment recording it.)
Report what actually applied. On failure, surface the statements that succeeded, the one that failed, and the ones never attempted, rather than a bare error string.
Re-read the grants after any outcome, success or failure, so the UI reflects the server rather than the optimistic edit. loadGrants() is currently called only on success.
Retitling suggestion: "applyChanges leaves privileges half-applied on partial failure — and cannot be made atomic".
Activity
EVWorth commentedon Aug 29, 2026
The proposed fix is not possible
Verified against MySQL 8:
GRANTcauses an implicit commit, so it cannot be rolled back.The grant survives the rollback. Wrapping
applyChangesin a transaction would change nothing — everyGRANT/REVOKE/FLUSH PRIVILEGEScommits as it executes.The underlying problem stands: the loop
for (const sql of statements) await api.executeQuery(...)leaves privileges half-applied when a middle statement fails, and the user sees only the error from the one that failed.Since atomicity is off the table, the remedy has to be different:
GRANTs beforeREVOKEs, so an interruption leaves the user with more access than intended rather than locked out mid-edit. (Or the reverse, if the safer default is judged to be least-privilege — worth an explicit decision either way, and a comment recording it.)loadGrants()is currently called only on success.Retitling suggestion: "applyChanges leaves privileges half-applied on partial failure — and cannot be made atomic".
fix(admin): enforce read-only connections, and stop the app killing i…
fix(admin): report what a half-applied privilege change actually did (#…