Skip to content

Commit 85d91c9

Browse files
committed
Sanitise symlink path and verify that it's relative to 'rsync_basepath'
1 parent 09d3241 commit 85d91c9

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/murfey/server/api/file_io_frontend.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
process_gain as _process_gain,
1515
)
1616
from murfey.server.murfey_db import murfey_db
17+
from murfey.util import sanitise_path
1718
from murfey.util.config import get_machine_config
1819
from murfey.util.db import Session
1920

@@ -51,9 +52,17 @@ async def create_symlink(
5152
instrument_name
5253
]
5354
rsync_basepath = (machine_config.rsync_basepath or Path("")).resolve()
54-
symlink_full_path = rsync_basepath / symlink_params.symlink
55+
symlink_full_path = sanitise_path(rsync_basepath / symlink_params.symlink)
56+
# Verify that the symlink provided does not lead elsewhere
57+
if not symlink_full_path.resolve().is_relative_to(rsync_basepath):
58+
logger.warning(
59+
"Symlink rejected because it will be created in a forbidden location"
60+
)
61+
return ""
62+
# Remove and replace symlink if it exists are 'override' is set
5563
if symlink_full_path.is_symlink() and symlink_params.override:
5664
symlink_full_path.unlink()
65+
# If a file/folder already exists using the desired symlink name, return empty string
5766
if symlink_full_path.exists():
5867
return ""
5968
symlink_full_path.symlink_to(rsync_basepath / symlink_params.target)

0 commit comments

Comments
 (0)