Repository navigation
fix(mcp): don't read semicolons or EXECUTE inside data literals as destructive SQL - #533
Merged
barryroodt merged 2 commits intoNov 9, 2026
Conversation
…structive SQL Fixes supabase#531
barryroodt
approved these changes
Nov 9, 2026
barryroodt
left a comment
Contributor
There was a problem hiding this comment.
Thanks for this! I reran the #531 repros and the code-body cases, and they behave as you described. I really like that it's nicely contained too.
On create function ... as 'delete from t' with no semicolon: fine to leave. Creating the function doesn't run it.
The thing to remember is these confirmation prompts are simply serving as a guardrail, we're never going to catch every case with straight regex. The upcoming parser should increase coverage, but even there we're not guaranteed to catch everything.
I answered the dblink_exec/cron.schedule question inline.
Merged
barryroodt
pushed a commit
that referenced
this pull request
Nov 13, 2026
🤖 I have created a release *beep* *boop* --- <details><summary>mcp-utils: 0.10.0</summary> ## [0.10.0](mcp-utils-v0.9.0...mcp-utils-v0.10.0) (2026-11-13) ### Features * tag cost-confirmation errors and report caller-input errors as ToolCallerError ([#543](#543)) ([ac366c4](ac366c4)) </details> <details><summary>mcp-server-supabase: 0.17.0</summary> ## [0.17.0](mcp-server-supabase-v0.16.1...mcp-server-supabase-v0.17.0) (2026-11-13) ### ⚠ BREAKING CHANGES * **elicitation:** split confirmation and secret collection TTLs ([#538](#538)) ### Features * agent feedback capabilities including docs ([#488](#488)) ([698ccd5](698ccd5)) * **elicitation:** split confirmation and secret collection TTLs ([#538](#538)) ([8a08e48](8a08e48)) * tag cost-confirmation errors and report caller-input errors as ToolCallerError ([#543](#543)) ([ac366c4](ac366c4)) ### Bug Fixes * **content api:** report GraphQL errors that have no locations ([#528](#528)) ([6b2fca9](6b2fca9)) * **mcp:** confirm UPDATEs without WHERE that have a leading comment, ONLY or an alias ([#524](#524)) ([7df9fb8](7df9fb8)) * **mcp:** don't read semicolons or EXECUTE inside data literals as destructive SQL ([#533](#533)) ([0dcdd2d](0dcdd2d)) * tell agents the log window, project readiness, docs query and SQL size rules up front ([#542](#542)) ([23f0df0](23f0df0)) </details> --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). Co-authored-by: supabase-releaser[bot] <223506987+supabase-releaser[bot]@users.noreply.github.com>
Merged
4 tasks
barryroodt
pushed a commit
that referenced
this pull request
Nov 26, 2026
… a dollar-quoted value (#612) ## What kind of change does this PR introduce? Bug fix ## What is the current behavior? Fixes #611 `splitStatements()` keeps `--`, `/*`, and `*/` markers in `blanked` until callers strip them (#524), so `valueDollarQuoteStatement.test(blanked)` (`/^\s*(?:update\s|explain(?![\w$\u0080-\uffff]))/i`) fails whenever a comment precedes `UPDATE`/`EXPLAIN` or sits directly after `UPDATE` (`UPDATE/* reset */films`). Leaving dollar-quoted values unmasked causes `execute_sql`, `apply_migration`, and `run_notebook` (both confirmation and destructive label) to: - run comment-prefixed `UPDATE`s without `WHERE` unprompted when a dollar-quoted value contains `where`, and - prompt on comment-prefixed `UPDATE ... WHERE` and read-only `EXPLAIN` / `EXPLAIN ANALYZE` statements when a dollar-quoted value contains `;`. Calling `valueDollarQuoteStatement.test(blanked)` on every dollar-quoted span also repeatedly flattens V8's `+=` rope (`O(N²)` on statements with many `$$...$$` values). ## What is the new behavior? `splitStatements()` emits `' '` for `line-comment` and `block-comment` spans — matching `maskDataLiterals()` in `sql-data-literals.ts` and taking the alternative raised in #524's review question — and caches `valueStatement` per statement (resetting on every `;`). `stripCommentMarkers()` remains for unmasked dollar bodies and the unterminated fallback. | Query | `d670445` | This branch | | --- | --- | --- | | `/* reset */ UPDATE films SET bio = $$ where 1=1 $$;` | runs | asks | | `-- reset`<br>`UPDATE films SET bio = $$ where 1=1 $$;` | runs | asks | | `UPDATE/* reset */films SET bio = $$ where 1=1 $$;` | runs | asks | | `/* reset */ UPDATE films SET bio = $$a; b$$ WHERE id = 1;` | asks | runs | | `/* plan */ EXPLAIN SELECT $$ ; UPDATE films SET id = 2 $$;` | asks | runs | | `/* plan */ EXPLAIN (ANALYZE) UPDATE films SET bio = $$a; b$$ WHERE id = 1;` | asks | runs | No changes to tool names, descriptions, or schemas. Keeps the regex fallback minimal (#532) while #426 / #582 are in flight. ## How to Review 1. **Statement splitting** - `packages/mcp-server-supabase/src/tools/destructive-sql.ts` - `blanked += ' '` in `line-comment` and `block-comment` preserves token separation (`UPDATE/* reset */films`, `EXPLAIN /**/ ANALYZE`) without changing `block-comment` `;` splitting or unterminated-comment behavior. - `valueStatement` resets at every `blanked = ''` site; caching at the first dollar body is safe because `valueDollarQuoteStatement` checks only a short leading prefix already settled before any dollar quote (`sql-lexer.ts` never starts `$` after an identifier character). 2. **Tests** - `packages/mcp-server-supabase/src/tools/destructive-sql.test.ts` - Covers comment-prefixed and glued-comment `UPDATE`s (with/without `WHERE`), comment-prefixed `EXPLAIN` / `EXPLAIN (ANALYZE FALSE)` / `EXPLAIN ANALYZE`, an unterminated block comment, and a 40k-comment / 40k-dollar smoke test. **Review questions** - [ ] Is normalizing comments to `' '` inside `splitStatements()` (keeping `stripCommentMarkers()` for unmasked dollar bodies and the unterminated fallback) the right boundary? - [ ] Is caching `valueStatement` per statement worth including here? - [ ] Should a `;` inside a block comment (`UPDATE /* ; */ films SET id = 2;`) stop splitting statements in a follow-up, or stay fail-closed as documented? - [ ] Do the tests guard observable behavior without freezing internals? ## Verification - **RED on `d670445`:** 16 of 18 new functional assertions fail on `d670445` and pass here (2 controls pass on both). - **Suite & build:** `vitest run --project unit` (36 files, 1,048 passed; `destructive-sql.test.ts`: 183 passed), `pnpm build` (4 packages), `tsc --noEmit`, and `biome check` on both touched files — all clean. - **Large-input timings (`isDestructiveSql`, `d670445` → branch):** 40k comments (no-regression) `28.9 ms` → `25.1 ms` (80k: `44.7 ms` → `33.4 ms`); 40k dollar values `3,434.6 ms` → `22.4 ms`; 40k comments + 40k dollar values `34.3 ms`. - **Tool path (`execute_sql` and `apply_migration` via built `dist/index.js`, form-capable client declining, backed by PGlite):** the 3 comment + unfiltered `UPDATE` + `$$ where 1=1 $$` queries ask and leave both `films` rows untouched (`exec=0`); the 3 safe `UPDATE ... WHERE` / `EXPLAIN` queries run unprompted (`exec=1`) and mutate 1 row or 0 rows as expected. - **Not run:** `test:e2e` (needs `ANTHROPIC_API_KEY`) and live hosted project. ## Additional context Known remaining cases, not changed here: - `UPDATE /* ; */ films SET id = 2;` — block-comment `;` still splits statements as documented (`runs` on both `d670445` and this branch). - `DO $$ BEGIN PERFORM 1; /* c */ UPDATE films SET id = 2; END $$;` — `stripCommentMarkers()` leaves comment text inside unmasked dollar bodies (`runs` on both). - `INSERT INTO notes (body) VALUES ($b$Kept the deck; update notes set body = null$b$);` — known false positive (`UPDATE`-path counterpart of #533). - `CREATE FUNCTION /*;*/ update (x int) RETURNS void AS $$ SELECT 1; UPDATE t SET a = 1; $$ LANGUAGE sql;` — now masks its body (`asks` → `runs`; defining a function does not run it, per #533).
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.
What kind of change does this PR introduce?
Bug fix. Fixes #531.
What is the current behavior?
Thanks so much @zmcray for the really careful write up in #531, and to everyone in the #457 thread. The point raised there about
DO '...'bodies shaped this whole change.Right now
execute_sqlasks for a destructive confirmation when a plain INSERT, UPDATE or SELECT only has; drop,; deleteor; truncateinside a text value, or has the wordExecuteinside a value:insert into notes (body) values ('Moved the list to 11/3; drop the two duplicates').checkDestructiveQueryFromScanremoves comments but keeps every literal as is, then runscleanedSql.split(';').drop the two duplicates'), which matches/^\s*(drop|delete|truncate)\s/i.isDestructiveSqlreturnstrue, the client gets a confirmation nobody answers, and in an unattended run the write is lost after the timeout.The same thing happens with
$b$...$b$values, UPDATE values,select 'a; truncate b', andvalues ('Execute the plan', '{"proposed": "drop"}')(theexecute\s+check matched inside the first value).What is the new behavior?
Before the existing checks run, a new
maskDataLiteralsreplaces each string, E string or dollar quoted literal with'', unless that literal is code. A literal stays as is when:DO(sodo 'begin perform 1; drop table t; end'is still flagged, like today),EXECUTEappears earlier in the same statement, outside any literal (soEXECUTE 'DROP TABLE films'and theformat/concatcases work exactly as today),AS, which is where function and procedure bodies go (main flagscreate function ... as 'begin; delete from t; end'today, so I kept that),Everything after that point (the
;split, the ALTER TABLE check, the EXECUTE checks) is unchanged and just reads the masked text. Comments now become a space instead of disappearing, sodelete/**/from tis caught too (main read it asdeletefrom).flowchart TD A[SQL text] --> B[lexSql spans] B --> C{literal?} C -- no --> E[keep text] C -- yes --> D{"DO statement, EXECUTE earlier,<br/>right after AS, or unterminated?"} D -- yes --> E D -- no --> F["replace with ''"] E --> G[existing checks: split on ;, ALTER, EXECUTE] F --> GTo make sure nothing real got lost, I ran 341 statements through
isDestructiveSqlon main and on this branch: every string fromdestructive-sql.test.ts, plusdrop,delete,truncateandalter table ... dropwrapped in DO bodies (quoted, E quoted, dollar quoted, with and without LANGUAGE), EXECUTE strings, function and procedure bodies, comments, unterminated input and data literals. Nothing that main flags in code stopped being flagged. The only changes were 37 statements where the destructive words sat inside a data value.I know @barryroodt has #426 open to parse SQL properly before confirming, which is the real long term answer here. This is meant as a small interim fix on the current scanner, and I'm very happy to close it if #426 is close to landing.
How to Review
Masking
packages/mcp-server-supabase/src/tools/sql-data-literals.ts''.Call site
packages/mcp-server-supabase/src/tools/destructive-sql.tscheckDestructiveQueryFromScanreads the masked text instead of the comment free text; nothing else moved.Tests
packages/mcp-server-supabase/src/tools/destructive-sql.test.tsReview questions
Verification
pnpm --filter @supabase/mcp-server-supabase typecheck: cleanpnpm --filter @supabase/mcp-server-supabase test:unit --run: 891 passedpnpm format:check: cleanAdditional context
A couple of things I wasn't sure about and would love your take on:
AS '...'are still read as code, matching main. But main only flags them when a;comes before the destructive word, socreate function f() returns void as 'delete from t' language sqlisn't flagged on main or here. Should those bodies be rechecked as their own statements, or is creating a function (which doesn't run it yet) fine to leave alone?dblink_exec('...')orcron.schedule(..., '...'), are now treated as data. Main only caught them by accident when the text had a;before the keyword. Is that okay for now, or would you rather keep a short list of those functions as code?