Skip to content

Destructive-SQL check splits on semicolons inside string literals, so safe UPDATEs with a ";" in a value trigger a confirmation (and hang in clients that cannot answer it) #457

Closed

Description

@ArseniosEfrem

What happens

Since the destructive-SQL confirmation was added, execute_sql asks the client to confirm some statements that are not destructive. Any UPDATE ... WHERE ... whose string value contains a semicolon is flagged as an "UPDATE without WHERE", and any string value containing ; delete, ; drop or ; truncate is flagged as a destructive statement. In a client that receives the confirmation request but never answers it, the call waits until the tool timeout (about 180 s for us) and then fails.

Why (packages/mcp-server-supabase/src/tools/destructive-sql.ts, at 4602ee9)

  • isUpdateWithoutWhere does sql.split(';') BEFORE stripQuotedSpans runs. A semicolon inside a quoted value cuts the statement in two. The first fragment starts with update, matches updateWithoutWhereRegex, and has no where (the WHERE is in the second fragment), so the function returns true.
  • checkDestructiveQuery does cleanedSql.split(';') and then tests each fragment with /^\s*(drop|delete|truncate)\s/i, so a value such as 'done; delete later' produces a fragment that starts with delete.

Minimal reproduction (no table needed: call the exported functions directly)

import { isUpdateWithoutWhere, isDestructiveSql } from './destructive-sql';

isUpdateWithoutWhere(`update t set note = 'a; b' where id = 1`);
// expected false, actual true

isDestructiveSql(`update t set note = 'done; delete later' where id = 1`);
// expected false, actual true

isUpdateWithoutWhere(`update t set note = 'a, b' where id = 1`);
// false (correct: no semicolon, no problem)

isUpdateWithoutWhere(`update t set a = 1`);
// true (correct: a real UPDATE without WHERE must stay flagged)

Run in Node 24 against destructive-sql.ts at 4602ee9: the four calls print true, true, false, true.

What we saw through the hosted server: appends of the form update some_table set note = note || '... x; y ...' where id = ... waited for a confirmation every time, while the same append with commas instead of semicolons, and plain state updates, returned at once. The functions above explain that difference.

Suggested fix

Split statements with a quote-aware scan that ignores semicolons inside single-quoted strings (with '' escapes), double-quoted identifiers, dollar-quoted bodies ($$...$$, $tag$...$tag$) and comments. Or strip those spans (as stripQuotedSpans already does, extended to dollar quotes) BEFORE splitting, in both isUpdateWithoutWhere and checkDestructiveQuery. Suggested tests: the four calls above; a value containing '; drop table x; '; a dollar-quoted function body containing delete; and a real update t set a = 1 with no WHERE, which must still be flagged.

Workaround we use meanwhile

Keep semicolons out of the SQL text, for example by sending the value as hex (convert_from(decode('...', 'hex'), 'UTF8')). We have deliberately NOT turned the confirmation off, because it protects every other statement.

Environment

Hosted Supabase MCP server. Seen in a client that supports MCP elicitation (the confirmation form) but cannot answer it inside the session; a client without elicitation is not affected.

