Skip to content

fix(core): validate and quote the RSYNC_CONNECT_PROG %H substitution - #7430

Merged
oferchen merged 5 commits into
masterfrom
fix/connect-prog-host-validation
Aug 21, 2026
Merged

oferchen merged 5 commits into
masterfrom
fix/connect-prog-host-validation

Conversation

@oferchen

Copy link
Copy Markdown
Owner

Ports upstream 3.5.0's two RSYNC_CONNECT_PROG host defences, which oc did
not have at all.

What was wrong

%H is substituted into a command string that a shell runs. oc substituted
the host with zero validation and no quoting, so a host taken from an
rsync://HOST/mod operand became shell syntax rather than data.

Upstream applies two defences, both inside if (prog && strchr(prog, '%'))
(socket.c:488-495), so a template with no specifier never inspects the host:

defence upstream oc before
refuse a shell-active host socket.c:204-215 shell_unsafe_connect_host() absent
single-quote what survives socket.c:152 shell_quote_connect_host() absent

The refusal is not redundant with the quoting. Quoting keeps a host one word
but cannot stop a leading -/+ looking like an option to the named
program, ~root being tilde-expanded by a nested shell, or %self being
expanded by a nested fish - those change an argument's meaning, not its text.
An empty host is refused for the same reason: it survives a direct exec as an
empty argument but vanishes when a nested shell re-splits, shifting every
later argument left.

Measured

Against the real upstream 3.5.0 binary as the control, on Linux:

cell oc before oc after upstream 3.5.0
connect-prog-host-quoting pass pass pass
connect-prog-nested-singlequote-host-injection fail fail pass

⚠ This change flips no manifest row, and the PR does not claim one.
connect-prog-host-quoting was already recorded pass; the cell that
actually exercises the guard is the nested one, and it still fails for an
independent reason given below. The change is upstream fidelity plus a real
injection defence, not a row flip - stated plainly rather than implied.

⚠ METHOD NOTE. My first control run used rsync from PATH, which is
3.4.1 here - it fails the nested cell too, which would have read as
"fixture-limited, not an oc bug" and closed the investigation. Re-run against
the pinned 3.5.0 binary, upstream passes and the residual is oc's. A control
from PATH is not a control.

The residual, surfaced rather than folded in

The nested cell now fails on exactly one row: host %self is not refused,
because it never reaches the validator. oc percent-decodes the daemon host
(module_list/parsing.rs, invalid percent-encoding in daemon host) with an
IPv6-zone fallback, so %self is rejected as a malformed escape before the
connect-program path runs.

Upstream 3.5.0 has no percent-decoding of the daemon host anywhere -
verified by reading, not assumed: % is a literal hostname byte, which is why
%self reaches shell_unsafe_connect_host() and is refused there. So oc's
decode is an invention, and removing it is the upstream-fidelity direction.

It is left out of this PR deliberately: it is a user-visible behaviour change
to every rsync:// URL, it has its own tests asserting the current error, and
the IPv6-zone fallback exists only to paper over the decode. That belongs in
its own reviewable change, not bolted onto a security fix.

Tests

