Skip to content

fix(mcp): confirm UPDATEs without WHERE that use inheritance syntax - #565

Merged
barryroodt merged 1 commit into
supabase:mainfrom
jargnar:fix/update-inheritance-confirm
Nov 24, 2026
Merged

barryroodt merged 1 commit into
supabase:mainfrom
jargnar:fix/update-inheritance-confirm

Conversation

@jargnar

@jargnar jargnar commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

What kind of change does this PR introduce?

Bug fix

What is the current behavior?

Fixes #564

This is the follow-up named in the review of #524. execute_sql and apply_migration ask for confirmation before an UPDATE without WHERE, but not when the table is written films* or ONLY (films). The update runs and changes every row.

Postgres spells the target of an UPDATE four ways (relation_expr in gram.y): t, t *, ONLY t and ONLY (t). updateWithoutWhereRegex matches only the first and the third, so the other two never reach the WHERE check.

What is the new behavior?

updateWithoutWhereRegex matches all four. Whitespace around * and the parentheses is optional, as it is in Postgres.

query before after
update public.films* set id = 2 runs asks
update films * as f set id = 2 runs asks
update only (films) set id = 2 runs asks
update only(public.films)f set id = 2 runs asks
explain analyze update films* set id = 2 runs asks
any of the above with where id = 1 runs runs

run_notebook already asks before any cell that isn't a plain read, and its prompt now counts these statements as destructive. No change to tool names, descriptions, or input and output schemas.

Not covered: the spellings under Additional context, which miss for other reasons. UPDATE ONLY t * ... isn't valid Postgres but now matches, so the server asks and Postgres then rejects the statement.

#426 plans a parser for this check, and the regex stays on as its fallback (#532), so the fix still applies once the parser lands.

How to Review

  1. UPDATE check

    • packages/mcp-server-supabase/src/tools/destructive-sql.ts
    • updateWithoutWhereRegex is now built from named parts, like directDropColumnRegex. updateIdentifier and updateTable are the old sub-patterns, unchanged. updateTarget is new: it adds \s*\*\s* after the table and the only\s*\(...\) alternative. The whitespace before the alias and before SET now sits after the target and after the alias, since * and ) need none.
  2. Tests

Review questions

Verification

With only the test file applied on main (9092ab9), the 9 new "matches" rows and both isDestructiveSql cases fail with expected false to be true, and the other 145 tests pass.

With the change:

  • pnpm --filter @supabase/mcp-server-supabase test:unit --run: 926 passed (34 files)
  • pnpm --filter @supabase/mcp-server-supabase test:integration --run: 7 passed
  • pnpm build (runs tsc --noEmit in each package), pnpm format:check, biome ci . and pnpm test:packed-platform-consumer: clean

Through the tools, with setupModern and a form-capable client that declines, the mocked Management API, and PGlite holding a table and a child table:

query, through execute_sql and apply_migration main this branch
update public.films* set title = 'x' not asked, 4 of 4 rows changed asked, none changed
update only (films) set title = 'x' not asked, 2 of 2 parent rows changed asked, none changed
either query with where id = 1 not asked, 1 row changed not asked, 1 row changed

I also compared the old and the new classifier on every SQL string in the test file, on 1,874,880 combinations of statement parts and on 2,000,000 random token sequences. No statement stopped asking, and each one that started asking is an UPDATE with one of the two targets. Those scripts aren't part of this PR.

Not run: the e2e project, which needs ANTHROPIC_API_KEY. I haven't tested against a hosted project or with a real MCP client.

Additional context

🤖 Generated with Claude Code

@flipslidersand flipslidersand left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I checked this out locally and ran the test file with CI=1 npx vitest run src/tools/destructive-sql.test.ts: 156/156 pass.

I had independently reproduced #564 and written a fix (#575), so I also ran my six spellings against this branch:

  • UPDATE films SET title = 1;
  • UPDATE public.films* SET title = 1;
  • UPDATE films * AS f SET title = 1;
  • UPDATE ONLY films SET title = 1;
  • UPDATE ONLY (films) SET title = 1;
  • UPDATE ONLY (public.films) f SET title = 1;

All six are flagged. This PR also covers the no-whitespace forms (films*SET, ONLY(public.films)SET), which mine does not, and it adds the WHERE negatives. I think this one should land, so I'm closing #575 as a duplicate.

One note for the maintainers: #557 and #562 change the same regex (where-suffixed column names), so whichever lands second will need a rebase.

@officialbidisha

Copy link
Copy Markdown
Contributor

Tested locally: the destructive-sql tests pass on this branch, and the 11 new cases fail on current main (efe189f), so they cover the bug. The branch merges cleanly into main. On Postgres (PGlite) with a child table inheriting films, UPDATE films* SET id = 2 updated 3 rows (parent and child) and UPDATE ONLY (films) SET id = 2 updated 2. These are now flagged, as are newlines inside ONLY ( … ), a comment before *, a 'where' string literal, RETURNING *, and a second statement after select 1;. The same statements with WHERE are not flagged. CTE-prefixed UPDATEs still aren't caught, but that's #563 (closed as not planned).

@jargnar

jargnar commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @flipslidersand for running your six spellings against it and for closing #575 in its favour, and @officialbidisha for testing the inheritance cases on PGlite. Noted on #557 and #562: if either lands first, I'll rebase this the same day.

@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.

Thanks for the thorough write-up, and for pulling in the inheritance cases from the #524 review!

@barryroodt
barryroodt merged commit 687b3ee into supabase:main Nov 24, 2026
3 of 5 checks passed
@supabase-releaser supabase-releaser Bot mentioned this pull request Nov 24, 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 UPDATEs without WHERE that use inheritance syntax (films*, ONLY (films))

4 participants