Repository navigation
fix(admin): enforce read-only connections, and stop the app killing itself - #522
Merged
Merged
Conversation
…tself Two security holes in the admin area, both of the same shape: a protection that existed on paper and nowhere in the execution path. read_only was stored on the profile, carried onto the live connection, and checked in exactly one place — EXPLAIN ANALYZE. Every other path ignored it. A read-only production profile would still run DROP TABLE from the editor, create accounts from the admin panel, or grant SUPER to itself. The executor now refuses any statement that could change data, schema, privileges or server state, before the batch is assembled, so a script containing a write is rejected whole rather than half-run. Classifying by leading keyword would have left two ways through, both covered: `WITH doomed AS (...) DELETE` is a DELETE, and `EXPLAIN ANALYZE <write>` executes the write it measures — so run through the ordinary Run button, its leading EXPLAIN would have looked harmless. Plain EXPLAIN stays allowed whatever it plans, since it only plans. The verb list is an allowlist: an unrecognised statement is treated as a write and refused. kill_process had no notion of which sessions belonged to SQLPilot, and PROCESSLIST includes the connections the panel is using to read PROCESSLIST. Killing one worked; killing the last exhausted the pool and surfaced "pool timed out", which never told the user they had disconnected themselves. The pool now records each server thread it opens, kill_process refuses those, and the UI disables the button with a tooltip explaining why rather than letting the click fail. Other users' sessions stay killable. ERROR 1095 is translated into a message naming the privilege that is missing, since PROCESSLIST is visible to users who cannot act on it. Writes now carry the account they ran as in the log line, which is the audit trail #429 asks for. Two parts of #429 are deliberately not done. Parameterised SQL is not available for DDL — MySQL takes no placeholders for identifiers or privilege names, so correct quoting is the remedy, and that landed in #521. Wrapping GRANT/REVOKE in a transaction is impossible: they force an implicit commit, verified by a GRANT surviving ROLLBACK. That is recorded on #439. Refs #429, #433
This was referenced Aug 29, 2026
EVWorth
added a commit
that referenced
this pull request
Aug 29, 2026
…ord (#526) The frontend never receives credentials, so on edit it sends them back absent, and the command layer fills them in from the store. It did that with `if let Ok(stored)`, which treats every failure the same way: a keyring that is locked, sandboxed or momentarily unavailable looked exactly like "this profile has no stored password". The field stayed empty, and `save()` reads an empty password as "the user cleared it" and calls `delete_password`. The user edits a profile name, sees a success toast, and the credential is gone. `ConnectionStore::get_existing` now returns `Option`, so the two outcomes have different types and the call site has to decide. A profile that does not exist is `None` — a new profile, where empty really is the intent. Anything else is an error, and the save is refused with a message saying that nothing was written and the stored password is untouched. `test_connection` had the same pattern, where the cost was a false "Access denied" sending the user off to debug credentials that were fine. Also completes #277. Enforcement landed in #522; the other half of that issue is a connection marked read-only being indistinguishable from any other until the executor refuses something. Read-only connections now carry a lock in their tab. Two things found while testing: The mock specifiers in ConnectionTabs.test.tsx resolve relative to the test file, not the component, so `../../stores/connectionStore` pointed at `src/components/stores/…`, which does not exist. None of that file's mocks were ever applied — the tests ran against the real stores and asserted only things that held either way. Fixed, which is what let the new tests render a tab at all. Three ConnectionStore tests were swept up by the blanket #[ignore] in #516. They touch only the store and an in-memory keyring, so they are back on the ordinary test path where they belong; CI has no database services, so a green Test Rust job is the proof they need none. Refs #274, #277
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refs #429, #433.
Two holes of the same shape: a protection that existed on paper and nowhere in the execution path.
read-only was enforced in exactly one place
read_onlyis stored on the profile, carried onto the live connection (since #512) — and checked only by EXPLAIN ANALYZE. Every other path ignored it. A read-only production profile would still runDROP TABLEfrom the editor, create accounts from the admin panel, or grant itselfSUPER.The executor now refuses any statement that could change data, schema, privileges or server state, before the batch is assembled, so a script whose second statement writes is rejected whole rather than half-run.
Classifying by leading keyword would have left two ways through, both covered:
WITH doomed AS (...) DELETE FROM tis a DELETE (resolved via theeffective_verbhelper from fix(explain): stop EXPLAIN ANALYZE running writes, and make timeouts real #512)EXPLAIN ANALYZE <write>executes the write it measures — run through the ordinary Run button, that leadingEXPLAINlooks harmlessPlain
EXPLAINstays allowed whatever it plans, because it only plans. The verb list is an allowlist, so an unrecognised statement is treated as a write and refused rather than waved through.The app could disconnect itself
PROCESSLISTincludes the sessions SQLPilot is using to readPROCESSLIST. Killing one worked; killing the last exhausted the pool and surfacedpool timed out, which never told the user what they had just done.The pool now records each server thread it opens (in
after_connect),kill_processrefuses those, and the UI disables the button with an explanatory tooltip rather than letting the click fail. Other users' sessions stay killable.ERROR 1095is translated into a message naming the missing privilege, sincePROCESSLISTis visible to users who cannot act on it.Writes now carry the account they ran as in the log line — the audit trail #429 asks for.
Two parts of #429 deliberately not done
GRANTsurvivingROLLBACK. Recorded on [P1] [bug] applyChanges runs statements as separate awaits — partial failure corrupts DB #439, which proposed exactly that fix.Verification
65 integration tests against MySQL 8 + MariaDB 11, including:
WITH ... SELECTEXPLAIN ANALYZE DELETEkill_processrefuses every thread the pool owns, and the connection still works after the refusalPlus 1635 frontend tests, including the disabled-button guard. clippy/tsc/dprint clean.
🤖 Generated with Claude Code