Repository navigation
fix(mcp): confirm UPDATEs without WHERE that have a leading comment, ONLY or an alias - #524
Merged
barryroodt merged 1 commit intoNov 9, 2026
Conversation
…ONLY or an alias isUpdateWithoutWhere tested each statement with the comment markers left by splitStatements still in front of it, so a leading comment hid the UPDATE. Its regex also expected the table name right before SET, which missed UPDATE ONLY t and UPDATE t [AS] x. Strip the markers the same way isDestructiveSql already does, and accept ONLY and an optional alias. Fixes supabase#523
barryroodt
approved these changes
Nov 9, 2026
barryroodt
left a comment
Contributor
There was a problem hiding this comment.
Thanks for this! I ran all three repros from #523 against main and this branch, and they all ask for confirmation now.
Just noting that inheritance syntax like update public.films* set ... (and update only (films) set ...) is still missed, but I'd like to keep this change small and file that as a follow-up.
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>
barryroodt
pushed a commit
that referenced
this pull request
Nov 24, 2026
…565) ## 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** - `packages/mcp-server-supabase/src/tools/destructive-sql.test.ts` - Nine new rows in the `isUpdateWithoutWhere` "matches" table, two in its "with WHERE does not match" table, and one `isDestructiveSql` test with the two statements from the review of #524. **Review questions** - [ ] Is a pattern built from named parts fine, or would you rather have a one-line edit of the literal, as in #524? The built pattern is 252 characters long. - [ ] Is it fine that `UPDATE ONLY t * ...` asks before Postgres rejects it? - [ ] Do you want the spellings under Additional context as a follow-up, or as test cases for #426? ## 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 - Spellings that run without asking on `main` and 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 after `SET` (`update "films"set ...`), a Unicode-escaped name (`update U&"films" set ...`), and `WITH ... UPDATE` or an `UPDATE` first in a `DO` body (under Trade-offs in #408). - Studio's `updateWithoutWhereRegex`, which this one was adapted from, has no `ONLY`, alias, `*` or parentheses. This PR doesn't change Studio. - #557 is open against the same function. The two changes don't overlap, and with both applied the file's 162 tests pass. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
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
What is the current behavior?
Fixes #523
isUpdateWithoutWherechecks each statement with the--or/* */marker left bysplitStatementsstill in front of it, so a leading comment hides theUPDATE. Its regex also expects the table name right beforeSET, soUPDATE ONLY tandUPDATE t [AS] xdo not match.What is the new behavior?
isUpdateWithoutWherestrips the comment markers before checking, the same wayisDestructiveSqlalready does forEXPLAIN. That existing one-liner is now a sharedstripCommentMarkershelper. The regex accepts an optionalONLYbefore the table name and an optional[AS] aliasafter it.-- reset idsupdate films set id = 2update only films set id = 2update films as f set id = 2where id = 1No change to tool names, descriptions, or input and output schemas.
How to Review
UPDATE check
packages/mcp-server-supabase/src/tools/destructive-sql.tsisUpdateWithoutWhereFromScannow runsstripCommentMarkerson each statement, andupdateWithoutWhereRegexhas theONLYand alias groups.Tests
packages/mcp-server-supabase/src/tools/destructive-sql.test.tsisUpdateWithoutWhererows for a leading--or/* */comment,ONLY,AS fand a bare alias, plus the same shapes withWHEREstaying unmatched. OneisDestructiveSqltest for the leading-comment case.Review questions
isUpdateWithoutWhereFromScanthe right place, or shouldsplitStatementsdrop them instead?Verification
main, the 7 new "matches" rows and the newisDestructiveSqltest fail, and every other test passes.CI=1 npx vitest run --project unit: 34 files, 878 passed.npx tsc --noEmitandpnpm format:check: clean.dist/cli.js --httpwith a form-capable client that declines:mainruns the comment,ONLYandASupdates without asking, and this branch asks for all three. The same update withwhere id = 1runs without asking on both.