Skip to content

test: port link-dest module-escape rejection to nextest - #5900

Merged
oferchen merged 1 commit into
masterfrom
test/uts-nextest-link-dest-module-escape
Jun 17, 2026
Merged

oferchen merged 1 commit into
masterfrom
test/uts-nextest-link-dest-module-escape

Conversation

@oferchen

Copy link
Copy Markdown
Owner

Summary

Pin the daemon's --link-dest / --copy-dest / --compare-dest path-validation invariant against four module-escape scenarios drawn from the upstream alt-dest-symlink-race.test / link-dest-module-escape security pin. The tests extend the existing unit-test suite for confine_basis_under_module in crates/daemon/src/daemon/sections/module_access/tests.rs (alongside confine_basis_drops_absolute_out_of_module, _dotdot_escape_to_sibling, etc.) so the daemon's basedir-confinement contract runs on every PR via the standard nextest matrix.

Scenarios pinned

  • negative (relative escape) - confine_basis_link_dest_relative_etc_passwd_escape_is_dropped: client sends --link-dest=../etc/passwd from a dest at the module root; the lexical normalisation collapses past the module root and starts_with(module_root) rejects.
  • negative (in-module symlink trap, Unix only) - confine_basis_link_dest_in_module_symlink_to_outside_is_dropped: ports the exact attack shape from upstream alt-dest-symlink-race.test. An in-module symlink mod/cd -> /outside used as --link-dest=cd canonicalises out of the module root and is dropped before the receiver's basis-file lookup can hard-link to attacker-readable files outside the module.
  • negative (absolute escape) - confine_basis_link_dest_absolute_etc_passwd_is_dropped: absolute --link-dest pointing outside the module root is dropped via the canonicalise-with-lexical-fallback containment check.
  • positive control - confine_basis_link_dest_relative_in_module_sibling_is_accepted: relative --link-dest=../01 from dest/00/ survives as a legitimate basis, matching upstream main.c:1199-1206's check_alt_basis_dirs() after get_local_name() chdir's into the dest.

Lineage

  • Upstream test: target/interop/upstream-src/rsync-3.4.4/testsuite/alt-dest-symlink-race.test (the link-dest-module-escape family; named alt-dest-symlink-race.test in 3.4.3+).
  • Production defence: PR fix(daemon): silently drop out-of-module --link-dest/--copy-dest paths #5778 fix(daemon): silently drop out-of-module --link-dest/--copy-dest paths, extended via URV-5.b.1.c to inspect all three --{link,copy,compare}-dest flags through validate_client_paths_in_module / confine_basis_under_module in crates/daemon/src/daemon/sections/module_access/{transfer,client_args}.rs.

Note on divergence from the upstream test's literal error string

Upstream rsync's daemon does NOT emit a literal "outside the module" @ERROR for these scenarios. Its util1.c:1035 sanitize_path collapses .. against the module root depth (rewriting the path under the module) and main.c:841 check_alt_basis_dirs only warns when the resulting basis is missing or out-of-tree. PR #5778 aligned the oc-rsync daemon with that contract by switching from a hard @ERROR reject to a silent drop. These tests pin the silent-drop contract so a future regression to either the old @ERROR reject path or to admission of the escape cannot ship.

Test plan

  • cargo fmt --all -- --check clean locally
  • CI nextest (stable) - new unit tests run inside the daemon crate's module_access_tests module
  • CI Windows / macOS / Linux musl - the symlink trap test is #[cfg(unix)]; the other three are portable and exercise the same confine_basis_under_module invariant on every platform

Pin the daemon's `--link-dest` / `--copy-dest` / `--compare-dest`
path-validation invariant against four module-escape scenarios drawn
from the upstream `alt-dest-symlink-race.test` / `link-dest-module-
escape` security pin:

- relative `--link-dest=../etc/passwd` from a dest at the module root
  must be silently dropped (lexical climb past the module root);
- relative in-module sibling `--link-dest=../01` from `dest/00/`
  must survive as a legitimate basis (positive control matching
  upstream `main.c:1199-1206`);
- an in-module symlink `mod/cd -> /outside` used as `--link-dest=cd`
  must canonicalise out of the module root and be dropped (the exact
  attack shape from upstream `alt-dest-symlink-race.test`);
- an absolute `--link-dest` pointing outside the module root must be
  dropped (canonicalise-with-lexical-fallback branch).

The tests exercise `confine_basis_under_module`, the daemon-side
defence introduced in PR #5778 / extended via URV-5.b.1.c. They lock
in the silent-drop contract upstream `util1.c:1035 sanitize_path` and
`main.c:841 check_alt_basis_dirs` model, guarding against a future
regression to either a hard `@ERROR` reject or admission of the
escape into `cfg.reference_directories`.
@oferchen
oferchen force-pushed the test/uts-nextest-link-dest-module-escape branch from 87751cd to 06623d5 Compare June 17, 2026 19:31
@oferchen
oferchen merged commit bb68d3d into master Jun 17, 2026
@github-actions github-actions Bot added the test label Jun 17, 2026
@oferchen
oferchen deleted the test/uts-nextest-link-dest-module-escape branch June 17, 2026 19:33
oferchen added a commit that referenced this pull request Aug 24, 2026
Pin the daemon's `--link-dest` / `--copy-dest` / `--compare-dest`
path-validation invariant against four module-escape scenarios drawn
from the upstream `alt-dest-symlink-race.test` / `link-dest-module-
escape` security pin:

- relative `--link-dest=../etc/passwd` from a dest at the module root
  must be silently dropped (lexical climb past the module root);
- relative in-module sibling `--link-dest=../01` from `dest/00/`
  must survive as a legitimate basis (positive control matching
  upstream `main.c:1199-1206`);
- an in-module symlink `mod/cd -> /outside` used as `--link-dest=cd`
  must canonicalise out of the module root and be dropped (the exact
  attack shape from upstream `alt-dest-symlink-race.test`);
- an absolute `--link-dest` pointing outside the module root must be
  dropped (canonicalise-with-lexical-fallback branch).

The tests exercise `confine_basis_under_module`, the daemon-side
defence introduced in PR #5778 / extended via URV-5.b.1.c. They lock
in the silent-drop contract upstream `util1.c:1035 sanitize_path` and
`main.c:841 check_alt_basis_dirs` model, guarding against a future
regression to either a hard `@ERROR` reject or admission of the
escape into `cfg.reference_directories`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant