Repository navigation
Conversation
…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]>
3 tasks
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. |
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.
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:update films set elsewhere = 1update films set nowhere = 1update films set title = 'x' where(id = 1)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: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
elsewhere,nowhere,somewherecolumns, andwhere(id = 1)).destructive-sql.test.ts: 147/147 pass (including the 4 new tests).mcp-server-supabaseunit suite: 917/917 pass — no regressions.biome check— clean.Fixes #556
🤖 Generated with Claude Code