Skip to content

fix(mcp-server-supabase): fix word-boundary bug in UPDATE-without-WHERE detection - #562

Closed
livebitz1 wants to merge 1 commit into
supabase:mainfrom
livebitz1:fix/update-without-where-boundary-556
Closed

livebitz1 wants to merge 1 commit into
supabase:mainfrom
livebitz1:fix/update-without-where-boundary-556

Conversation

@livebitz1

Copy link
Copy Markdown

Summary

execute_sql's safety check for "UPDATE without a WHERE clause" used /where\s/i, which matches the bare substring "where" followed by whitespace — with no word boundary. This caused two opposite failures:

Query Before Should be
update films set elsewhere = 1 not asked (dangerous — unbounded update ran silently) asked
update films set nowhere = 1 not asked asked
update films set title = 'x' where(id = 1) asked unnecessarily not asked (has a real WHERE)

The dangerous case is the column-name one: a real UPDATE with no WHERE clause at all was allowed to run without confirmation, just because the column name happened to contain "where" as a substring.

Fix

Changed the regex to /\bwhere\b/i, which requires a word boundary on both sides of "where". This correctly:

  • excludes "elsewhere"/"nowhere"/"somewhere" (no boundary between the preceding letter and "w")
  • still matches where( (a parenthesis is a non-word character, so the boundary exists)

Text inside comments, string literals, and quoted identifiers is already masked out before this check runs (handled separately by splitStatements), so those cases are unaffected either way.

Verification

  • Added 4 new tests covering exactly the issue's reported cases (elsewhere, nowhere, somewhere columns, and where(id = 1)).
  • destructive-sql.test.ts: 147/147 pass (including the 4 new tests).
  • Full mcp-server-supabase unit suite: 917/917 pass — no regressions.
  • biome check — clean.

Fixes #556

🤖 Generated with Claude Code

…RE detection

isUpdateWithoutWhere used /where\s/i to detect a WHERE clause, which
matches the bare substring "where" followed by whitespace with no
word boundary. Two consequences:

- A column name ending in "where" (elsewhere, nowhere, somewhere)
  was mistaken for a real WHERE clause, so execute_sql ran an
  unbounded UPDATE without asking for confirmation.
- A WHERE immediately followed by a parenthesis, e.g.
  `where(id = 1)`, was not recognized as a WHERE clause, so
  execute_sql asked for confirmation unnecessarily.

Switched to /\bwhere\b/i, which requires a real word boundary on
both sides, fixing both cases while still correctly ignoring
WHERE text inside comments, string literals, and quoted identifiers
(already masked before this check runs).

Fixes supabase#556

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@barryroodt

Copy link
Copy Markdown
Contributor

Thanks for the fix! #557 covers the same word-boundary bug and was opened first, so I'm going with that one and closing this as a duplicate.

@barryroodt barryroodt closed this Nov 25, 2026
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 an UPDATE without WHERE when a column name ends in "where"

2 participants