Skip to content

fix(safety): gate every destructive write on production, not just the editor's - #595

Merged
EVWorth merged 2 commits into
mainfrom
fix/production-gate-all-writes
Sep 10, 2026
Merged

EVWorth merged 2 commits into
mainfrom
fix/production-gate-all-writes

Conversation

@EVWorth

@EVWorth EVWorth commented Sep 9, 2026

Copy link
Copy Markdown
Owner

Closes #588.

The hole

resultStore has held the production confirmation since #393, but only statements routed through resultStore.executeQuery reach it. These call api.executeQuery directly:

  • grid cell edits (ResultsGrid.tsx:449)
  • admin — DROP USER, GRANT/REVOKE
  • import, and restore — which runs a whole dump

Editing a cell on a connection marked production wrote to it with no confirmation at all.

Why they bypassed it

The store's gate can't be awaited: it raises a dialog and returns, leaving the caller no way to learn whether the user agreed. Any caller with work to do afterwards — refresh the grid, advance an import loop — couldn't use it. #393 fixed one call site by restructuring it around that limitation instead of removing the limitation, which is why the pattern was never swept.

confirmDestructive answers. true when there's nothing to ask about (so callers gate unconditionally without judging danger themselves), false when declined (so they stop). A second question while one is open declines the first rather than stranding its promise.

Two judgement calls

  • Batches ask once. Prompting per statement through a thousand-line dump would be held down, not read.
  • The grid asks about every write, not just destructive verbs. isDestructiveStatement excludes UPDATE/INSERT because typing one is ordinary work — but nobody composes a statement to edit a cell. A stray keystroke and a click on Save is the whole gesture, so direct manipulation gets a lower bar (alwaysAsk).

Incidental

isProductionConnection tolerates an absent connection list rather than throwing — a read landing before connections load is the same situation as a connection not in the list, and both already answer "not production". Throwing would abort the caller's save instead of gating it. The grid's test mock omitting those fields is how this surfaced.

That led to #594: nine vi.mock paths across five test files resolve to nothing (../../stores/x from a __tests__ dir lands in src/components/stores/x). Vitest silently no-ops an unresolvable mock, so those suites have been running against the real modules and passing anyway. RestoreDialog.test.tsx mocks nothing it thinks it does. Filed rather than folded in here — fixing the paths will surface assertions that only passed by accident, and that deserves its own diff.

Verification

12 tests on the guard, 4 on the grid. 3 of the 4 fail against the ungated grid; the 4th is a guard (non-production must not ask) that correctly passes either way. Full suite green, 0 lint errors.

EVWorth and others added 2 commits September 9, 2026 17:53
… editor's

resultStore has held the production confirmation since #393, but only
statements routed through resultStore.executeQuery ever reached it. Grid
cell edits, the admin panel, import and restore all call api.executeQuery
directly, so editing a cell on a connection marked production wrote to it
with no confirmation at all (#588).

The reason they went direct is that the store's gate cannot be awaited: it
raises a dialog and returns, leaving the caller no way to learn whether the
user agreed. A caller with work to do afterwards — refresh the grid,
advance an import loop, close a dialog — could not use it. #393 fixed one
call site by restructuring it around that limitation rather than removing
the limitation.

confirmDestructive answers. It resolves true when there is nothing to ask
about, so a caller gates unconditionally without deciding for itself what
counts as dangerous, and false when the user declines, so the caller stops.
A second question while one is open declines the first rather than
stranding its promise.

Wired into the four bypassing paths. Batches ask once: prompting per
statement through a thousand-line dump would be held down rather than read.

The grid asks about every write, not only the destructive verbs.
isDestructiveStatement deliberately excludes UPDATE and INSERT because
typing one is the ordinary business of a SQL client — but nobody composes a
statement to edit a grid cell. A stray keystroke and a click on Save is the
whole gesture, so direct manipulation gets a lower bar.

isProductionConnection tolerates an absent connection list rather than
throwing. A read landing before connections have loaded is the same
situation as a connection that is not in the list, and both already answer
"not production"; throwing would abort the caller's save instead of gating
it. The grid's test mock omitted those fields, which is how this surfaced.

Closes #588

Co-Authored-By: Claude Opus 5 <[email protected]>
The unit test was updated for the production guard's dialog; its browser
counterpart was not, and it is the browser suite that CI runs. `npx vitest
run` uses the unit config, which excludes *.browser.test.tsx, so this
passed locally and failed in CI — my mistake for not running
`npm run test:browser` before pushing.

Also covers the guard dialog starting closed, which nothing asserted.

Co-Authored-By: Claude Opus 5 <[email protected]>
@EVWorth
EVWorth merged commit 5a62b87 into main Sep 10, 2026
10 checks passed
@EVWorth
EVWorth deleted the fix/production-gate-all-writes branch September 10, 2026 00:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[P1/bug] Grid edits and admin actions bypass the production confirmation

1 participant