1
mirror of https://github.com/home-assistant/core synced 2024-07-12 07:21:24 +02:00

Check whitelisted paths #13107 (#13154)

This commit is contained in:
Johann Kellerman 2018-03-30 04:57:19 +02:00 committed by Paulus Schoutsen
parent 3e5462ebff
commit 507c658fe9
2 changed files with 9 additions and 4 deletions

View File

@ -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

View File

@ -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)