nathanwilliams-ct commented on issue #2178:
URL: https://github.com/apache/buildstream/issues/2178#issuecomment-5328826912
It might be worth switching Buildstream to using PathLib instead of raw
strings for all paths in buildstream, as it will make it much easier to handle
the paths?
```
_basedir = Path('elements')
target = '../../bananas/my_element.bst'
element_path = (_basedir / target).resolve()
try:
element_path.relative_to(_basedir.resolve())
except ValueError as e:
# Handle the directory traversal Error
```
old way, with os path:
```
_basedir = 'elements'
target = '../../bananas/my_element.bst'
element_path = os.path.join(_basedir, target)
actual_basedir = os.path.realpath(_basedir)
actual_element_path = os.path.realpath(element_path)
if os.path.commonprefix(actual_element_path,actual_basedir) !=
actual_basedir:
# Handle the directory traversal Error
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]