mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-03 05:51:15 +02:00
Prevent directory traversal
This commit is contained in:
1 parent
2c938b2c19
commit
6294ad9e76
9 files changed
+70
-67
No files matched your search
@@ -37,6 +37,18 @@ def get_default_project_directory():
|
||||
return path
|
||||
|
||||
|
||||
def is_safe_path(file_path, directory):
|
||||
"""
|
||||
Check that file path is safe.
|
||||
(the file is stored inside directory or one of its sub-directory)
|
||||
"""
|
||||
|
||||
requested_path = os.path.relpath(file_path, start=directory)
|
||||
requested_path = os.path.abspath(requested_path)
|
||||
common_prefix = os.path.commonprefix([requested_path, directory])
|
||||
return common_prefix != directory
|
||||
|
||||
|
||||
def check_path_allowed(path):
|
||||
"""
|
||||
If the server is non local raise an error if
|
||||
|
||||
Reference in new issue
Block a user