55from PIL import Image
66from sqlalchemy .exc import NoResultFound
77from sqlmodel import Session , select
8- from werkzeug .utils import secure_filename
98
109from murfey .server import _murfey_id , _transport_object , sanitise
1110from murfey .server .api .auth import MurfeySessionID
11+ from murfey .util import secure_path
1212from murfey .util .config import get_machine_config , get_microscope
1313from murfey .util .db import (
1414 AutoProcProgram ,
@@ -72,11 +72,8 @@ def register_grid_square(
7272 else :
7373 # mock up response so that below still works
7474 gs_ispyb_response = {"success" : False , "return_value" : None }
75- secured_grid_square_image_path = secure_filename (grid_square_params .image )
76- if (
77- secured_grid_square_image_path
78- and Path (secured_grid_square_image_path ).is_file ()
79- ):
75+ secured_grid_square_image_path = secure_path (Path (grid_square_params .image ))
76+ if secured_grid_square_image_path and secured_grid_square_image_path .is_file ():
8077 jpeg_size = Image .open (secured_grid_square_image_path ).size
8178 else :
8279 jpeg_size = (0 , 0 )
@@ -98,7 +95,7 @@ def register_grid_square(
9895 thumbnail_size_x = grid_square_params .thumbnail_size_x or jpeg_size [0 ],
9996 thumbnail_size_y = grid_square_params .thumbnail_size_y or jpeg_size [1 ],
10097 pixel_size = grid_square_params .pixel_size ,
101- image = secured_grid_square_image_path ,
98+ image = str ( secured_grid_square_image_path ) ,
10299 )
103100 murfey_db .add (grid_square )
104101 murfey_db .commit ()
@@ -124,8 +121,8 @@ def register_foil_hole(
124121 f"Foil hole { sanitise (str (foil_hole_params .name ))} could not be registered as grid square { sanitise (str (gs_name ))} was not found"
125122 )
126123 return
127- secured_foil_hole_image_path = secure_filename ( foil_hole_params .image )
128- if foil_hole_params .image and Path ( secured_foil_hole_image_path ) .is_file ():
124+ secured_foil_hole_image_path = secure_path ( Path ( foil_hole_params .image ) )
125+ if foil_hole_params .image and secured_foil_hole_image_path .is_file ():
129126 jpeg_size = Image .open (secured_foil_hole_image_path ).size
130127 else :
131128 jpeg_size = (0 , 0 )
@@ -188,7 +185,7 @@ def register_foil_hole(
188185 thumbnail_size_x = foil_hole_params .thumbnail_size_x or jpeg_size [0 ],
189186 thumbnail_size_y = foil_hole_params .thumbnail_size_y or jpeg_size [1 ],
190187 pixel_size = foil_hole_params .pixel_size ,
191- image = secured_foil_hole_image_path ,
188+ image = str ( secured_foil_hole_image_path ) ,
192189 )
193190 murfey_db .add (foil_hole )
194191 murfey_db .commit ()
0 commit comments