Repository navigation
fix(mcp): confirm UPDATEs without WHERE that follow a comment and set a dollar-quoted value - #612
Merged
barryroodt merged 1 commit intoNov 26, 2026
Conversation
… a dollar-quoted value
barryroodt
approved these changes
Nov 26, 2026
barryroodt
left a comment
Contributor
There was a problem hiding this comment.
Happy to approve this, @Dodhon. Thanks for the careful fix to a gap in the confirmation check. I fuzzed the branch against main with about 600k generated statements, and each case without a ; inside a block comment gave the same verdict as main with the comments removed.
splitStatements() is the right place to replace comments with a space, and I'd keep the per-statement cache here. Semicolons inside block comments are worth a follow-up so the splitter treats the whole comment as a space too.
Merged
barryroodt
pushed a commit
that referenced
this pull request
Nov 26, 2026
🤖 I have created a release *beep* *boop* --- <details><summary>mcp-utils: 0.11.1</summary> ## [0.11.1](mcp-utils-v0.11.0...mcp-utils-v0.11.1) (2026-11-26) ### Bug Fixes * **mcp-ui:** shared project card for create-project and create-branch ([#578](#578)) ([efe189f](efe189f)) </details> <details><summary>mcp-server-supabase: 0.20.0</summary> ## [0.20.0](mcp-server-supabase-v0.19.0...mcp-server-supabase-v0.20.0) (2026-11-26) ### Features * **debugging:** add project issues DEBUG-311 ([#546](#546)) ([01f8021](01f8021)) * **mcp-server-supabase:** add optional schemas parameter to generate_typescript_types ([#592](#592)) ([7532f53](7532f53)) ### Bug Fixes * **debugging:** link docs once per issue in get_issues ([#610](#610)) ([74801d8](74801d8)) * **mcp-server-supabase:** detect import maps uploaded with a ./ prefix ([#591](#591)) ([6b8f4dc](6b8f4dc)) * **mcp-server-supabase:** keep a declined or cancelled SQL confirmation final ([#581](#581)) ([03afe8e](03afe8e)) * **mcp-server-supabase:** match Studio's notebook row_limit and clarify skip and blank-input messages ([#593](#593)) ([ad07f1b](ad07f1b)) * **mcp-server-supabase:** skip cost confirmation for $0 projects on clients without forms ([#608](#608)) ([50cfc37](50cfc37)) * **mcp-server-supabase:** stop reusing a removed import map on edge function redeploy ([#588](#588)) ([56093a6](56093a6)) * **mcp-ui:** shared project card for create-project and create-branch ([#578](#578)) ([efe189f](efe189f)) * **mcp:** confirm UPDATEs without WHERE that follow a comment and set a dollar-quoted value ([#612](#612)) ([468907a](468907a)) * **mcp:** confirm UPDATEs without WHERE that use inheritance syntax ([#565](#565)) ([687b3ee](687b3ee)) * **mcp:** confirm UPDATEs without WHERE when a column name ends in where ([#557](#557)) ([57fa34b](57fa34b)) </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>
1 task
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
What is the current behavior?
Fixes #611
splitStatements()keeps--,/*, and*/markers inblankeduntil callers strip them (#524), sovalueDollarQuoteStatement.test(blanked)(/^\s*(?:update\s|explain(?![\w$\u0080-\uffff]))/i) fails whenever a comment precedesUPDATE/EXPLAINor sits directly afterUPDATE(UPDATE/* reset */films). Leaving dollar-quoted values unmasked causesexecute_sql,apply_migration, andrun_notebook(both confirmation and destructive label) to:UPDATEs withoutWHEREunprompted when a dollar-quoted value containswhere, andUPDATE ... WHEREand read-onlyEXPLAIN/EXPLAIN ANALYZEstatements 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' 'forline-commentandblock-commentspans — matchingmaskDataLiterals()insql-data-literals.tsand taking the alternative raised in #524's review question — and cachesvalueStatementper statement (resetting on every;).stripCommentMarkers()remains for unmasked dollar bodies and the unterminated fallback.d670445/* reset */ UPDATE films SET bio = $$ where 1=1 $$;-- resetUPDATE films SET bio = $$ where 1=1 $$;UPDATE/* reset */films SET bio = $$ where 1=1 $$;/* reset */ UPDATE films SET bio = $$a; b$$ WHERE id = 1;/* plan */ EXPLAIN SELECT $$ ; UPDATE films SET id = 2 $$;/* plan */ EXPLAIN (ANALYZE) UPDATE films SET bio = $$a; b$$ WHERE id = 1;No changes to tool names, descriptions, or schemas. Keeps the regex fallback minimal (#532) while #426 / #582 are in flight.
How to Review
Statement splitting
packages/mcp-server-supabase/src/tools/destructive-sql.tsblanked += ' 'inline-commentandblock-commentpreserves token separation (UPDATE/* reset */films,EXPLAIN /**/ ANALYZE) without changingblock-comment;splitting or unterminated-comment behavior.valueStatementresets at everyblanked = ''site; caching at the first dollar body is safe becausevalueDollarQuoteStatementchecks only a short leading prefix already settled before any dollar quote (sql-lexer.tsnever starts$after an identifier character).Tests
packages/mcp-server-supabase/src/tools/destructive-sql.test.tsUPDATEs (with/withoutWHERE), comment-prefixedEXPLAIN/EXPLAIN (ANALYZE FALSE)/EXPLAIN ANALYZE, an unterminated block comment, and a 40k-comment / 40k-dollar smoke test.Review questions
' 'insidesplitStatements()(keepingstripCommentMarkers()for unmasked dollar bodies and the unterminated fallback) the right boundary?valueStatementper statement worth including here?;inside a block comment (UPDATE /* ; */ films SET id = 2;) stop splitting statements in a follow-up, or stay fail-closed as documented?Verification
d670445: 16 of 18 new functional assertions fail ond670445and pass here (2 controls pass on both).vitest run --project unit(36 files, 1,048 passed;destructive-sql.test.ts: 183 passed),pnpm build(4 packages),tsc --noEmit, andbiome checkon both touched files — all clean.isDestructiveSql,d670445→ branch): 40k comments (no-regression)28.9 ms→25.1 ms(80k:44.7 ms→33.4 ms); 40k dollar values3,434.6 ms→22.4 ms; 40k comments + 40k dollar values34.3 ms.execute_sqlandapply_migrationvia builtdist/index.js, form-capable client declining, backed by PGlite): the 3 comment + unfilteredUPDATE+$$ where 1=1 $$queries ask and leave bothfilmsrows untouched (exec=0); the 3 safeUPDATE ... WHERE/EXPLAINqueries run unprompted (exec=1) and mutate 1 row or 0 rows as expected.test:e2e(needsANTHROPIC_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 (runson bothd670445and this branch).DO $$ BEGIN PERFORM 1; /* c */ UPDATE films SET id = 2; END $$;—stripCommentMarkers()leaves comment text inside unmasked dollar bodies (runson both).INSERT INTO notes (body) VALUES ($b$Kept the deck; update notes set body = null$b$);— known false positive (UPDATE-path counterpart of fix(mcp): don't read semicolons or EXECUTE inside data literals as destructive SQL #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 fix(mcp): don't read semicolons or EXECUTE inside data literals as destructive SQL #533).