Read-only mode and the write-approval gate are bypassed by SELECT ... INTO
Description
WhoDB classifies SQL before applying the CLI read-only gate and the MCP --confirm-writes approval gate. Statements beginning with SELECT are treated as reads unless a token appears in sqlguard.mutatingKeywords. INTO, OUTFILE, and DUMPFILE are absent, so write-capable SELECT ... INTO forms are classified as non-mutating.
Confirmed examples include:
SELECT * INTO evil_copy FROM users
select id, email into stolen from accounts
SELECT * FROM users INTO OUTFILE '/tmp/dump.txt'
SELECT data FROM blobs INTO DUMPFILE '/tmp/x.bin'The first two forms create and populate a PostgreSQL table. The latter forms write files on the MySQL server.
Confirmed affected paths
Classification.Mutating controls all of these paths:
cli/internal/database/manager.go: CLI read-only mode checksIsMutationQuery, which delegates tosqlguard.Classify.cli/pkg/mcp/tools.go:--confirm-writesrequests approval only when!sqlguard.IsReadOnly(query).cli/pkg/mcp/validation.go: MCP read-only validation accepts statements for whichClassification.Mutatingis false.
The same classification reaches CE and EE because both editions use the shared CLI/MCP and source session execution layers.
Maintainer verification
The issue was reproduced end to end against the code shipped in 0.131.0. The 0.131.0 core/src/sqlguard/classify.go blob is identical to the tested checkout.
PostgreSQL:
- Standard
--confirm-writesdid not request confirmation andSELECT ... INTOcreated a table. - Strict
--confirm-writesalso did not request confirmation and created a table when the target name did not incidentally match a strict substring rule. - Current read-only mode rejected the statement with SQLSTATE 25006 and did not persist the table. This protection comes from the database-enforced read-only transaction added in 0.130.0; it does not correct the classifier or confirmation gate.
MySQL 8.4:
- Standard
--confirm-writesdid not request confirmation andSELECT ... INTO OUTFILEwrote a file. - Current read-only mode also wrote the file. MySQL permits this server-side file operation inside the transaction mode currently used by WhoDB.
- Strict mode blocked
INTO OUTFILEandINTO DUMPFILEthrough its existing dangerous-function substring list. Strict mode is not the default and does not block PostgreSQLSELECT ... INTO <table>.
Classifier-only tests also confirmed that all four submitted statements produce Mutating=false.
Impact
A model or local caller can execute these statements without the approval promised by --confirm-writes. On affected backends, read-only mode may also fail to prevent the write.
Impact is bounded by the connected database account and server configuration:
- PostgreSQL table creation requires
CREATEpermission in the target schema. - MySQL
INTO OUTFILEandINTO DUMPFILErequire theFILEprivilege.secure_file_priv, when configured, restricts the destination directory. Existing files cannot be overwritten.
The confirmed outcomes are unauthorized table creation within the connected PostgreSQL database and server-side file creation on MySQL. No broader host compromise was tested or established.
Affected versions
The original report identified >= 0.123.0 based on the introduction of core/src/sqlguard/classify.go. That range was too narrow: the same first-keyword decision existed before the shared classifier.
- The vulnerable MCP confirmation gate is present from 0.88.0.
- The vulnerable CLI read-only gate is present from 0.105.0.
- The shared
sqlguardimplementation is vulnerable from 0.123.0 through the current 0.131.0 release.
The combined affected range is therefore >= 0.88.0. No patched release exists yet.
Required remediation
A complete fix must:
- Classify write-capable output/creation clauses structurally, including PostgreSQL
SELECT ... INTO <table>, MySQLSELECT ... INTO OUTFILE/DUMPFILE, and equivalent leading forms such asTABLE ... INTO OUTFILE. - Use the corrected verdict consistently for read-only validation and write confirmation.
- Preserve database-enforced read-only execution as a second boundary, while recognizing that transaction read-only does not prevent every server-side side effect on every backend.
- Add backend-specific end-to-end tests through the actual CLI/MCP execution path.
Until a patched release is available, use a database account without schema-creation or MySQL FILE privileges. MySQL users should configure secure_file_priv. MCP users should not rely on standard --confirm-writes or read-only mode as the only boundary for untrusted SQL.
Disclosure
The reporter supplied a deterministic classifier reproduction and clearly noted that they had not performed live database writes. Maintainer testing subsequently confirmed the end-to-end PostgreSQL and MySQL behavior described above.