Skip to content

fix(sql): the destructive-query detector misses non-Latin names, MySQL DELETE forms, WITH ... DELETE, EXPLAIN ANALYZE and DROP COLUMN #1770

Closed

Description

@ZhuchkaTriplesix

Problem

`DestructiveSqlDetector.inspect` (lib/core/database/destructive_sql_detector.dart) decides whether the confirmation dialog appears. Its regexes were run on these inputs, and no confirmation would be shown for:

  • Non-Latin identifiers (names are `[a-zA-Z0-9_]+`): `DROP TABLE "заказы"`, `DROP DATABASE склад`, `TRUNCATE "таблица"`. `DROP TABLE public.заказы` is detected, but the target is reported as `public`.
  • MySQL `DELETE` forms: `DELETE IGNORE FROM t`, `DELETE LOW_PRIORITY FROM t`, `DELETE t1 FROM t1 JOIN t2 ...`. The `UPDATE` regex accepts `LOW_PRIORITY|IGNORE`, the `DELETE` one does not.
  • PostgreSQL: `WITH x AS (...) DELETE FROM t` and `EXPLAIN ANALYZE DELETE FROM t` (which really deletes). The regexes are anchored at the start of the statement.
  • Not a covered category at all: `ALTER TABLE ... DROP COLUMN` (loses data), `DROP INDEX/TYPE/FUNCTION/ROLE/USER`, `DROP ... CASCADE`.

Fix

  • Use a Unicode-aware identifier pattern (`[\p{L}\p{N}_$]+` with `unicode: true`) or a quoted-identifier rule that takes everything between the quotes.
  • Allow the MySQL modifiers (`LOW_PRIORITY`, `QUICK`, `IGNORE`) and the multi-table `DELETE t1 FROM` form.
  • Look through a leading `WITH (...)` list and an `EXPLAIN [ANALYZE]` prefix before matching.
  • Add `ALTER TABLE ... DROP COLUMN` and the other `DROP` kinds (a new type, risk HIGH).
  • Tests with these exact statements.

Found in the review of the SQL safety layer.

Activity

  1. added
    bugSomething isn't working
    editorCode/SQL editor
    P2Medium priority / Parity & Refactoring
    on Oct 25, 2026
  2. added a commit that references this issue on Oct 25, 2026
  3. ZhuchkaTriplesix commented on Oct 25, 2026

    @ZhuchkaTriplesix
    MemberAuthor

    Fixed on dev in #1786, #1797 (merged). Closing by hand: the PRs target dev, so GitHub would only close this when dev is merged into main.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Medium priority / Parity & RefactoringbugSomething isn't workingeditorCode/SQL editor

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions