Skip to content

Keep SQL deep scan on for custom read-only allowed_types - #76688

Merged
kaxil merged 2 commits into
apache:mainfrom
ColtenOuO:fix-sql-validation-narrowed-allowed-types
Nov 8, 2026
Merged

kaxil merged 2 commits into
apache:mainfrom
ColtenOuO:fix-sql-validation-narrowed-allowed-types

Conversation

@ColtenOuO

Copy link
Copy Markdown
Contributor

validate_sql() skipped the data-modifying deep scan whenever allowed_types was not exactly DEFAULT_ALLOWED_TYPES. So a stricter list like (exp.Select,), a reordered default, or the default plus exp.Describe let these through:

WITH d AS (DELETE FROM users RETURNING *) SELECT * FROM d
SELECT * INTO new_table FROM users

Now the deep scan is skipped only when the allow-list itself contains a data-modifying type (e.g. exp.Insert). Added tests cover the narrower, reordered and widened read-only lists.


Was generative AI tooling used to co-author this PR?
  • Yes — Claude Code (Opus 5.5)

validate_sql() skipped the data-modifying deep scan whenever allowed_types
was not exactly DEFAULT_ALLOWED_TYPES. A narrower or reordered read-only
list such as (exp.Select,) therefore let statements like
"WITH d AS (DELETE ...) SELECT ..." or "SELECT ... INTO ..." through.

Skip the deep scan only when the allow-list itself admits a data-modifying
type.
An allow-list such as (exp.Select, exp.DML) admits an INSERT at the type
check, but the one-way issubclass test left the deep scan on and rejected
the same INSERT as read-only. Treat an allowed type that is a write node or
a base of one as admitting writes. Scanning only the write types the list
does not admit is not an option: MERGE nests Insert and Update, and ALTER
... DROP COLUMN nests Drop, so it would reject writes the list allows.

Also update the denylist comment and stability.rst to the new rule.
@kaxil
kaxil enabled auto-merge (squash) November 8, 2026 01:58
@kaxil
kaxil merged commit 72502d6 into apache:main Nov 8, 2026
80 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants