Repository navigation
fix(log): implement the ADR-0024 control-byte-escaping field formatter - #101
Conversation
ADR-0024 mandates that the human-readable formatter escape control bytes in string field values to a visible \xNN form via a custom field formatter — explicitly 'part of this decision and not an implementation afterthought' — because stock tracing_subscriber fmt() renders %-recorded (Display) field values verbatim. The binary was using the stock layer, so an authenticated client's command could replay ANSI sequences and forge log lines in an operator's live terminal under --log-format human (threat model §5.4.3). Adds log_fields::EscapingFields, a FormatFields impl whose visitor escapes everything char::is_control reports (C0, DEL, C1 — all <= U+009F) as \xNN, wired into the LogFormat::Human arm only; the JSON format keeps serde's escaping. Covered by unit tests plus an end-to-end test that drives the OSC-title + forged-line attack through a real subscriber and asserts nothing live survives. The dev-dependency on tracing with the std feature exists only for the scoped test subscriber (tracing::subscriber::with_default); the runtime dependency set is unchanged. Found by security review of the merged Phase-1 code: the one direct code-vs-accepted-ADR gap. Claude-Session: https://claude.ai/code/session_017JuwgCHx6Uv5E13g1BHAud Signed-off-by: Gonzalo Fleming <[email protected]>
There was a problem hiding this comment.
Pull request overview
This PR brings the quantumssh binary’s human log formatter in line with ADR-0024 by ensuring control characters inside field values are rendered as visible \xNN escapes (mitigating terminal escape injection / log-line forgery in interactive --log-format human use).
Changes:
- Adds
EscapingFields, a customtracing_subscriber::fmt::FormatFieldsimplementation that escapeschar::is_control()characters when formatting field values (including%/Display-recorded fields viarecord_debug). - Wires the formatter into the
LogFormat::Humanbranch of the binary’sfmt_layer, leaving JSON unchanged. - Adds unit + end-to-end subscriber tests for escaping behavior, plus a
dev-dependencyontracingwithstdfor scoped subscriber tests.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| crates/quantumssh/src/main.rs | Hooks the ADR-0024 escaping field formatter into the human tracing_subscriber fmt layer. |
| crates/quantumssh/src/log_fields.rs | Implements EscapingFields + tests to ensure control bytes in field values are printed as visible \\xNN. |
| crates/quantumssh/Cargo.toml | Adds tracing dev-dependency with std to support tracing::subscriber::with_default in tests. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Code reviewNo issues found. Checked for bugs and CLAUDE.md compliance. |
… adapter Copilot review: record_debug allocated a String per non-str field via format!. EscapingWriter implements fmt::Write over the layer's Writer and escapes in write_str, so Debug/Display formatting streams straight through write_escaped with no intermediate allocation. Output is unchanged; the three log_fields tests pass as-is. Claude-Session: https://claude.ai/code/session_017JuwgCHx6Uv5E13g1BHAud Signed-off-by: Gonzalo Fleming <[email protected]>
Review: ADR-0024 control-byte-escaping field formatterClassification: Rust under Verdict: Clean. No issues found.Changes reviewed against the five MANIFIESTO commitments:
Applied hard security rules:
Design notes (non-blocking):
|
|
Review: ADR-0024 control-byte-escaping field formatterClassification: Rust under Verdict: Clean. No issues found.The PR directly implements the field formatter that ADR-0024 §"Decision – Consequences – Positive" mandates ("the field formatter is part of this decision and not an implementation afterthought"), closing the only Phase-1 gap between ADR text and binary code. The threat model's §5.4.3 OSC-title + line-forgery attack vector is tested end-to-end through a real subscriber. Five commitments
Hard security rules
Design notes (non-blocking)
fmt + clippy + 110 tests (including 3 new): all green. |
…each edit touched Claude checked the Links lines against the milestone PRs' file lists and found four wrong attributions: server.rs (ADR-0016) and everything ADR-0022 names landed in M0 (#62), not M5/M3; transport.rs (ADR-0021) landed in M3 (#65), not M2; and log_fields.rs (ADR-0024) came with #101 on 2026-07-06, after the ADR's acceptance. All four corrected, with the banners' milestone references. Each banner now says which section the edit touched (Context in 0018/0019, Related in 0021/0023/0024, both in 0022) instead of the same sentence everywhere. ADR-0020's Links line no longer carries a note about the unimplemented package pin — that is decision-level content and lives in ADR-0034 (#161). ADR-0023 no longer points at "PR #50 in review" for the event schema, and ADR-0021 drops a "(TBD)" next to the kex module. docs/adr/README.md step 5 distinguishes the governance state from the file's Status line and lists what actually happened (ADR-0027 merged Accepted; 0028/0029 flipped in their implementing PRs; 0030-0032 in #158) instead of calling one instance the practice. docs/infrastructure.md says first-party unsafe would need a superseding ADR, as ADR-0018 states, not an RFC. Findings by Claude and opencode on #159. Claude-Session: https://claude.ai/code/session_018UmL9wcgKBGFjdjGSSLafa Signed-off-by: Gonzalo Fleming <[email protected]>
…events; ADR-0020 and 0017 drafting-time sentences ADR-0024's Related line and banner still grouped the subscriber initialisation under M4/M5 after the Links line moved it to M0; all three now agree (subscriber M0, events M4/M5, formatter #101). ADR-0020's Consequences said the gate is wired up in the first-crate PR; it was wired up in M5 (#84), once a connectable binary existed, and the banner records the edit. ADR-0017's Context no longer calls the workspace currently empty. Raised by Codex and opencode on #159. Claude-Session: https://claude.ai/code/session_018UmL9wcgKBGFjdjGSSLafa Signed-off-by: Gonzalo Fleming <[email protected]>
Qué
Implementa el field formatter que ADR-0024 declara parte de la decisión ("not an implementation afterthought") y que el binario no tenía: en formato humano, los bytes de control dentro de valores de campos se renderizan como
\xNNvisible, nunca vivos.crates/quantumssh/src/log_fields.rs:EscapingFields, unFormatFieldscuyo visitor escapa todo lo quechar::is_controlreporta (C0, DEL, C1 — todo ≤ U+009F). Cubre tantorecord_strcomorecord_debug— este último es el camino que toman los campos%(Display), incluidocommand.LogFormat::Humandefmt_layer; el formato JSON queda intacto (serde ya escapa).tracingcon featurestdsolo para el subscriber scoped de los tests (with_default); el set de dependencias de runtime no cambia.Por qué
El vector de threat model §5.4.3: un cliente autenticado ejecuta
ssh host $'\e]0;pwned\a\ninfo forged.event'y un operador corriendo con--log-format human(default cuando stderr es TTY) recibe escapes ANSI vivos (título de terminal, clear screen) más un salto de línea que forja una segunda línea de log. El default JSON (stderr no-TTY) ya mitigaba el despliegue típico; este PR cierra el caso interactivo que el ADR aceptado mandata. Era el único gap directo código↔ADR de Phase 1.Validación
cargo fmt/clippy --workspace --all-targets -- -D warnings/cargo test --workspace: verdes (110 tests, +3 nuevos).quantumssh --log-format humanemiteserver.config_errorpor el layer nuevo correctamente.Hallazgo de la revisión de seguridad del código Phase-1 mergeado (misma serie que #100, independiente de él).
https://claude.ai/code/session_017JuwgCHx6Uv5E13g1BHAud