Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions homeassistant/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1060,15 +1060,19 @@ def is_allowed_path(self, path: str) -> bool:
"""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
Expand Down
3 changes: 2 additions & 1 deletion tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -809,7 +809,8 @@ def test_is_allowed_path(self):

valid = [
test_file,
tmp_dir
tmp_dir,
os.path.join(tmp_dir, 'notfound321')
]
for path in valid:
assert self.config.is_allowed_path(path)
Expand Down