From ed12b2c7d6036e16ac49123d62963f0819861fdd Mon Sep 17 00:00:00 2001 From: Antonov Maxim <99024963+antonovmaxim@users.noreply.github.com> Date: Thu, 13 Jul 2023 20:21:25 +0300 Subject: [PATCH] Allow absolute paths when not restricting to workspace root (#4946) * restrict_to_root fix * Fix formatting --------- Co-authored-by: Reinier van der Leer --- autogpt/workspace/workspace.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/autogpt/workspace/workspace.py b/autogpt/workspace/workspace.py index 6d90f854..07186e73 100644 --- a/autogpt/workspace/workspace.py +++ b/autogpt/workspace/workspace.py @@ -123,7 +123,11 @@ class Workspace: logger.debug(f"Resolved root as '{root}'") # Allow exception for absolute paths if they are contained in your workspace directory. - if relative_path.is_absolute() and not relative_path.is_relative_to(root): + if ( + relative_path.is_absolute() + and restrict_to_root + and not relative_path.is_relative_to(root) + ): raise ValueError( f"Attempted to access absolute path '{relative_path}' in workspace '{root}'." )