Skip to content

fix(mcp): confirm UPDATEs without WHERE that follow a comment and set a dollar-quoted value - #612

Merged
barryroodt merged 1 commit into
supabase:mainfrom
Dodhon:fix/comment-prefixed-dollar-quote-masking
Nov 26, 2026
Merged

barryroodt merged 1 commit into
supabase:mainfrom
Dodhon:fix/comment-prefixed-dollar-quote-masking

Conversation

@Dodhon

@Dodhon Dodhon commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

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 UPDATEs 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
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 UPDATEs (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:

@Dodhon
Dodhon requested a review from a team as a code owner November 26, 2026 02:00

@barryroodt barryroodt left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@barryroodt
barryroodt merged commit 468907a into supabase:main Nov 26, 2026
5 of 7 checks passed
@supabase-releaser supabase-releaser Bot mentioned this pull request Nov 26, 2026
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>
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.

execute_sql does not ask for confirmation for comment-prefixed UPDATEs with dollar-quoted "where"

2 participants