Option to disable working directory restrictions (#1875)

Remove restriction on working directory if RESTRICT_TO_WORKSPACE != True

---------

Co-authored-by: Reinier van der Leer <github@pwuts.nl>
This commit is contained in:
Josh XT
2023-04-18 19:54:38 -04:00
committed by GitHub
parent 24d5e1fc8a
commit 9514919d37
4 changed files with 12 additions and 4 deletions

View File

@@ -3,6 +3,8 @@
################################################################################
# EXECUTE_LOCAL_COMMANDS - Allow local command execution (Example: False)
EXECUTE_LOCAL_COMMANDS=False
# RESTRICT_TO_WORKSPACE - Restrict file operations to workspace ./auto_gpt_workspace (Default: True)
RESTRICT_TO_WORKSPACE=True
# BROWSE_CHUNK_MAX_LENGTH - When browsing website, define the length of chunk stored in memory
BROWSE_CHUNK_MAX_LENGTH=8192
# USER_AGENT - Define the user-agent used by the requests library to browse website (string)

View File

@@ -3,8 +3,7 @@ from __future__ import annotations
import os
import os.path
from pathlib import Path
from typing import Generator, List
from typing import Generator
import requests
from colorama import Back, Fore

View File

@@ -39,6 +39,9 @@ class Config(metaclass=Singleton):
self.execute_local_commands = (
os.getenv("EXECUTE_LOCAL_COMMANDS", "False") == "True"
)
self.restrict_to_workspace = (
os.getenv("RESTRICT_TO_WORKSPACE", "True") == "True"
)
if self.use_azure:
self.load_azure_config()

View File

@@ -3,6 +3,10 @@ from __future__ import annotations
import os
from pathlib import Path
from autogpt.config import Config
CFG = Config()
# Set a dedicated folder for file I/O
WORKSPACE_PATH = Path(os.getcwd()) / "auto_gpt_workspace"
@@ -35,9 +39,9 @@ def safe_path_join(base: Path, *paths: str | Path) -> Path:
"""
joined_path = base.joinpath(*paths).resolve()
if not joined_path.is_relative_to(base):
if CFG.restrict_to_workspace and not joined_path.is_relative_to(base):
raise ValueError(
f"Attempted to access path '{joined_path}' outside of working directory '{base}'."
f"Attempted to access path '{joined_path}' outside of workspace '{base}'."
)
return joined_path