File tree Expand file tree Collapse file tree 1 file changed +15
-2
lines changed
Expand file tree Collapse file tree 1 file changed +15
-2
lines changed Original file line number Diff line number Diff line change 1414 process_gain as _process_gain ,
1515)
1616from murfey .server .murfey_db import murfey_db
17+ from murfey .util import secure_path
1718from murfey .util .config import get_machine_config
1819from murfey .util .db import Session
1920
@@ -51,10 +52,22 @@ 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 = secure_path (
56+ rsync_basepath / symlink_params .symlink , keep_spaces = True
57+ )
58+ # Verify that the symlink provided does not lead elsewhere
59+ if not symlink_full_path .resolve ().is_relative_to (rsync_basepath ):
60+ logger .warning (
61+ "Symlink rejected because it will be created in a forbidden location"
62+ )
63+ return ""
64+ # Remove and replace symlink if it exists are 'override' is set
5565 if symlink_full_path .is_symlink () and symlink_params .override :
5666 symlink_full_path .unlink ()
67+ # If a file/folder already exists using the desired symlink name, return empty string
5768 if symlink_full_path .exists ():
5869 return ""
59- symlink_full_path .symlink_to (rsync_basepath / symlink_params .target )
70+ symlink_full_path .symlink_to (
71+ secure_path (rsync_basepath / symlink_params .target , keep_spaces = True )
72+ )
6073 return str (symlink_params .symlink )
You can’t perform that action at this time.
0 commit comments