parent
3e5462ebff
commit
507c658fe9
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."""
|
"""Check if the path is valid for access from outside."""
|
||||||
assert path is not None
|
assert path is not None
|
||||||
|
|
||||||
parent = pathlib.Path(path)
|
thepath = pathlib.Path(path)
|
||||||
try:
|
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):
|
except (FileNotFoundError, RuntimeError, PermissionError):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
for whitelisted_path in self.whitelist_external_dirs:
|
for whitelisted_path in self.whitelist_external_dirs:
|
||||||
try:
|
try:
|
||||||
parent.relative_to(whitelisted_path)
|
thepath.relative_to(whitelisted_path)
|
||||||
return True
|
return True
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -809,7 +809,8 @@ class TestConfig(unittest.TestCase):
|
||||||
|
|
||||||
valid = [
|
valid = [
|
||||||
test_file,
|
test_file,
|
||||||
tmp_dir
|
tmp_dir,
|
||||||
|
os.path.join(tmp_dir, 'notfound321')
|
||||||
]
|
]
|
||||||
for path in valid:
|
for path in valid:
|
||||||
assert self.config.is_allowed_path(path)
|
assert self.config.is_allowed_path(path)
|
||||||
|
|
Loading…
Add table
Reference in a new issue