fix(sql): dashboard/datasource CTE DML bypassed read-only gate - #33
Draft
cursor[bot] wants to merge 1 commit into
Draft
fix(sql): dashboard/datasource CTE DML bypassed read-only gate#33cursor[bot] wants to merge 1 commit into
cursor[bot] wants to merge 1 commit into
Conversation
pgQueryReadOnly/mysqlQueryReadOnly only used ForbiddenWrite, which misses
DELETE/INSERT/UPDATE after "(" inside WITH CTEs. Dashboard, datasource,
and SREyun SQL panels could therefore run mutating PostgreSQL statements
while the workbench StrictReadOnly* gate already blocked them. Align both
helpers with StrictReadOnlyPostgres/MySQL and lock it with regression tests.
Co-authored-by: Ethan <sreyun@users.noreply.github.com>
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.
Bug and impact
Dashboard / datasource / SREyun SQL panels (
pgQueryReadOnly/mysqlQueryReadOnly) accepted PostgreSQL data-modifying CTEs such asWITH x AS (DELETE FROM orders RETURNING *) SELECT * FROM x. That statement runs DELETE on the live datasource while returning rows — data loss through APIs advertised as read-only.Workbench
/sql/.../queryalready usedStrictReadOnly*; these panel helpers still usedForbiddenWrite, which only matches space-paddeddeleteand misses(delete.Root cause
ForbiddenWritetoken scan is space-delimited. CTE DML after(is still a validWITHfirst keyword forIsReadOnlyQuery, so the weak gate returned allow and the query was executed (optionally wrapped inSELECT * FROM (...) LIMIT n, which still runs the mutating CTE in PostgreSQL).Fix
StrictReadOnlyPostgres/StrictReadOnlyMySQL(same as workbench).cmd/servertests compile after license/classic-console removal.Validation
go test ./cmd/server/ -run 'TestPgQueryReadOnly|TestMysqlQueryReadOnly' -count=1— pass.