Both upstream cells are transcribed directly, row for row - the refuse set
(localhost;touch${IFS}pwned;#, -c, +x, ~root, %self, empty) and the
accept set (example.com, example.com., host_name, host+alias,
host~alias, fe80::1%eth0), so an allow-list that simply refused everything
cannot pass. Plus the no-specifier gate, and a direct pin on the '\'' escape

  • unreachable through format_command by construction, since ' is outside
    the allowed byte set, so it is pinned against its own helper instead of
    through a path that cannot reach it.

Nine existing assertions recorded the pre-fix unquoted rendering. They are
inverted, not deleted: format_command("example.com") now yields
connect to 'example.com', and the empty-host and user@host cases become
refusals. The end-to-end run_module_list_uses_connect_program_command test
is untouched and still passes - the outer shell strips the quotes, which is
the demonstration that the quoting is transparent to a real connect program.

⚠ The first two rounds fixed only the assertions a failing run named. The
third round swept every format_command call in the module and found two more
(port_zero, port_max) that no run had reached yet.

  • cargo nextest -p core --all-features --lib -E 'test(connect) or test(format_command) or test(shell_quote)': 181/181 on Linux
  • cargo fmt --all -- --check clean and cargo clippy --workspace --all-targets --all-features --no-deps -- -D warnings clean, both verified
    on Linux (macOS cargo fmt reported clean while Linux rustfmt did not)

…am cells

Both rows of testsuite/connect-prog-host-quoting_test.py are now covered
directly, and the assertions that recorded the pre-fix unquoted rendering
are inverted rather than deleted: upstream substitutes the single-quoted
host (socket.c:495), so an empty host and a byte outside the allowed set
are refusals, not renderings.
Same defect class as the previous commit; found by sweeping every
format_command call in the module rather than only the one the failing
run named.
@github-actions github-actions Bot added the bug Something isn't working label Aug 21, 2026
@oferchen
oferchen merged commit 87b164d into master Aug 21, 2026
70 checks passed
@oferchen
oferchen deleted the fix/connect-prog-host-validation branch August 21, 2026 21:38
oferchen added a commit that referenced this pull request Aug 21, 2026
oc rewrote the daemon host three ways before anything could judge it.
Upstream rewrites it in none of them: `check_for_hostspec` (options.c:3295)
takes the host as written and hands the same bytes to `getaddrinfo`, or, under
`RSYNC_CONNECT_PROG`, to `shell_unsafe_connect_host` (socket.c:204-215).

| rewrite | oc before | upstream |
|---|---|---|
| percent-decode `%XX` in host and username | decoded, and rejected a lone `%` as a malformed escape | no percent-decoder exists anywhere |
| empty authority | substituted `localhost` | stays empty |
| leading/trailing whitespace | trimmed | kept |

Each one is load-bearing in the same direction: the validator can only refuse
what reaches it.

- `%self` was rejected as a bad escape before the connect-program guard could
  refuse it - and refusing it is the point, since a nested fish expands
  `%self` to its pid.
- `rsync:///mod/` silently dialled a host the operator never named. Measured
  against the pinned 3.5.0 binary: upstream fails in `getaddrinfo` with an
  empty node, and refuses the empty host outright under `RSYNC_CONNECT_PROG`
  (an empty argument survives a direct exec but vanishes when a nested shell
  re-splits, shifting every later argument left).
- Trimming is not cosmetic. Measured: `rsync:// localhost /m/` under a connect
  program is refused by upstream as shell-unsafe (space is outside the allowed
  byte set) while oc handed the program a clean `localhost`. Trimming
  converted a host upstream refuses into one it accepts.

An IPv6 zone id (`fe80::1%eth0`) relies on the same literal treatment, which
is why the decoder needed a zone-id fallback to paper over itself.

`DaemonAddress::new` therefore cannot fail and no longer returns `Result`;
its empty-host rejection existed only to be routed around by the `localhost`
default. The CONNECT-header CRLF guard in `proxy.rs` is now the only thing
standing between a hostile host and the request line, and its comment says so.

## Measured

Against the pinned upstream 3.5.0 binary as the control, on Linux:

| cell | before | after | upstream 3.5.0 |
|---|---|---|---|
| `connect-prog-host-quoting` | pass | pass | pass |
| `connect-prog-nested-singlequote-host-injection` | fail | **pass** | pass |

The nested cell needed both this change and #7430; neither flips it alone.
Its four manifest rows flip in this commit.

RED proven by restoring only the `localhost` default: the cell returns to
`overall result is 1`.

⚠ The empty-host parse had no test at all before this - that absence is why
the substitution survived. It is pinned now, with a named-host companion so
the pin cannot pass by everything coming back empty.

- `cargo nextest run -p core --all-features --lib`: 2558/2558 on Linux
- `cargo fmt --all -- --check` and `cargo clippy --workspace --all-targets
  --all-features --no-deps -- -D warnings`: both clean on Linux
oferchen added a commit that referenced this pull request Aug 21, 2026
oc rewrote the daemon host three ways before anything could judge it.
Upstream rewrites it in none of them: `check_for_hostspec` (options.c:3295)
takes the host as written and hands the same bytes to `getaddrinfo`, or, under
`RSYNC_CONNECT_PROG`, to `shell_unsafe_connect_host` (socket.c:204-215).

| rewrite | oc before | upstream |
|---|---|---|
| percent-decode `%XX` in host and username | decoded, and rejected a lone `%` as a malformed escape | no percent-decoder exists anywhere |
| empty authority | substituted `localhost` | stays empty |
| leading/trailing whitespace | trimmed | kept |

Each one is load-bearing in the same direction: the validator can only refuse
what reaches it.

- `%self` was rejected as a bad escape before the connect-program guard could
  refuse it - and refusing it is the point, since a nested fish expands
  `%self` to its pid.
- `rsync:///mod/` silently dialled a host the operator never named. Measured
  against the pinned 3.5.0 binary: upstream fails in `getaddrinfo` with an
  empty node, and refuses the empty host outright under `RSYNC_CONNECT_PROG`
  (an empty argument survives a direct exec but vanishes when a nested shell
  re-splits, shifting every later argument left).
- Trimming is not cosmetic. Measured: `rsync:// localhost /m/` under a connect
  program is refused by upstream as shell-unsafe (space is outside the allowed
  byte set) while oc handed the program a clean `localhost`. Trimming
  converted a host upstream refuses into one it accepts.

An IPv6 zone id (`fe80::1%eth0`) relies on the same literal treatment, which
is why the decoder needed a zone-id fallback to paper over itself.

`DaemonAddress::new` therefore cannot fail and no longer returns `Result`;
its empty-host rejection existed only to be routed around by the `localhost`
default. The CONNECT-header CRLF guard in `proxy.rs` is now the only thing
standing between a hostile host and the request line, and its comment says so.

## Measured

Against the pinned upstream 3.5.0 binary as the control, on Linux:

| cell | before | after | upstream 3.5.0 |
|---|---|---|---|
| `connect-prog-host-quoting` | pass | pass | pass |
| `connect-prog-nested-singlequote-host-injection` | fail | **pass** | pass |

The nested cell needed both this change and #7430; neither flips it alone.
Its four manifest rows flip in this commit.

RED proven by restoring only the `localhost` default: the cell returns to
`overall result is 1`.

⚠ The empty-host parse had no test at all before this - that absence is why
the substitution survived. It is pinned now, with a named-host companion so
the pin cannot pass by everything coming back empty.

- `cargo nextest run -p core --all-features --lib`: 2558/2558 on Linux
- `cargo fmt --all -- --check` and `cargo clippy --workspace --all-targets
  --all-features --no-deps -- -D warnings`: both clean on Linux
oferchen added a commit that referenced this pull request Aug 21, 2026
oc rewrote the daemon host three ways before anything could judge it.
Upstream rewrites it in none of them: `check_for_hostspec` (options.c:3295)
takes the host as written and hands the same bytes to `getaddrinfo`, or, under
`RSYNC_CONNECT_PROG`, to `shell_unsafe_connect_host` (socket.c:204-215).

| rewrite | oc before | upstream |
|---|---|---|
| percent-decode `%XX` in host and username | decoded, and rejected a lone `%` as a malformed escape | no percent-decoder exists anywhere |
| empty authority | substituted `localhost` | stays empty |
| leading/trailing whitespace | trimmed | kept |

Each one is load-bearing in the same direction: the validator can only refuse
what reaches it.

- `%self` was rejected as a bad escape before the connect-program guard could
  refuse it - and refusing it is the point, since a nested fish expands
  `%self` to its pid.
- `rsync:///mod/` silently dialled a host the operator never named. Measured
  against the pinned 3.5.0 binary: upstream fails in `getaddrinfo` with an
  empty node, and refuses the empty host outright under `RSYNC_CONNECT_PROG`
  (an empty argument survives a direct exec but vanishes when a nested shell
  re-splits, shifting every later argument left).
- Trimming is not cosmetic. Measured: `rsync:// localhost /m/` under a connect
  program is refused by upstream as shell-unsafe (space is outside the allowed
  byte set) while oc handed the program a clean `localhost`. Trimming
  converted a host upstream refuses into one it accepts.

An IPv6 zone id (`fe80::1%eth0`) relies on the same literal treatment, which
is why the decoder needed a zone-id fallback to paper over itself.

`DaemonAddress::new` therefore cannot fail and no longer returns `Result`;
its empty-host rejection existed only to be routed around by the `localhost`
default. The CONNECT-header CRLF guard in `proxy.rs` is now the only thing
standing between a hostile host and the request line, and its comment says so.

## Measured

Against the pinned upstream 3.5.0 binary as the control, on Linux:

| cell | before | after | upstream 3.5.0 |
|---|---|---|---|
| `connect-prog-host-quoting` | pass | pass | pass |
| `connect-prog-nested-singlequote-host-injection` | fail | **pass** | pass |

The nested cell needed both this change and #7430; neither flips it alone.
Its four manifest rows flip in this commit.

RED proven by restoring only the `localhost` default: the cell returns to
`overall result is 1`.

⚠ The empty-host parse had no test at all before this - that absence is why
the substitution survived. It is pinned now, with a named-host companion so
the pin cannot pass by everything coming back empty.

- `cargo nextest run -p core --all-features --lib`: 2558/2558 on Linux
- `cargo fmt --all -- --check` and `cargo clippy --workspace --all-targets
  --all-features --no-deps -- -D warnings`: both clean on Linux
oferchen added a commit that referenced this pull request Aug 24, 2026
…7477)

