Repository navigation
fix(mcp): confirm UPDATEs without WHERE that use inheritance syntax - #565
Conversation
flipslidersand
left a comment
There was a problem hiding this comment.
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.
|
Tested locally: the |
|
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
left a comment
There was a problem hiding this comment.
Thanks for the thorough write-up, and for pulling in the inheritance cases from the #524 review!
🤖 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>
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_sqlandapply_migrationask for confirmation before anUPDATEwithoutWHERE, but not when the table is writtenfilms*orONLY (films). The update runs and changes every row.Postgres spells the target of an
UPDATEfour ways (relation_expringram.y):t,t *,ONLY tandONLY (t).updateWithoutWhereRegexmatches only the first and the third, so the other two never reach theWHEREcheck.What is the new behavior?
updateWithoutWhereRegexmatches all four. Whitespace around*and the parentheses is optional, as it is in Postgres.update public.films* set id = 2update films * as f set id = 2update only (films) set id = 2update only(public.films)f set id = 2explain analyze update films* set id = 2where id = 1run_notebookalready 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
UPDATE check
packages/mcp-server-supabase/src/tools/destructive-sql.tsupdateWithoutWhereRegexis now built from named parts, likedirectDropColumnRegex.updateIdentifierandupdateTableare the old sub-patterns, unchanged.updateTargetis new: it adds\s*\*\s*after the table and theonly\s*\(...\)alternative. The whitespace before the alias and beforeSETnow sits after the target and after the alias, since*and)need none.Tests
packages/mcp-server-supabase/src/tools/destructive-sql.test.tsisUpdateWithoutWhere"matches" table, two in its "with WHERE does not match" table, and oneisDestructiveSqltest with the two statements from the review of fix(mcp): confirm UPDATEs without WHERE that have a leading comment, ONLY or an alias #524.Review questions
UPDATE ONLY t * ...asks before Postgres rejects it?Verification
With only the test file applied on
main(9092ab9), the 9 new "matches" rows and bothisDestructiveSqlcases fail withexpected 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 passedpnpm build(runstsc --noEmitin each package),pnpm format:check,biome ci .andpnpm test:packed-platform-consumer: cleanThrough the tools, with
setupModernand a form-capable client that declines, the mocked Management API, and PGlite holding a table and a child table:execute_sqlandapply_migrationmainupdate public.films* set title = 'x'update only (films) set title = 'x'where id = 1I 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
UPDATEwith 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
mainand still do after this change: an unquoted name with a character outside[A-Za-z0-9_](update café set ...,update films$x set ...), whitespace around the dot or a three-part name, no whitespace next to a quoted name or afterSET(update "films"set ...), a Unicode-escaped name (update U&"films" set ...), andWITH ... UPDATEor anUPDATEfirst in aDObody (under Trade-offs in feat(mcp)!: confirm destructive SQL via elicitation and rename costConfirmation option #408).updateWithoutWhereRegex, which this one was adapted from, has noONLY, alias,*or parentheses. This PR doesn't change Studio.🤖 Generated with Claude Code