Skip to content

fix(sql): dashboard/datasource CTE DML bypassed read-only gate - #33

Draft
cursor[bot] wants to merge 1 commit into
masterfrom
cursor/critical-bug-management-6cc0
Draft

fix(sql): dashboard/datasource CTE DML bypassed read-only gate#33
cursor[bot] wants to merge 1 commit into
masterfrom
cursor/critical-bug-management-6cc0

Conversation

@cursor

@cursor cursor Bot commented Sep 6, 2026

Copy link
Copy Markdown

Bug and impact

Dashboard / datasource / SREyun SQL panels (pgQueryReadOnly / mysqlQueryReadOnly) accepted PostgreSQL data-modifying CTEs such as WITH 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/.../query already used StrictReadOnly*; these panel helpers still used ForbiddenWrite, which only matches space-padded delete and misses (delete.

Root cause

ForbiddenWrite token scan is space-delimited. CTE DML after ( is still a valid WITH first keyword for IsReadOnlyQuery, so the weak gate returned allow and the query was executed (optionally wrapped in SELECT * FROM (...) LIMIT n, which still runs the mutating CTE in PostgreSQL).

Fix

  • Route both helpers through StrictReadOnlyPostgres / StrictReadOnlyMySQL (same as workbench).
  • Regression tests that assert CTE DELETE is rejected before dial, and that plain SELECT is not blocked by the gate.
  • Minimal test stubs so cmd/server tests compile after license/classic-console removal.

Validation

go test ./cmd/server/ -run 'TestPgQueryReadOnly|TestMysqlQueryReadOnly' -count=1 — pass.

Open in Web View Automation 

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>
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.

1 participant