@@ -36,17 +36,15 @@ class TaskProcessor:
3636
3737 config_hash : str
3838 module_path_hash : str
39- hook_ref : HookRef | None
40- executor : PluginExecutor | None
39+ hook_ref : HookRef
40+ executor : PluginExecutor
4141
4242 def __init__ (self ) -> None :
4343 """Initialize defaults."""
4444 hasher = hashlib .sha256 ()
4545 hasher .update (b"" )
4646 self .config_hash = hasher .hexdigest ()
4747 self .module_path_hash = self .config_hash
48- self .hook_ref = None
49- self .executor = None
5048
5149 def compute_hash (self , json_config_or_module_path : str ):
5250 """Compute the hash of the supplied string"""
@@ -105,8 +103,19 @@ async def process_task(task_data, tp: TaskProcessor):
105103 json_config = task_data .get ("config" )
106104 config_raw = json .loads (json_config )
107105 module_path : str = task_data .get ("script_path" )
106+
107+ # Security: Validate module_path to prevent directory traversal
108+ if ".." in module_path or module_path .startswith ("/" ):
109+ raise ValueError (f"Invalid module_path: '{ module_path } ' - path traversal not allowed" )
110+
108111 if tp .module_path_hash != tp .compute_hash (module_path ) or tp .config_hash != tp .compute_hash (json_config ):
109- sys .path .append (str (Path (module_path ).resolve ()))
112+ # pull the resolved plugin path and only add the module path if it has the same root
113+ path = Path (module_path ).resolve ()
114+ resolved_module_path = str (path )
115+ if path .exists ():
116+ sys .path .append (resolved_module_path )
117+ else :
118+ raise RuntimeError (f"plugin module_path '{ resolved_module_path } ' does not exist." )
110119 config = get_proper_config (config_raw .get ("name" ), module_path )
111120 hook_type = task_data .get (HOOK_TYPE )
112121 cls_name : str = task_data .get ("class_name" )
@@ -128,7 +137,7 @@ async def process_task(task_data, tp: TaskProcessor):
128137 state = context .get ("state" ), global_context = context .get ("global_context" ), metadata = context .get ("metadata" )
129138 )
130139 result = await tp .executor .execute_plugin (
131- hookref = tp .hook_ref ,
140+ hook_ref = tp .hook_ref ,
132141 payload = task_data .get ("payload" ),
133142 local_context = plugin_context ,
134143 violations_as_exceptions = False ,
0 commit comments