Skip to content

fix(import): one escape table, and say what a dump will drop - #579

Merged
EVWorth merged 1 commit into
mainfrom
fix/import-safety
Sep 9, 2026
Merged

EVWorth merged 1 commit into
mainfrom
fix/import-safety

Conversation

@EVWorth

@EVWorth EVWorth commented Sep 9, 2026

Copy link
Copy Markdown
Owner

Closes #364, #367.

The escaping was a third copy — #364

The issue is right that the escaping is correct today, and right about why that isn't the end of it: the escape table is the security boundary, and three implementations means three chances for a future change to drop a transformation from one of them.

The other two copies have already been the site of exactly that — a missing backslash escape in admin (#444) and in the routine viewer (#397), both of which stored or executed something the user never typed.

sql-import now uses quoteStringLiteral and quoteIdentifier, so there's one implementation with its own tests, shared by the grid, the routine viewer, admin and the importer.

The only rule dropped in the move is escaping a tab as \t. A literal tab inside a quoted string is valid MySQL and round-trips unchanged — the value is identical, only the statement's appearance differs.

Being plain about what this is: the five escaping tests pass against the previous code too. They're regression guards on a boundary that has failed twice elsewhere, not a fix for a live injection. Nothing here was exploitable.

A dump's DROP was invisible until it ran — #367

The preview rendered the file's first fifty lines verbatim. A DROP TABLE at line 5,000 of a mysqldump wasn't visible without reading the whole file, and the count above it said only how many statements there were.

Statements are now classified with isDestructiveStatement — the same check the production gate uses, so a file is judged by rules the app already applies — and the ones that drop or overwrite data are listed above the preview before Import is available.

Also found, filed rather than fixed

An empty CSV cell becomes SQL NULL. CSV distinguishes ,, from ,"",, but the parser returns plain strings so the distinction is gone before this code sees it. A NOT NULL column then rejects a row the user considers valid; a nullable one silently stores NULL where the file said "". Defensible as a default, not as an invisible decision — #578, and the call site now names it.

Tests

Five on the escaping boundary (quote-and-semicolon payload, trailing backslash, control characters, backtick identifiers, empty cell), two on the warning. Only the warning tests fail against the previous version, as above.

1785 unit + 299 browser green; tsc/dprint/eslint clean.

Left in import

#365 (SQL import runs serially — one failed statement aborts the rest, leaving a partial import) and #366 (no row-size or file-size cap; parseCSV on a very large file). #363 is doc-drift about commands ARCHITECTURE declares that don't exist.

🤖 Generated with Claude Code

Closes #364, #367.

## The escaping was a third copy (#364)

The issue is right that the escaping is correct today and right about why
that is not the end of it: the escape table is the security boundary, and
three implementations of it means three chances for a future change to drop a
transformation from one of them. The other two have already been the site of
exactly that — a missing backslash escape in admin (#444) and in the routine
viewer (#397), both of which stored or executed something the user never
typed.

sql-import now uses quoteStringLiteral and quoteIdentifier, so there is one
implementation with its own tests, shared by the grid, the routine viewer,
admin and the importer.

The only rule dropped in the move is escaping a tab as \t. A literal tab
inside a quoted string is valid MySQL and round-trips unchanged, so the value
is identical; only the statement's appearance differs.

Being plain about what this is: the five escaping tests pass against the
previous code too. They are regression guards on a boundary that has failed
twice elsewhere, not a fix for a live injection. Nothing was exploitable.

## A dump's DROP was invisible until it ran (#367)

The preview rendered the file's first fifty lines verbatim. A DROP TABLE at
line 5,000 of a mysqldump was not visible without reading the whole file, and
the count above it said only how many statements there were.

The statements are now classified with isDestructiveStatement — the same
check the production gate uses, so a file is judged by the rules the app
already applies — and the ones that drop or overwrite data are listed above
the preview before Import is available.

## Also found, filed rather than fixed

An empty CSV cell becomes SQL NULL. CSV distinguishes `,,` from `,"",` but
the parser returns plain strings, so the distinction is gone before this code
sees it: a NOT NULL column rejects a row the user considers valid, and a
nullable one silently stores NULL where the file said "". Defensible as a
default, not as an invisible decision. #578, and the call site now names it.

Co-Authored-By: Claude Opus 5 <[email protected]>
@EVWorth
EVWorth merged commit 76d3bc0 into main Sep 9, 2026
10 checks passed
@EVWorth
EVWorth deleted the fix/import-safety branch September 9, 2026 11:01
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.

[P0][security] CSV import uses string interpolation (escapeValue); no parameterized inserts

1 participant