Skip to content

fix(grid): make Copy as INSERT name the table the rows came from - #539

Merged
EVWorth merged 1 commit into
mainfrom
fix/grid-copy-insert-table
Sep 4, 2026
Merged

EVWorth merged 1 commit into
mainfrom
fix/grid-copy-insert-table

Conversation

@EVWorth

@EVWorth EVWorth commented Sep 4, 2026

Copy link
Copy Markdown
Owner

Closes #409.

The bug

The statement was built with a literal placeholder:

INSERT INTO your_table (`id`, `name`) VALUES (1, 'Alice');

Pasting that fails with Table 'db.your_table' doesn't exist — the harmless outcome. On a schema where that name happens to be real, it succeeds, and writes the row somewhere the user never chose. That is why this was filed as security rather than papercut.

The fix

The table now comes from resolveEditTarget — the same resolver Save uses — against the active editor tab's SQL.

Reusing it is deliberate, not convenience. A join or a CTE selects columns belonging to more than one table, so there is no single table an INSERT of that row could target, and resolveEditTarget already refuses exactly those shapes. Where it refuses, the menu item is disabled and its hover text carries the reason, rather than leaving a dead entry with no explanation. The click handler re-checks anyway, since disabled is a UI convention and not a lock.

Identifiers go through quoteIdentifier instead of bare backticks, so a table or column name containing a backtick can't terminate the quoting early.

MenuItem gains an optional title. Nothing else used one; a disabled item with no way to say why is the reason it now exists.

Tests

Three in the browser suite — the table is named, a name needing quoting survives, and a join disables the item with a reason. All three fail against the previous implementation, verified by stashing ResultsGrid.tsx and ContextMenu.tsx and re-running.

Also

Dropped extractTableName from that file's sql-generator mock. #529 removed it from the module, so the mock was describing an export that no longer exists.

Local: 1693 unit + 295 browser tests green, tsc/dprint/eslint clean.

🤖 Generated with Claude Code

Closes #409.

The statement was built with a literal placeholder:

  INSERT INTO your_table (`id`, `name`) VALUES (1, 'Alice');

Pasting it fails with "Table 'db.your_table' doesn't exist", which is the
harmless outcome. On a schema where that name happens to be real, it
succeeds and writes the row somewhere the user never chose — which is why
this was filed as security rather than papercut.

The table now comes from resolveEditTarget, the same resolver Save uses,
against the active editor tab's SQL. Reusing it is deliberate: a join or a
CTE selects columns belonging to more than one table, so there is no single
table an INSERT of that row could target, and it already refuses exactly
those shapes. Where it refuses, the menu item is disabled and its hover text
gives the reason rather than leaving a dead entry with no explanation. The
click handler re-checks, since disabled is a UI convention and not a lock.

Identifiers now go through quoteIdentifier instead of bare backticks, so a
table or column name containing a backtick cannot terminate the quoting
early.

MenuItem gains an optional `title`. Nothing else used it; a disabled item
with no way to say why is the reason it exists.

Three tests in the browser suite. All three fail against the previous
implementation — verified by stashing the two source files and re-running.

Also dropped `extractTableName` from that file's sql-generator mock. It was
removed from the module in #529, so the mock was describing an export that
no longer exists.

Co-Authored-By: Claude Opus 5 <[email protected]>
@EVWorth
EVWorth merged commit 36f0cc4 into main Sep 4, 2026
10 checks passed
@EVWorth
EVWorth deleted the fix/grid-copy-insert-table branch September 4, 2026 23:53
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.

[P1] [security] Copy as INSERT uses hardcoded your_table placeholder — broken SQL

1 participant