fix: refuse EXPLAIN ANALYZE and INTO OUTFILE as writes - #12
Merged
Merged
Conversation
blaipr
force-pushed
the
fix/read-only-guard-bypass
branch
from
September 2, 2026 22:07
62512d2 to
4f6940c
Compare
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.
What this changes
isReadOnly()no longer judges a statement by its leading keyword alone.EXPLAIN ANALYZE ...(alsoDESC/DESCRIBE ANALYZE) andSELECT ... INTO OUTFILE/INTO DUMPFILEare now refused bydb_queryanddb:query, like any other write. PlainEXPLAINstays allowed.docs/safety.mdgains a "What counts as read-only" section anddocs/tools.mdnames the two exceptions.Why
Both start like a read and are not. MySQL 8 executes the statement under
EXPLAIN ANALYZEto time it, and accepts anUPDATEorDELETEthere, so rows changed while the output looked like a query plan — a write through the read-only tool with noCDMON_ALLOW_WRITES.INTO OUTFILEwrites a file on the database host. Both are refused by pattern rather than parsed around, so a string literal containingINTO OUTFILEis refused too; that is a false refusal, which is the cheap direction to be wrong in here. Tests were sabotage-checked against the previous implementation (2 fail, as expected).Checklist
npm testpassesnpm run typecheckpassesdocs/updated if behaviour changedCHANGELOG.mdupdated if the change is user-observable