| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
import os |
| 16 |
import subprocess |
| 17 |
|
| 18 |
from rsyncfns import ( |
| 19 |
SCRATCHDIR, rmtree, rsync_argv, run_rrsync_denied, test_fail, |
| 20 |
) |
| 21 |
|
| 22 |
SECRET = 'OUTSIDE-SECRET-readable-by-the-rrsync-account\n' |
| 23 |
|
| 24 |
base = SCRATCHDIR / 'rrsync-copy-unsafe' |
| 25 |
rmtree(base) |
| 26 |
served = base / 'restricted' |
| 27 |
outside = base / 'outside' |
| 28 |
served.mkdir(parents=True) |
| 29 |
outside.mkdir() |
| 30 |
(outside / 'secret').write_text(SECRET) |
| 31 |
|
| 32 |
os.symlink('../outside/secret', served / 'leak') |
| 33 |
|
| 34 |
|
| 35 |
dest = base / 'dest' |
| 36 |
dest.mkdir() |
| 37 |
subprocess.run(rsync_argv('-a', '--copy-unsafe-links', f'{served}/', f'{dest}/'), |
| 38 |
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) |
| 39 |
leaked = dest / 'leak' |
| 40 |
if not (leaked.is_file() and not leaked.is_symlink() and leaked.read_text() == SECRET): |
| 41 |
test_fail("premise check failed: --copy-unsafe-links should turn the escaping " |
| 42 |
"symlink into a regular file holding the outside secret") |
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
run_rrsync_denied('rsync --server --sender --copy-unsafe-links . .', |
| 47 |
'option --copy-unsafe-links has been disabled') |
| 48 |
|
| 49 |
print("rrsync-copy-unsafe-links: --copy-unsafe-links exfiltrates outside symlink " |
| 50 |
"targets; restricted rrsync refuses it") |