The docs were last refreshed at #7423; 55 PRs have merged since, and the
testsuite figures they quote had drifted far enough to understate the
current state by roughly half.

CHANGELOG: fill in Unreleased for everything merged since #7423. The
dominant theme is routing every operator-named auxiliary file open onto
the ownership walk - upstream's open_no_attacker_symlinks() applied at the
call sites upstream applies it - plus a daemon hardening batch and an
alt-dest correctness batch.

README and SECURITY: the per-leg outcome tables were re-derived from the
committed expect manifests rather than carried forward. Failures fell and
the corpus grew, so every figure moved:

  non-root pipe  43 -> 21 fail   (345 -> 349 corpus)
  root pipe      62 -> 29 fail   (345 -> 349 corpus)
  non-root tcp   42 -> 29 fail   (155 -> 158 corpus)
  root tcp       55 -> 38 fail   (155 -> 158 corpus)

Distinct divergences: 64 -> 31 across the two full-corpus legs, 89 -> 55
across all four.

SECURITY, two CVE rows that had gone stale:
- CVE-2026-53790 said "under audit". The refusal has since been applied at
  the live sink - oc-rsync's own single-character config expander, which
  upstream does not have, so an upstream-shaped port alone would have been
  inert (#7465, #7430, #7445).
- CVE-2026-53795 listed only the staging family. The auxiliary-file family
  followed it onto the walk (#7421-#7426, #7439, #7441-#7443, #7459,
  #7463); what remains is the per-option-family confinement.
oferchen added a commit that referenced this pull request Aug 24, 2026
…7430)

* wip: connect-prog host validation (production only)

* test(core): pin RSYNC_CONNECT_PROG host validation against the upstream cells

Both rows of testsuite/connect-prog-host-quoting_test.py are now covered
directly, and the assertions that recorded the pre-fix unquoted rendering
are inverted rather than deleted: upstream substitutes the single-quoted
host (socket.c:495), so an empty host and a byte outside the allowed set
are refusals, not renderings.

* test(core): quote the two remaining port-boundary expectations

Same defect class as the previous commit; found by sweeping every
format_command call in the module rather than only the one the failing
run named.

* style(core): satisfy rustfmt and clippy on the host-safety helpers

* style(core): match rustfmt's line width on the safe-byte predicate
oferchen added a commit that referenced this pull request Aug 24, 2026
oc rewrote the daemon host three ways before anything could judge it.
Upstream rewrites it in none of them: `check_for_hostspec` (options.c:3295)
takes the host as written and hands the same bytes to `getaddrinfo`, or, under
`RSYNC_CONNECT_PROG`, to `shell_unsafe_connect_host` (socket.c:204-215).

| rewrite | oc before | upstream |
|---|---|---|
| percent-decode `%XX` in host and username | decoded, and rejected a lone `%` as a malformed escape | no percent-decoder exists anywhere |
| empty authority | substituted `localhost` | stays empty |
| leading/trailing whitespace | trimmed | kept |

Each one is load-bearing in the same direction: the validator can only refuse
what reaches it.

- `%self` was rejected as a bad escape before the connect-program guard could
  refuse it - and refusing it is the point, since a nested fish expands
  `%self` to its pid.
- `rsync:///mod/` silently dialled a host the operator never named. Measured
  against the pinned 3.5.0 binary: upstream fails in `getaddrinfo` with an
  empty node, and refuses the empty host outright under `RSYNC_CONNECT_PROG`
  (an empty argument survives a direct exec but vanishes when a nested shell
  re-splits, shifting every later argument left).
- Trimming is not cosmetic. Measured: `rsync:// localhost /m/` under a connect
  program is refused by upstream as shell-unsafe (space is outside the allowed
  byte set) while oc handed the program a clean `localhost`. Trimming
  converted a host upstream refuses into one it accepts.

An IPv6 zone id (`fe80::1%eth0`) relies on the same literal treatment, which
is why the decoder needed a zone-id fallback to paper over itself.

`DaemonAddress::new` therefore cannot fail and no longer returns `Result`;
its empty-host rejection existed only to be routed around by the `localhost`
default. The CONNECT-header CRLF guard in `proxy.rs` is now the only thing
standing between a hostile host and the request line, and its comment says so.

## Measured

Against the pinned upstream 3.5.0 binary as the control, on Linux:

| cell | before | after | upstream 3.5.0 |
|---|---|---|---|
| `connect-prog-host-quoting` | pass | pass | pass |
| `connect-prog-nested-singlequote-host-injection` | fail | **pass** | pass |

The nested cell needed both this change and #7430; neither flips it alone.
Its four manifest rows flip in this commit.

RED proven by restoring only the `localhost` default: the cell returns to
`overall result is 1`.

⚠ The empty-host parse had no test at all before this - that absence is why
the substitution survived. It is pinned now, with a named-host companion so
the pin cannot pass by everything coming back empty.

- `cargo nextest run -p core --all-features --lib`: 2558/2558 on Linux
- `cargo fmt --all -- --check` and `cargo clippy --workspace --all-targets
  --all-features --no-deps -- -D warnings`: both clean on Linux
oferchen added a commit that referenced this pull request Aug 24, 2026
…7477)

