Repository navigation
fix(import): one escape table, and say what a dump will drop - #579
Merged
Merged
Conversation
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]>
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.
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-importnow usesquoteStringLiteralandquoteIdentifier, 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 TABLEat 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. ANOT NULLcolumn 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;
parseCSVon a very large file). #363 is doc-drift about commands ARCHITECTURE declares that don't exist.🤖 Generated with Claude Code