Skip to content

fix(guard): reject data-modifying CTEs in SqlGuard - #49

Merged
stbischof merged 1 commit into
eclipse-daanse:mainfrom
stbischof:wip/sqlquery-querymap
Aug 25, 2026
Merged

stbischof merged 1 commit into
eclipse-daanse:mainfrom
stbischof:wip/sqlquery-querymap

Conversation

@stbischof

Copy link
Copy Markdown
Contributor

A statement like WITH x AS (UPDATE foo ...) SELECT ... parses as a Select and passed every gate, because the resolver never populates its update/insert column lists for DML wrapped in a WITH item. The guard then returned the write statement as approved SQL.

Add ReadOnlyStatementValidator, which walks the parsed Select tree (reusing TablesNamesFinder's recursion) and rejects any WITH item that wraps an UPDATE/INSERT/DELETE instead of a SELECT. Run it before resolve(), which also stops the INSERT-in-CTE ClassCastException leak.

A statement like `WITH x AS (UPDATE foo ...) SELECT ...` parses as a
Select and passed every gate, because the resolver never populates its
update/insert column lists for DML wrapped in a WITH item. The guard
then returned the write statement as approved SQL.

Add ReadOnlyStatementValidator, which walks the parsed Select tree
(reusing TablesNamesFinder's recursion) and rejects any WITH item that
wraps an UPDATE/INSERT/DELETE instead of a SELECT. Run it before
resolve(), which also stops the INSERT-in-CTE ClassCastException leak.

Signed-off-by: Stefan Bischof <stbischof@bipolis.org>
@stbischof
stbischof merged commit a95b818 into eclipse-daanse:main Aug 25, 2026
6 of 8 checks passed
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