def validate_absolute_path(self, root, absolute_path):
"""
Validate and return the absolute path.
Credit:
https://github.com/tornadoweb/tornado/blob/master/tornado/web.py
"""
root = os.path.abspath(root)
if not root.endswith(os.path.sep):
root += os.path.sep
if not (absolute_path + os.path.sep).startswith(root):
# Only files under the specified root can be accessed
raise HTTPError(403, "%s is not in the root directory", self.path)
if not os.path.exists(absolute_path):
raise HTTPError(404)
if not os.path.isfile(absolute_path):
raise HTTPError(403, "%s is not a file", self.path)
return absolute_path
评论列表
文章目录