Skip to content

[P1] [bug] applyChanges runs statements as separate awaits — partial failure corrupts DB #439

Closed

Description

@EVWorth

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

Needs human verify

Yes

Labels: audit, area/admin, severity/p1, kind/bug

Activity

  1. added
    audit
    severity/p1
    kind/bug
    area/admin
    on Jul 31, 2026
  2. EVWorth commented on Aug 29, 2026

    @EVWorth
    OwnerAuthor

    The proposed fix is not possible

    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:

    1. 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.)
    2. 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.
    3. 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".

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/adminauditkind/bugseverity/p1

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions