parent
78f3e01854
commit
9fc8a8f679
2 changed files with 9 additions and 4 deletions
|
@ -1060,15 +1060,19 @@ class Config(object):
|
|||
"""Check if the path is valid for access from outside."""
|
||||
assert path is not None
|
||||
|
||||
parent = pathlib.Path(path)
|
||||
thepath = pathlib.Path(path)
|
||||
try:
|
||||
parent = parent.resolve() # pylint: disable=no-member
|
||||
# The file path does not have to exist (it's parent should)
|
||||
if thepath.exists():
|
||||
thepath = thepath.resolve()
|
||||
else:
|
||||
thepath = thepath.parent.resolve()
|
||||
except (FileNotFoundError, RuntimeError, PermissionError):
|
||||
return False
|
||||
|
||||
for whitelisted_path in self.whitelist_external_dirs:
|
||||
try:
|
||||
parent.relative_to(whitelisted_path)
|
||||
thepath.relative_to(whitelisted_path)
|
||||
return True
|
||||
except ValueError:
|
||||
pass
|
||||
|
|
|
@ -809,7 +809,8 @@ class TestConfig(unittest.TestCase):
|
|||
|
||||
valid = [
|
||||
test_file,
|
||||
tmp_dir
|
||||
tmp_dir,
|
||||
os.path.join(tmp_dir, 'notfound321')
|
||||
]
|
||||
for path in valid:
|
||||
assert self.config.is_allowed_path(path)
|
||||
|
|
Loading…
Add table
Reference in a new issue