Skip to content

armgit / txtai

Public Imported from GitHub
0

💡 All-in-one AI framework for semantic search, LLM orchestration and language model workflows

Add safeopen validation to retrieve task output, closes #1181

davidmezzetti84be3476d82f
diff --git a/src/python/txtai/workflow/task/retrieve.py b/src/python/txtai/workflow/task/retrieve.py
index c5fa2340..9285f784 100644
--- a/src/python/txtai/workflow/task/retrieve.py
+++ b/src/python/txtai/workflow/task/retrieve.py
@@ -52,11 +52,17 @@ class RetrieveTask(Task):
if self.flatten:
# Flatten directory structure (default)
path = os.path.join(self.directory, os.path.basename(path))
+ directory = None
else:
# Derive output path
path = os.path.join(self.directory, os.path.normpath(path.lstrip("/")))
directory = os.path.dirname(path)
+ # Validate output path
+ self.safeopen.valid(path)
+
+ # Create output directory, if necessary
+ if directory:
# Create local directory, if necessary
os.makedirs(directory, exist_ok=True)