fix: audit #23 — DDL asSelect routes through compile() (plugin-walk)#88
Merged
Conversation
HIGH (SECURITY) — CREATE TABLE AS SELECT / CREATE VIEW AS SELECT bypassed plugins entirely. When the Sumak.compile() router hit a DDL node it wired the DDL printer's inner-SELECT callback to the raw dialect printer (`base.print(sel)`). That path skipped every pipeline stage: plugin transformNode, hooks, normalize, optimize. A `CREATE VIEW tenant_orders AS SELECT * FROM orders` captured every tenant's rows into the view — MultiTenantPlugin had no chance to attach its tenant filter. Same for SoftDeletePlugin (deleted rows leaked into the materialized copy), AuditTimestampPlugin (stale views), OptimisticLockPlugin. Fix: wire the DDL printer's SELECT callback to `this.compile(sel)` instead of `base.print(sel)`, at all three call sites (compile(), generateDDL(), compileDDL()). The inner SELECT now goes through the full 7-stage pipeline just like a top-level query. Regression tests cover CTAS + CREATE VIEW with MultiTenant and SoftDelete plugins, plus a no-plugin baseline to confirm the no-op path still works. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Review of PR #88 noted the shared DDLPrinter across the generateDDL loop is inconsistent with the one-printer-per-statement contract used by compileDDL(). While print()'s internal params reset makes the shared instance safe for the current schema-only code path, future additions (asSelect on DDL, raw-SQL defaults accumulating params in printExpr) would have to remember the invariant. Move the printer allocation inside the loop to match compileDDL. No observable behavior change with current inputs. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.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.
Summary
HIGH (SECURITY) —
CREATE TABLE … AS SELECTandCREATE VIEW … AS SELECTbypassed every plugin.Sumak.compile()routed DDL nodes directly toDDLPrinter, wiring the DDL printer's inner-SELECT callback to the raw dialect printer (base.print(sel)). That path skipped every pipeline stage — plugintransformNode, hooks, normalize, optimize. ACREATE VIEW tenant_orders AS SELECT * FROM orderson a multi-tenant schema captured every tenant's rows into the view.MultiTenantPluginhad no chance to attach its tenant filter;SoftDeletePlugincouldn't mask deleted rows.Fix: wire the DDL printer's SELECT callback to
this.compile(sel)instead ofbase.print(sel)at all three call sites (compile(),generateDDL(),compileDDL()). The inner SELECT now goes through the full 7-stage pipeline.Test plan
pnpm fmt && pnpm lint && pnpm typecheckcleanpnpm test— 1239 pass (+4 new)CREATE TABLE orders_cache AS (SELECT * FROM orders WHERE ("tenant_id" = $1))with params[42]🤖 Generated with Claude Code