Skip to content

Commit 75854c1

Browse files
security: fix enforcement of --restrict-to-path in args processing
Fixes CVE-2017-15914 (affects releases 1.1.0, 1.1.1, 1.1.2, but not 1.0.x). Thanks to Florian Apolloner for discovering/reporting this! Also: added tests for this. (cherry picked from commit ea0203b)
1 parent 1cf6e1e commit 75854c1

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/borg/archiver.py

+1
Original file line numberDiff line numberDiff line change
@@ -3806,6 +3806,7 @@ def get_args(self, argv, cmd):
38063806
return forced_result
38073807
# we only take specific options from the forced "borg serve" command:
38083808
result.restrict_to_paths = forced_result.restrict_to_paths
3809+
result.restrict_to_repositories = forced_result.restrict_to_repositories
38093810
result.append_only = forced_result.append_only
38103811
return result
38113812

src/borg/testsuite/archiver.py

+12
Original file line numberDiff line numberDiff line change
@@ -3546,10 +3546,22 @@ def test_get_args():
35463546
assert args.restrict_to_paths == ['/p1', '/p2']
35473547
assert args.umask == 0o027
35483548
assert args.log_level == 'info'
3549+
# similar, but with --restrict-to-repository
3550+
args = archiver.get_args(['borg', 'serve', '--restrict-to-repository=/r1', '--restrict-to-repository=/r2', ],
3551+
'borg serve --info --umask=0027')
3552+
assert args.restrict_to_repositories == ['/r1', '/r2']
35493553
# trying to cheat - break out of path restriction
35503554
args = archiver.get_args(['borg', 'serve', '--restrict-to-path=/p1', '--restrict-to-path=/p2', ],
35513555
'borg serve --restrict-to-path=/')
35523556
assert args.restrict_to_paths == ['/p1', '/p2']
3557+
# trying to cheat - break out of repository restriction
3558+
args = archiver.get_args(['borg', 'serve', '--restrict-to-repository=/r1', '--restrict-to-repository=/r2', ],
3559+
'borg serve --restrict-to-repository=/')
3560+
assert args.restrict_to_repositories == ['/r1', '/r2']
3561+
# trying to cheat - break below repository restriction
3562+
args = archiver.get_args(['borg', 'serve', '--restrict-to-repository=/r1', '--restrict-to-repository=/r2', ],
3563+
'borg serve --restrict-to-repository=/r1/below')
3564+
assert args.restrict_to_repositories == ['/r1', '/r2']
35533565
# trying to cheat - try to execute different subcommand
35543566
args = archiver.get_args(['borg', 'serve', '--restrict-to-path=/p1', '--restrict-to-path=/p2', ],
35553567
'borg init --encryption=repokey /')

0 commit comments

Comments
 (0)