fix(security): fix file_tools.py validate_path startswith bypass #7478 #11175

Closed
HAL9000 wants to merge 1 commits from feature/pr-7801-fix-validate-path-security into master
+6 -2
View File
2
@@ -77,8 +77,12 @@ def validate_sandbox_path(path_str: str, sandbox_root: str | None = None) -> Pat
root = root.resolve()
target = (root / path_str).resolve()
if not str(target).startswith(str(root)):
raise ValueError(f"Path traversal detected: '{path_str}' escapes sandbox root")
try:
target.relative_to(root)
except ValueError as exc:
raise ValueError(
f"Path traversal detected: '{path_str}' escapes sandbox root",
) from exc
return target