Debian Codegraph @

testsuite/symlink-exclude_test.py

raw symbols SCIP
1 #!/usr/bin/env python3
2 # The daemon exclude/filter is a NAME-based listing/tamper filter, not a
3 # physical-path security boundary: a peer that pushes through an in-module symlink
4 # whose own name is not excluded reaches the excluded target. This is the
5 # behaviour of stock rsync (verified against 3.2.7) and is documented in
6 # rsyncd.conf(5) -- the symlink defense is `munge symlinks` (default on for a
7 # writable non-chroot module), NOT the filter. This test asserts that
8 # 3.2.7-equivalent behaviour: the symlink IS followed.
9
10 import os
11 import subprocess
12
13 from rsyncfns import (
14 SCRATCHDIR, rmtree, rsync_argv, start_test_daemon, test_fail, write_daemon_conf,
15 )
16
17 DAEMON_PORT = 12962
18
19 base = SCRATCHDIR / 'symlink-exclude-daemon'
20 rmtree(base)
21 base.mkdir()
22
23 mod = base / 'mod'
24 mod.mkdir()
25
26 secret = mod / 'secret'
27 secret.mkdir(parents=True)
28 victim = secret / 'f0'
29 victim.write_text("OLD-EXCLUDED-CONTENT\n")
30 src = mod / 'src'
31 src.mkdir()
32 (src / 'f0').write_text("NEW\n")
33
34 blink = mod / 'blink' # in-module symlink -> excluded subtree
35 os.symlink('secret/', blink)
36
37 conf = write_daemon_conf(
38 [('mod', {'path': str(mod), 'read only': 'no', 'exclude': '/secret/'})])
39 url = start_test_daemon(conf, DAEMON_PORT)
40
41 # Push through the symlink whose own name ("blink") is not excluded.
42 subprocess.run(
43 rsync_argv('-a', f'{src}/', f'{url}mod/blink/'),
44 stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
45
46 after = victim.read_text() if victim.exists() else None
47 if after != "NEW\n":
48 test_fail(
49 "the daemon refused a symlink that stock rsync (3.2.7) follows: "
50 f"{secret / 'f0'} is {after!r}, expected 'NEW\\n'. The daemon exclude "
51 "filter is name-based, not a symlink boundary -- it must not block this "
52 "(use `munge symlinks` to defend a writable module).")
53 print("daemon exclude is name-based: a symlink whose name is not excluded is "
54 "followed (3.2.7-equivalent)")