Skip to content

fix(engine): escape the table name and path in the import/export access log - #772

Open
LeeroyHannigan wants to merge 2 commits into
mainfrom
fix/705-escape-export-path-log
Open

LeeroyHannigan wants to merge 2 commits into
mainfrom
fix/705-escape-export-path-log

Conversation

@LeeroyHannigan

Copy link
Copy Markdown
Collaborator

ImportTable and ExportTableToPointInTime logged 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, 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 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

  • Both handlers log through a new 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.
  • tracing-subscriber (already a workspace dependency) becomes a dev-dependency of extenddb-engine for the new tests, which adds one line to Cargo.lock.

Tests

a_path_with_control_characters_stays_on_one_log_line and a_table_name_with_control_characters_stays_on_one_log_line capture the record with the text formatter and check that a value holding \n, \r and \x1b gives one line, with the characters escaped. With either field back to Display, its test fails. The tests call log_file_access directly; no test reads a running server's log.

Measurement

sqlite-memory dev-mode servers on 127.0.0.1 with EXTENDDB__IMPORT_EXPORT_ROOT set:

Request main this change
ExportTableToPointInTime whose S3Prefix names a file x, LF, 2026-10-31T23:59:59.000000Z INFO forged line, CR LF, ESC[31mred ESC[0m.json the access line ends after x; the next line starts with the forged timestamp, and the one after with the escape sequence one access line, with the name escaped
ImportTable with TableName bad, LF, name the access line ends after table_name=bad covered by the unit test

Testing

  • cargo +1.97.0 fmt --all -- --check and cargo +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

  • The issue also suggests refusing control characters in FilePath with a ValidationException. This change does not: the export still creates a file with that name. How the service answers a control character in S3Prefix has not been measured.
  • ImportTable creates its table without the checks CreateTable makes, so it creates tables under names such as ab or one with a line feed, which the service refuses. ImportTable creates a table under a name CreateTable refuses #771 tracks that.

Fixes #705.

…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 LJMart11 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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() {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 demohan self-assigned this Nov 27, 2026

@demohan demohan left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

This branch has not been deployed

No deployments
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.

Export and import paths can write CR, LF and terminal escape sequences into the server log

3 participants