Repository navigation
fix(engine): escape the table name and path in the import/export access log - #772
LeeroyHannigan wants to merge 2 commits into
Conversation
…ss log ImportTable and ExportTableToPointInTime logged their access record with the table name and the resolved file path as Display fields. The path check accepts CR, LF and ESC in a file name, ImportTable logs the table name from TableCreationParameters before any check of it, and the text log format writes Display fields as they are. A caller allowed to import or export could therefore end the log line early, add a line formatted as a log line of its own, and send terminal escape sequences to whoever reads the log. Both handlers now log through log_file_access, which records the table name and the path as Debug fields. Debug escapes control characters, so the record stays one line. Both values now appear quoted in the text format, and in the JSON format table_name and resolved_path hold the Debug form; nothing in the repository reads them. Two unit tests capture the record with the text formatter and check that a path, and a table name, holding \n, \r and \x1b give one line with those characters escaped. With either field back to Display, its test fails. On a sqlite-memory dev-mode server with an export root, an export whose S3Prefix holds such a name put a forged log line and a line starting with the escape sequence into the server log of a build of main, and a single line with the name escaped into the log of a build with this change. Fixes #705.
crates/engine/Cargo.toml keeps the tokio-util, bytes and futures dependencies and the dev-dependencies from main and adds the tracing-subscriber dev-dependency from this branch to that section.
LJMart11
left a comment
There was a problem hiding this comment.
Reviewed at 1bf72a2. cargo test --locked -p extenddb-engine passed (870 tests), and putting either access-log field back to Display fails its new test. The one note is about the test count in the description.
1 finding is left inline.
| } | ||
|
|
||
| #[test] | ||
| fn a_path_with_control_characters_stays_on_one_log_line() { |
There was a problem hiding this comment.
The Testing section gives 195 passed for cargo test --locked -p extenddb-engine, but this head runs 870 (869 in the lib binary, 1 in tests/private_modes.rs, 0 doctests). Putting table_name or resolved_path back to Display in log_file_access fails the matching new test at import_export.rs:579 (left: 3, right: 1 for the table name), so both fields are pinned. Updating the count in the description would resolve this.
demohan
left a comment
There was a problem hiding this comment.
The access log record is escaped at 1bf72a2, and the check it records is unchanged. Over 38 ImportTable and ExportTableToPointInTime shapes, control characters, quotes, backslashes and Unicode in the table name and path, .., //, /./, absolute and relative paths, another account's subtree, the bare root, symlinked directories and files and NUL, run twice each on SQLite and PostgreSQL, this head and main give the same status, type and message, and nothing is written outside the roots. In the text log this head writes no forged line, CR or ESC where main writes six of each, and the escape covers U+2028, U+202E, U+0085, U+009B, NUL, " and \. Putting either field back to Display fails its test, the Cargo.lock line adds tracing-subscriber as a dev-dependency only, and fmt, clippy, 870 engine tests and the 1.88.0 check are clean.
Main has since moved both handlers into import_export/files.rs (#1009), so this branch conflicts there, and taking main's import_export.rs drops the fix while still building and passing: main keeps the Display fields at files.rs:56 and :319. Moved into files.rs by hand, the fix builds on main and its 981 engine tests pass. I will approve once the fix is carried into files.rs and a test fails if a handler logs the fields with Display.
| table_name = %table_name, | ||
| resolved_path = %output_path.display(), | ||
| "import/export file access" | ||
| log_file_access( |
There was a problem hiding this comment.
The tests call log_file_access directly, so a call site that logs the fields itself is not caught: with the export call site put back to main's inline Display log, both tests pass. The move into files.rs changes exactly these call sites; a test that runs the handler and reads the captured record would hold it.
| /// path are Debug fields, which escape control characters, so a value that | ||
| /// holds a line break or a terminal escape sequence stays inside this one log | ||
| /// line. Both come from the request: ImportTable logs the table name it is | ||
| /// about to create before any check of that name. |
There was a problem hiding this comment.
Optional. Since #830 the server's table name gate refuses TableName edbv-772-c-bad\nname with a 400 ValidationException before the handler, on both backends, so through the server only the path can carry control characters; the table name escape is defence in depth, which this comment and the body could say.
ImportTableandExportTableToPointInTimelogged their access record with the table name and the resolved file path as Display fields (table_name = %table_name,resolved_path = %path.display()). The path check accepts CR, LF and ESC in a file name,ImportTablelogs the table name fromTableCreationParametersbefore any check of it, and the text log format writes Display fields as they are. A caller allowed to import or export could therefore end the access log line early, add a line formatted as a log line of its own, and send terminal escape sequences to whoever reads the log.Change
log_file_access, which records the table name and the path as Debug fields (?). Debug escapes control characters, so the record stays one line.table_nameandresolved_pathhold the Debug form. Nothing in the repository reads them.tracing-subscriber(already a workspace dependency) becomes a dev-dependency ofextenddb-enginefor the new tests, which adds one line toCargo.lock.Tests
a_path_with_control_characters_stays_on_one_log_lineanda_table_name_with_control_characters_stays_on_one_log_linecapture the record with the text formatter and check that a value holding\n,\rand\x1bgives one line, with the characters escaped. With either field back to Display, its test fails. The tests calllog_file_accessdirectly; no test reads a running server's log.Measurement
sqlite-memory dev-mode servers on 127.0.0.1 with
EXTENDDB__IMPORT_EXPORT_ROOTset:ExportTableToPointInTimewhoseS3Prefixnames a filex, LF,2026-10-31T23:59:59.000000Z INFO forged line, CR LF,ESC[31mred ESC[0m.jsonx; the next line starts with the forged timestamp, and the one after with the escape sequenceImportTablewithTableNamebad, LF,nametable_name=badTesting
cargo +1.97.0 fmt --all -- --checkandcargo +1.97.0 clippy -p extenddb-engine --all-targets -- -D warnings: clean.cargo +1.88.0 test --locked -p extenddb-engine: 195 passed.Not in this change
FilePathwith aValidationException. This change does not: the export still creates a file with that name. How the service answers a control character inS3Prefixhas not been measured.ImportTablecreates its table without the checksCreateTablemakes, so it creates tables under names such asabor one with a line feed, which the service refuses. ImportTable creates a table under a name CreateTable refuses #771 tracks that.Fixes #705.