Skip to content

is_allowed_path() incorrectly returning False #12807

@robmarkcole

Description

@robmarkcole

https://github.com/home-assistant/home-assistant/blob/6ee3c1b3e57ff12ec27a9e466518d8ccf3e11efe/homeassistant/core.py#L1063

This function is returning False for valid paths as raised in #12788. I've extracted the responsible code below to illustrate:

path = '/Users/robincole/.homeassistant'  # Assume this is whitelisted
pathlib.Path(path).is_dir() # Returns True
parent = pathlib.Path(path).parent 
parent.relative_to(path)

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-29-e4a2522c8d67> in <module>()
      1 path = '/Users/robincole/.homeassistant'  # Assume this is whitelisted
      2 parent = pathlib.Path(path).parent
----> 3 parent.relative_to(path)

/anaconda3/lib/python3.6/pathlib.py in relative_to(self, *other)
    868             formatted = self._format_parsed_parts(to_drv, to_root, to_parts)
    869             raise ValueError("{!r} does not start with {!r}"
--> 870                              .format(str(self), str(formatted)))
    871         return self._from_parsed_parts('', root if n == 1 else '',
    872                                        abs_parts[n:])

ValueError: '/Users/robincole' does not start with '/Users/robincole/.homeassistant'

I believe @pvizeli last edited this code.
Cheers

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions