Fix static mounts using relative paths and prevent traversal exploits (#554)

Thanks, @abdusco! Closes #555
This commit is contained in:
Abdus 2019-07-11 19:13:19 +03:00 committed by Simon Willison
commit 74ecf8a7cc
3 changed files with 9 additions and 2 deletions

View file

@ -735,7 +735,8 @@ class StaticMount(click.ParamType):
param,
ctx,
)
path, dirpath = value.split(":")
path, dirpath = value.split(":", 1)
dirpath = os.path.abspath(dirpath)
if not os.path.exists(dirpath) or not os.path.isdir(dirpath):
self.fail("%s is not a valid directory path" % value, param, ctx)
return path, dirpath