Repository navigation
fix: apply munge symlinks prefix/strip in transfer paths - #5527
Merged
Merged
Conversation
2 tasks
Daemon modules with `munge symlinks = yes` were parsed correctly but the prefix/strip logic was missing from the transfer path. The on-disk symlink written by the receiver never carried the `/rsyncd-munged/` prefix, and the sender never stripped it when reading source symlinks, so a push/pull through the daemon silently bypassed upstream's anti-escape guard. Wire the daemon's `effective_munge_symlinks()` into `ServerConfig`, strip the prefix in `GeneratorContext::create_entry` after `read_link()`, and prepend it in `ReceiverContext::create_symlinks` before the `symlinkat` write so the quick-check comparison and the create syscall both see the munged form. Upstream reference: - `clientserver.c:992-1004` - daemon resolves `munge_symlinks` from `lp_munge_symlinks()` and `!use_chroot` auto default - `flist.c:222-226` - sender strips `SYMLINK_PREFIX` after `readlink()` - `flist.c:1122-1126` - receiver prepends `SYMLINK_PREFIX` to wire target - `rsync.h:36` - `SYMLINK_PREFIX "/rsyncd-munged/"` (15 bytes) Strict-length guard mirrors `llen > SYMLINK_PREFIX_LEN` so a target whose entire content is the prefix passes through unchanged. Receiver-side prefix helper preserves non-UTF-8 bytes on Unix via `OsStrExt`; safe-link evaluation continues to run against the pre-munge wire target so the policy decision matches upstream ordering. Regression tests cover both directions on Unix: receiver writes the prefixed target to disk, sender restores the original target after `readlink()`, plus negative controls verifying the bit is strictly opt-in.
The up:symlinks standalone test sets `use chroot = false` without an
explicit `munge symlinks` directive. With munge-symlinks now wired into
the transfer path, the auto-default of `!use_chroot` enables munging and
the receiver writes `/rsyncd-munged/target.txt` instead of `target.txt`.
This mirrors upstream's clientserver.c:992-1004 policy:
if ((munge_symlinks = lp_munge_symlinks(module_id)) < 0)
munge_symlinks = !use_chroot || module_dirlen;
The parallel oc:symlinks test already sets `munge symlinks = false`
against the upstream daemon for the same reason. Match that config on
the oc-rsync daemon side so both directions exercise the non-munged
path.
The comprehensive interop daemon config used 'use chroot = false' without an explicit 'munge symlinks' directive. Under upstream's auto default (!use_chroot || module_dirlen) this resolves to munging on, so symlink fixtures arrived as /rsyncd-munged/hello.txt on the receiver and failed the up:symlinks / up:inc-recursive-symlinks quick-check against the source's bare hello.txt. Pin the directive to false so the shared rust daemon config matches the upstream sibling helper and the standalone symlink test configs already do. upstream: clientserver.c:992-993 - munge_symlinks = !use_chroot when the per-module directive is unset.
oferchen
force-pushed
the
fix/uts-11-daemon-munge-symlinks
branch
from
June 10, 2026 11:10
ed519d7 to
f424304
Compare
oferchen
added a commit
that referenced
this pull request
Aug 24, 2026
* fix: apply munge symlinks prefix/strip in transfer paths
Daemon modules with `munge symlinks = yes` were parsed correctly but the
prefix/strip logic was missing from the transfer path. The on-disk symlink
written by the receiver never carried the `/rsyncd-munged/` prefix, and the
sender never stripped it when reading source symlinks, so a push/pull
through the daemon silently bypassed upstream's anti-escape guard.
Wire the daemon's `effective_munge_symlinks()` into `ServerConfig`, strip
the prefix in `GeneratorContext::create_entry` after `read_link()`, and
prepend it in `ReceiverContext::create_symlinks` before the `symlinkat`
write so the quick-check comparison and the create syscall both see the
munged form.
Upstream reference:
- `clientserver.c:992-1004` - daemon resolves `munge_symlinks` from
`lp_munge_symlinks()` and `!use_chroot` auto default
- `flist.c:222-226` - sender strips `SYMLINK_PREFIX` after `readlink()`
- `flist.c:1122-1126` - receiver prepends `SYMLINK_PREFIX` to wire target
- `rsync.h:36` - `SYMLINK_PREFIX "/rsyncd-munged/"` (15 bytes)
Strict-length guard mirrors `llen > SYMLINK_PREFIX_LEN` so a target whose
entire content is the prefix passes through unchanged. Receiver-side
prefix helper preserves non-UTF-8 bytes on Unix via `OsStrExt`; safe-link
evaluation continues to run against the pre-munge wire target so the
policy decision matches upstream ordering.
Regression tests cover both directions on Unix: receiver writes the
prefixed target to disk, sender restores the original target after
`readlink()`, plus negative controls verifying the bit is strictly
opt-in.
* test: set munge symlinks = false in up:symlinks interop config
The up:symlinks standalone test sets `use chroot = false` without an
explicit `munge symlinks` directive. With munge-symlinks now wired into
the transfer path, the auto-default of `!use_chroot` enables munging and
the receiver writes `/rsyncd-munged/target.txt` instead of `target.txt`.
This mirrors upstream's clientserver.c:992-1004 policy:
if ((munge_symlinks = lp_munge_symlinks(module_id)) < 0)
munge_symlinks = !use_chroot || module_dirlen;
The parallel oc:symlinks test already sets `munge symlinks = false`
against the upstream daemon for the same reason. Match that config on
the oc-rsync daemon side so both directions exercise the non-munged
path.
* test: disable munge symlinks in shared rust daemon interop config
The comprehensive interop daemon config used 'use chroot = false' without an explicit 'munge symlinks' directive. Under upstream's auto default (!use_chroot || module_dirlen) this resolves to munging on, so symlink fixtures arrived as /rsyncd-munged/hello.txt on the receiver and failed the up:symlinks / up:inc-recursive-symlinks quick-check against the source's bare hello.txt. Pin the directive to false so the shared rust daemon config matches the upstream sibling helper and the standalone symlink test configs already do.
upstream: clientserver.c:992-993 - munge_symlinks = !use_chroot when the per-module directive is unset.
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.
Summary
Task UTS-11 (#3574). The daemon's
munge symlinksdirective was parsed andstored on
ModuleDefinition::munge_symlinks: Option<bool>, but the actualprefix/strip transform was missing from the transfer path. Push and pull
through a module configured with
munge symlinks = yessilently bypassedupstream's anti-escape guard - the on-disk symlink written by the receiver
never carried the
/rsyncd-munged/prefix, and the sender never strippedit when reading source symlinks.
ModuleRuntime::effective_munge_symlinks()intoServerConfig.munge_symlinksalongside the existingfake_superwiring(
crates/daemon/src/daemon/sections/module_access/client_args.rs:292-297).GeneratorContext::create_entryafterread_link()so the wire target matches the unmunged source path(
crates/transfer/src/generator/file_list/entry.rs:82-94, 375-407).ReceiverContext::create_symlinksbeforethe
symlinkatwrite so the quick-check comparison and the create syscallboth see the munged form
(
crates/transfer/src/receiver/directory/links.rs:75-86, 444-465).Upstream reference
clientserver.c:992-1004- daemon resolvesmunge_symlinksfromlp_munge_symlinks()and the!use_chroot || module_dirlenauto default.flist.c:222-226- sender stripsSYMLINK_PREFIXafterreadlink(),guarded by
llen > SYMLINK_PREFIX_LEN.flist.c:1122-1126- receiver prependsSYMLINK_PREFIXto the wiretarget when storing the symlink in the file list.
rsync.h:36-#define SYMLINK_PREFIX "/rsyncd-munged/"(15 bytes).The strip helper mirrors the strict
llen > SYMLINK_PREFIX_LENguard so atarget whose entire content is the 15-byte prefix passes through
unchanged - matching upstream's
strncmpbranch byte-for-byte. Thereceiver-side prepend uses
OsStrExt::as_byteson Unix so non-UTF-8targets keep their raw bytes; the safe-link check continues to evaluate
the pre-munge wire target so the policy decision matches upstream
ordering.
Wiring audit findings
ModuleDefinition::munge_symlinks: Option<bool>andeffective_munge_symlinks()(auto =!use_chroot) were already inplace at
crates/daemon/src/daemon/module_state/definition.rs:54-56, 273-275.metadata::munge_symlink/unmunge_symlink/SYMLINK_MUNGE_PREFIXwere already exported and exercised by thelocal-copy executor at
crates/engine/src/local_copy/executor/special/symlink.rs:120-150, 402-409.and the transfer layer (
ServerConfig.munge_symlinks+ sender/receivercall sites).
Cross-platform
#[cfg(unix)]; the matchingcreate_symlinksis already Unix-only with a no-op fallback forWindows.
bytes; on non-Unix it falls back to UTF-8 since
read_linkalreadyrejects non-UTF-8 paths on those platforms.
Test plan
crates/transfer/src/generator/file_list/entry.rs::munge_strip_tests>guard)crates/transfer/src/generator/file_list/entry.rs::munge_symlinks_tests/rsyncd-munged/before encoding the file list entrycrates/transfer/src/receiver/tests/munge_symlinks.rsdaemon_safe_links_receivetest (usesmunge symlinks = false).