Activity

  1. kelliepatry commented on Oct 10, 2026

    @kelliepatry

    Reproduced the quoted-semicolon UPDATE warning against @supabase/mcp-server-supabase 0.13.0 at main commit 8a2650891e2fa6e5e895075663ba4f35867083d6.

    UPDATE films SET title = 'review; no adoption' WHERE id = 1;

    Both isUpdateWithoutWhere and isDestructiveSql return true on that baseline. This also affects scoped JSON evidence appends whose note strings contain semicolons. No reproduction SQL was executed against a database.

    I found the existing fix in #459 and checked its head 00f3e9aeb753c2c9e6f927ba34f73a6c92df9ca6 locally with Node v24.19.0. These seven direct isUpdateWithoutWhere checks all produced the expected result:

    const cases = [
      ["UPDATE films SET title = 'review; no adoption' WHERE id = 1;", false],
      ['UPDATE films SET title = null;', true],
      ['UPDATE "where; table" SET id = 1;', true],
      [String.raw`UPDATE t SET note = E'it\'s done; see where it failed'`, true],
      ['UPDATE t SET a = 1 -- todo; add a where clause later', true],
      ['DO $$ BEGIN PERFORM 1; UPDATE films SET title = null; END $$;', true],
      ["SELECT $$it's$$; UPDATE films SET title = null; SELECT 'a WHERE b';", true],
    ];
    for (const [sql, expected] of cases) {
      const actual = isUpdateWithoutWhere(sql);
      if (actual !== expected) throw new Error(JSON.stringify({sql, expected, actual}));
    }

    The baseline returns true for the bounded first case and false for the quoted-target third case; #459's current head corrects both. Its procedural-body case stays flagged.

    An alternative local candidate that masked entire dollar-quoted spans passed 46 existing and 33 added helper cases, but failed the procedural-body check above by returning false. That candidate is withdrawn and is not proposed for deployment. The existing #459 approach preserves that warning. Sharing this evidence on the existing issue rather than opening a competing PR.

    Verification was local classifier execution after TypeScript type erasure with Node's stripTypeScriptTypes; it was not a full Vitest/package CI, build/lint or hosted integration run. The separate checkDestructiveQuery quoted-DROP/DELETE/TRUNCATE issue remains outside these checks. No confirmation control was disabled. AI-assisted by GPT/Codex; maintainer/human review is still needed before merge and deployment.

  2. Bruce-k901 commented on Oct 10, 2026

    @Bruce-k901

    Adding a data point from a different client. In the Claude Code VS Code extension (2.1.292, Windows), which runs in non-interactive mode, the confirmation is not left waiting: it is declined immediately, and execute_sql returns only {"status":"declined"}. Nothing in that result says a confirmation was requested or why, so to the agent it looks like an arbitrary refusal. We only found the cause in the extension's debug log ("Elicitation request received in print mode").

    Same trigger as above: an UPDATE ... WHERE id = ... whose text value contained a semicolon. A minimal no-op reproduces it:

    update some_table set name = replace(name, 'x; y', 'x; y') where id = '...';

    Alongside #459, it would help if a declined confirmation said why, e.g. {"status":"declined","reason":"destructive_sql_confirmation","detail":"UPDATE without WHERE"}, so clients and agents can tell this apart from other refusals.

  3. hexproof-dev commented on Oct 13, 2026

    @hexproof-dev

    thanks for #459. I ran it against the statement shapes we've been hitting, and it covers more than its description says. The single-quoted semicolon UPDATEs are fixed, and so is a case I expected it to miss: an apostrophe inside a dollar-quoted value. On main, update t set v = $$it's$$ where k = 'r1' is flagged because stripQuotedSpans pairs that apostrophe with the opening quote of 'r1' and the WHERE disappears. The new lexer in #459 handles it.

    That said, these still get flagged with #459 applied (head 00f3e9a, checked by calling isDestructiveSql directly in Node 24, and all of them are flagged on main too):

    -- A semicolon inside a dollar-quoted value: read as an UPDATE without WHERE
    update t set v = $$a; b$$ where k = 'r1';
    update t set v = $n$a; b$n$ where k = 'r1';
    
    -- "; delete", "; drop" or "; truncate" inside any literal, in any statement type
    insert into t (k, v) values ('r3', 'done; delete later');
    update t set v = 'done; drop the idea' where k = 'r1';
    select f('ok; delete later');
    
    -- Smaller ones
    update t set v = 'x' /* a; b */ where k = 'r1';
    update t set v = 'x' where(k = 'r1');

    The first group is the trade-off #459 describes, where every semicolon inside a dollar body still splits so DO $$ ... $$ bodies stay checked. Could a dollar body that follows =, ||, (, , or VALUES be treated as a value, and only one that follows DO, AS or EXECUTE be treated as code? The second group is the checkDestructiveQuery half this issue still tracks. Agent-written prose runs into it easily, so it would be good to keep it on the list.

    One more client data point, to go with the VS Code one above. In the Claude Desktop app's Code tab, statements this check flags, including a plain delete ... where, ran in one to two seconds with no confirmation shown, and we saw no hang there across about 1,500 execute_sql calls over three days. We couldn't tell from the client side whether that's because it doesn't declare elicitation or because it answers automatically. Our hangs came from other Claude surfaces. We believe those are the claude.ai chat and Cowork connectors, but we haven't reproduced it there directly. So depending on the client, a flagged statement waits until the timeout, gets declined at once, or runs without a visible confirmation.

    In the meantime we've moved our free-text writes to base64 (convert_from(decode('...', 'base64'), 'UTF8')), as the original report suggests, and keep semicolons out of literals everywhere else.

  4. Miguel-Shinyenyi commented on Oct 14, 2026

    @Miguel-Shinyenyi

    Adding evidence on the second half of this issue, the checkDestructiveQuery false positive on 'done; delete later'. #459 covers the UPDATE half only.

    I prototyped a quote-aware split for checkDestructiveQuery locally (not a PR) and compared it with main by calling isDestructiveSql directly. It fixes these, which main flags:

    insert into t (k, v) values ('r3', 'done; delete later');
    select f('ok; delete later');

    But once single-quoted strings are treated as opaque, these pass silently, and main flags all of them:

    DO 'begin perform 1; drop table films; end'
    CREATE FUNCTION f() RETURNS void AS 'begin; delete from films; end' LANGUAGE plpgsql

    I special-cased EXECUTE '...; DROP TABLE films' so it stays flagged, but that was not enough. DO and CREATE FUNCTION ... AS take a code string in the same way. So a fix needs a rule for when a string is code (after DO, EXECUTE, AS, possibly others) and when it is data, or a real parser, and the choice changes what gets confirmed. Which direction would the maintainers prefer?

    Once this is accepted and #459 has merged, I can send a follow-up PR for this half that builds on #459's lexer instead of adding a second one.

    Verification: direct calls to the exported functions with vitest on Node. Nothing was run against a database or the hosted server.

  5. ahsannaem commented on Oct 19, 2026

    @ahsannaem

    Following up specifically on the extension returning only {"status":"declined"}: there is a related upstream report at anthropics/claude-code#89858 that may help separate the client behavior from the SQL classifier bug.

    The published Claude Agent SDK 0.3.234 returns {action:"decline"} in its elicitation control-request handler when onElicitation is absent. That establishes a client-side path to decline without a user response; it does not establish which path the extension version reported here took.

    On the Supabase side, at bd2d33f1b401adbbf913b3f40eb460fd67e1f9ea:

    So the remaining diagnostic question for the status-only symptom is what the affected client receives on the wire versus what it exposes to the agent. These source checks do not explain that difference, or let the server distinguish a real refusal from a client-generated decline.

    Verification: AI-assisted inspection of the published SDK and the pinned Supabase source, plus direct local execution of the confirmation helper with a stubbed request context. No reproduction in the affected extension or against the hosted server.

  6. self-assigned this
    on Oct 23, 2026
  7. mdstanberry commented on Nov 3, 2026

    @mdstanberry

    Data point from Claude Cowork (the agent surface in the Claude desktop app), for the client question raised above.

    In Cowork a flagged statement is not left waiting, and no confirmation reaches the person. execute_sql returns {"status":"cancelled"} right away and the statement does not run (checked by reading the data back each time). Each result below is one run per case, against a hosted project.

    • 2026-10-07, scratch table, server @supabase/mcp-server-supabase 0.13.0: UPDATE ... SET val = val || '-c1' with no WHERE returned cancelled and no row changed. The person watching live saw no prompt. UPDATE ... WHERE id = 1 in the same session ran. DROP SCHEMA ... CASCADE returned cancelled twice.
    • 2026-10-19, session-scoped temp table, WHERE false so nothing could change: a value of 'test a; b' returned cancelled. The same statement with 'control a, b' ran. A value built as 'workaround a' || chr(59) || ' b' ran.
    • 2026-10-23, after fix(mcp): don't split an UPDATE on a semicolon inside a quoted value #459 merged to main on 2026-10-20: the same in-value semicolon probe still returned cancelled on the hosted server, so the fix had not reached the hosted build yet. A DELETE ... WHERE false also returned cancelled. The server version was not recorded for this run.

    Why it matters: the calling agent cannot tell this result from a real decline, so a write that never ran can be reported as done. On our side we now treat cancelled as "did not run", read the row back before any retry, and write semicolons as chr(59).

    Two requests, both already suggested above:

    1. Keep the checkDestructiveQuery half of this issue on the list (the quoted delete, drop and truncate fragments).
    2. Where a client cannot show the confirmation, return a reason with the refusal (for example the destructive_sql_confirmation shape suggested above), so clients and agents can tell it from a person saying no.

    Thank you for #459.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions