@@ -59,6 +59,9 @@ def list_option_callback(ctx: click.Context, param: click.Parameter, value: str
5959
6060
6161def find_patchflow (possible_module_paths : Iterable [str ], patchflow : str ) -> Any | None :
62+ # Define a whitelist of allowed module paths
63+ allowed_modules = {'allowed_module_1' , 'allowed_module_2' }
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 the module is in the whitelist before importing
78+ if module_path in allowed_modules :
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 .warning (f"Module path { module_path } is not in the whitelist." )
8289
8390 return None
8491
0 commit comments