@@ -58,7 +58,10 @@ def list_option_callback(ctx: click.Context, param: click.Parameter, value: str
5858 ctx .exit ()
5959
6060
61- def find_patchflow (possible_module_paths : Iterable [str ], patchflow : str ) -> Any | None :
61+ def find_patchflow (possible_module_paths : Iterable [str ], patchflow : str , trusted_modules : Iterable [str ]) -> Any | None :
62+ # Prepare whitelist set
63+ trusted_modules_set = set (trusted_modules )
64+
6265 for module_path in possible_module_paths :
6366 try :
6467 spec = importlib .util .spec_from_file_location ("custom_module" , module_path )
@@ -71,14 +74,18 @@ def find_patchflow(possible_module_paths: Iterable[str], patchflow: str) -> Any
7174 except Exception :
7275 logger .debug (f"Patchflow { patchflow } not found as a file/directory in { module_path } " )
7376
74- try :
75- module = importlib .import_module (module_path )
76- logger .info (f"Patchflow { patchflow } loaded from { module_path } " )
77- return getattr (module , patchflow )
78- except ModuleNotFoundError :
79- logger .debug (f"Patchflow { patchflow } not found as a module in { module_path } " )
80- except AttributeError :
81- logger .debug (f"Patchflow { patchflow } not found in { module_path } " )
77+ # Check if module_path is trusted before importing it
78+ if module_path in trusted_modules_set :
79+ try :
80+ module = importlib .import_module (module_path )
81+ logger .info (f"Patchflow { patchflow } loaded from { module_path } " )
82+ return getattr (module , patchflow )
83+ except ModuleNotFoundError :
84+ logger .debug (f"Patchflow { patchflow } not found as a module in { module_path } " )
85+ except AttributeError :
86+ logger .debug (f"Patchflow { patchflow } not found in { module_path } " )
87+ else :
88+ logger .debug (f"Module path { module_path } is not in the list of trusted modules" )
8289
8390 return None
8491
0 commit comments