The docs were last refreshed at #7423; 55 PRs have merged since, and the
testsuite figures they quote had drifted far enough to understate the
current state by roughly half.

CHANGELOG: fill in Unreleased for everything merged since #7423. The
dominant theme is routing every operator-named auxiliary file open onto
the ownership walk - upstream's open_no_attacker_symlinks() applied at the
call sites upstream applies it - plus a daemon hardening batch and an
alt-dest correctness batch.

README and SECURITY: the per-leg outcome tables were re-derived from the
committed expect manifests rather than carried forward. Failures fell and
the corpus grew, so every figure moved:

  non-root pipe  43 -> 21 fail   (345 -> 349 corpus)
  root pipe      62 -> 29 fail   (345 -> 349 corpus)
  non-root tcp   42 -> 29 fail   (155 -> 158 corpus)
  root tcp       55 -> 38 fail   (155 -> 158 corpus)

Distinct divergences: 64 -> 31 across the two full-corpus legs, 89 -> 55
across all four.

SECURITY, two CVE rows that had gone stale:
- CVE-2026-53790 said "under audit". The refusal has since been applied at
  the live sink - oc-rsync's own single-character config expander, which
  upstream does not have, so an upstream-shaped port alone would have been
  inert (#7465, #7430, #7445).
- CVE-2026-53795 listed only the staging family. The auxiliary-file family
  followed it onto the walk (#7421-#7426, #7439, #7441-#7443, #7459,
  #7463); what remains is the per-option-family confinement.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant