Repository navigation
fix(logging): escape log-file lines in the sink, not the CLI renderer - #7357
Merged
Merged
Conversation
Upstream has exactly one writer to the log file: `logit()` (log.c:126), which hands every line to `filtered_fwrite(logfile_fp, buf, len, 0, 1, trailing)` at log.c:132. Escaping in the sink is what makes it unbypassable - a producer cannot forget it, because there is no other way to reach the file. oc-rsync escaped in the CLI out-format renderer instead. That covered `--log-file` on the client and nothing else: the daemon writes its log through an entirely different path, so a peer-supplied operand reached the log with a raw ESC where rsync 3.5.0 writes `\#33`. Move the escaper down to `logging_sink::logfile::LogFileWriter`, the one type both the CLI (summary.rs) and the daemon (daemon.rs, privilege.rs, hardening.rs, module_access) construct for a log file, and switch the renderer to the new `EscapeStyle::passthrough`. Applying both would double-escape: the sink's `\#ddd` guard (log.c:252-254) fires on the renderer's own output and turns `\#33` into `\#134#033`. Two consequences fall out of putting it in the sink: - `EscapeStyle` gains an `escape_controls` switch. Upstream has no such switch because every `filtered_fwrite` call site escapes C0 controls; oc-rsync needs one because it now has a sink upstream does not - the passthrough style, whose whole job is to leave the bytes alone. - The `Write` adapter now treats a newline as a record terminator only when it ends the write. A newline *inside* the message is escaped as `\#12`, matching log.c:128-129, which strips exactly one trailing newline. This is the injection itself: every line the sink emits gets a real timestamp and pid, so a name carrying `\n` would otherwise produce a second, entirely authentic-looking record. Tests: a daemon integration test pins the half a renderer-side escaper cannot reach (peer-supplied operand in the `client args:` line), with a printable control operand so the assertions cannot pass vacuously. It fails with a raw ESC in the log when the sink escaping is reverted. The existing 3.5.0 oracle test for `--log-file` still passes unchanged, which is what proves the move did not perturb the client half.
oferchen
added a commit
that referenced
this pull request
Aug 24, 2026
…#7357) Upstream has exactly one writer to the log file: `logit()` (log.c:126), which hands every line to `filtered_fwrite(logfile_fp, buf, len, 0, 1, trailing)` at log.c:132. Escaping in the sink is what makes it unbypassable - a producer cannot forget it, because there is no other way to reach the file. oc-rsync escaped in the CLI out-format renderer instead. That covered `--log-file` on the client and nothing else: the daemon writes its log through an entirely different path, so a peer-supplied operand reached the log with a raw ESC where rsync 3.5.0 writes `\#33`. Move the escaper down to `logging_sink::logfile::LogFileWriter`, the one type both the CLI (summary.rs) and the daemon (daemon.rs, privilege.rs, hardening.rs, module_access) construct for a log file, and switch the renderer to the new `EscapeStyle::passthrough`. Applying both would double-escape: the sink's `\#ddd` guard (log.c:252-254) fires on the renderer's own output and turns `\#33` into `\#134#033`. Two consequences fall out of putting it in the sink: - `EscapeStyle` gains an `escape_controls` switch. Upstream has no such switch because every `filtered_fwrite` call site escapes C0 controls; oc-rsync needs one because it now has a sink upstream does not - the passthrough style, whose whole job is to leave the bytes alone. - The `Write` adapter now treats a newline as a record terminator only when it ends the write. A newline *inside* the message is escaped as `\#12`, matching log.c:128-129, which strips exactly one trailing newline. This is the injection itself: every line the sink emits gets a real timestamp and pid, so a name carrying `\n` would otherwise produce a second, entirely authentic-looking record. Tests: a daemon integration test pins the half a renderer-side escaper cannot reach (peer-supplied operand in the `client args:` line), with a printable control operand so the assertions cannot pass vacuously. It fails with a raw ESC in the log when the sink escaping is reverted. The existing 3.5.0 oracle test for `--log-file` still passes unchanged, which is what proves the move did not perturb the client half.
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.
Problem
Upstream rsync has exactly one writer to the log file:
logit()(log.c:126), which hands every line tofiltered_fwrite(logfile_fp, buf, len, 0, 1, trailing)atlog.c:132. Escaping in the sink is what makes it unbypassable - a producer cannot forget it, because there is no other way to reach the file.oc-rsync escaped in the CLI out-format renderer instead. That covered
--log-fileon the client and nothing else. The daemon writes its log through an entirely different path, so a peer-supplied operand reached the log with a rawESCwhere rsync 3.5.0 writes\#033:Every line the sink emits carries a genuine timestamp and pid, so a name carrying a newline could open a second, entirely authentic-looking record (CWE-117).
Change
Move the escaper from
crates/cli/src/frontend/escape.rsdown tocrates/logging-sink/src/escape.rs, and apply it insideLogFileWriter- the one type both the CLI (summary.rs) and the daemon (daemon.rs,privilege.rs,hardening.rs,module_access) construct for a log file.logging-sinkwas already a dependency of both, so nothing new enters the crate graph.The renderer switches to a new
EscapeStyle::passthrough. Applying both would double-escape: the sink's\#dddguard (log.c:252-254) fires on the renderer's own output and turns\#033into\#134#033- which is exactly what the existing oracle test reported when only half the change was in place.Two consequences fall out of putting it in the sink:
EscapeStylegains anescape_controlsswitch. Upstream has no such switch because everyfiltered_fwritecall site escapes C0 controls. oc-rsync needs one because it now has a sink upstream does not - the passthrough style, whose whole job is to leave the bytes alone.Writeadapter treats a newline as a record terminator only when it ends the write. A newline inside the message is escaped as\#012, matchinglog.c:128-129, which strips exactly one trailing newline. The previous byte-stream splitting turned an embedded newline into a second prefixed line - the injection this defends against. Producers already deliver one message per call (MessageSink, andwriteln!on the CLI side), so this is the boundary upstream works on.Verification
tests/daemon_log_file_escaping.rspins the half a renderer-side escaper cannot reach: a peer-supplied operand carryingESCandLF, asserted byte-exactly asA\#033B\#012C, with a printable control operand in the same run so the assertions cannot pass vacuously.write_escaped-> rawwrite_all) fails the new test witha raw ESC reached the daemon log file.crates/cli/tests/log_file_control_char_escape.rspasses unchanged - that is what proves the move did not perturb the client half.cargo fmt --all -- --checkclean;cargo clippy --locked --workspace --all-targets --all-features --no-deps -- -D warningsclean.cargo nextest run -p logging-sink -p cli --all-features: 3974 passed.-p daemon --all-features: 1797 passed.Closes the residual filed when the log-file escaping port was reviewed.