Skip to content

Commit 4ad0236

Browse files
committed
Verify that the symlink path requested lives under the 'rsync_basepath'
1 parent 09d3241 commit 4ad0236

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/murfey/server/api/file_io_frontend.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,16 @@ async def create_symlink(
5252
]
5353
rsync_basepath = (machine_config.rsync_basepath or Path("")).resolve()
5454
symlink_full_path = rsync_basepath / symlink_params.symlink
55+
# Verify that the symlink provided does not lead elsewhere
56+
if not symlink_full_path.resolve().is_relative_to(rsync_basepath):
57+
logger.warning(
58+
"Symlink rejected because it will be created in a forbidden location"
59+
)
60+
return ""
61+
# Remove and replace symlink if it exists are 'override' is set
5562
if symlink_full_path.is_symlink() and symlink_params.override:
5663
symlink_full_path.unlink()
64+
# If a file/folder already exists using the desired symlink name, return empty string
5765
if symlink_full_path.exists():
5866
return ""
5967
symlink_full_path.symlink_to(rsync_basepath / symlink_params.target)

0 commit comments

Comments
 (0)