Skip to content

🙌 OpenHands: AI-Driven Development

fix: fix path traversal vulnerability (#1199)

Alex Bäuerle51149780acd2
diff --git a/opendevin/server/listen.py b/opendevin/server/listen.py
index b8f3dadf04..5ea9aa25cd 100644
--- a/opendevin/server/listen.py
+++ b/opendevin/server/listen.py
@@ -114,6 +114,8 @@ def select_file(file: str):
try:
workspace_base = config.get('WORKSPACE_BASE')
file_path = Path(workspace_base, file)
+ # The following will check if the file is within the workspace base and throw an exception if not
+ file_path.resolve().relative_to(Path(workspace_base).resolve())
with open(file_path, 'r') as selected_file:
content = selected_file.read()
except Exception as e: