file_manager: always deny access to .git folders

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
Eric Callahan 2022-11-06 07:21:48 -05:00
parent d490796da9
commit a8018afd46
No known key found for this signature in database
GPG Key ID: 5A1EB336DFB4C71B
1 changed files with 16 additions and 11 deletions

View File

@ -251,6 +251,8 @@ class FileManager:
if isinstance(req_path, str):
req_path = pathlib.Path(req_path)
req_path = req_path.expanduser().resolve()
if ".git" in req_path.parts:
return True
for name, (res_path, can_read) in self.reserved_paths.items():
if (
(res_path == req_path or res_path in req_path.parents) and
@ -543,18 +545,21 @@ class FileManager:
path = pathlib.Path(path)
real_path = path.resolve()
fstat = path.stat()
permissions = "rw"
if (
root not in self.full_access_roots or
(path.is_symlink() and path.is_file())
):
permissions = "r"
for name, (res_path, can_read) in self.reserved_paths.items():
if (res_path == real_path or res_path in real_path.parents):
if not can_read:
permissions = ""
break
if ".git" in real_path.parts:
permissions = ""
else:
permissions = "rw"
if (
root not in self.full_access_roots or
(path.is_symlink() and path.is_file())
):
permissions = "r"
for name, (res_path, can_read) in self.reserved_paths.items():
if (res_path == real_path or res_path in real_path.parents):
if not can_read:
permissions = ""
break
permissions = "r"
return {
'modified': fstat.st_mtime,
'size': fstat.st_size,