Merge pull request #2061 from imachug/dotdot
Allow some paths to contain .. but not ../
This commit is contained in:
commit
f83ade8d33
2 changed files with 3 additions and 3 deletions
|
@ -382,7 +382,7 @@ class SiteStorage(object):
|
||||||
if not inner_path:
|
if not inner_path:
|
||||||
return self.directory
|
return self.directory
|
||||||
|
|
||||||
if ".." in inner_path:
|
if "../" in inner_path:
|
||||||
raise Exception("File not allowed: %s" % inner_path)
|
raise Exception("File not allowed: %s" % inner_path)
|
||||||
|
|
||||||
return "%s/%s" % (self.directory, inner_path)
|
return "%s/%s" % (self.directory, inner_path)
|
||||||
|
|
|
@ -524,7 +524,7 @@ class UiRequest(object):
|
||||||
if path.endswith("/"):
|
if path.endswith("/"):
|
||||||
path = path + "index.html"
|
path = path + "index.html"
|
||||||
|
|
||||||
if ".." in path or "./" in path:
|
if "../" in path or "./" in path:
|
||||||
raise SecurityError("Invalid path")
|
raise SecurityError("Invalid path")
|
||||||
|
|
||||||
match = re.match(r"/media/(?P<address>[A-Za-z0-9]+[A-Za-z0-9\._-]+)(?P<inner_path>/.*|$)", path)
|
match = re.match(r"/media/(?P<address>[A-Za-z0-9]+[A-Za-z0-9\._-]+)(?P<inner_path>/.*|$)", path)
|
||||||
|
@ -603,7 +603,7 @@ class UiRequest(object):
|
||||||
if match: # Looks like a valid path
|
if match: # Looks like a valid path
|
||||||
file_path = "src/Ui/media/%s" % match.group("inner_path")
|
file_path = "src/Ui/media/%s" % match.group("inner_path")
|
||||||
allowed_dir = os.path.abspath("src/Ui/media") # Only files within data/sitehash allowed
|
allowed_dir = os.path.abspath("src/Ui/media") # Only files within data/sitehash allowed
|
||||||
if ".." in file_path or not os.path.dirname(os.path.abspath(file_path)).startswith(allowed_dir):
|
if "../" in file_path or not os.path.dirname(os.path.abspath(file_path)).startswith(allowed_dir):
|
||||||
# File not in allowed path
|
# File not in allowed path
|
||||||
return self.error403()
|
return self.error403()
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in a new issue