Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/crewai-tools/src/crewai_tools/security/safe_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,9 @@ def validate_directory_path(path: str, base_dir: str | None = None) -> str:
"""
validated = validate_file_path(path, base_dir)
if not os.path.isdir(validated):
raise ValueError(f"Path '{validated}' is not a directory.")
raise ValueError(
f"Path '{format_path_for_display(validated, base_dir)}' is not a directory."
)
return validated


Expand Down
10 changes: 10 additions & 0 deletions lib/crewai-tools/tests/utilities/test_safe_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,16 @@ def test_rejects_file_as_directory(self, tmp_path):
with pytest.raises(ValueError, match="not a directory"):
validate_directory_path("file.txt", str(tmp_path))

def test_rejects_file_as_directory_without_leaking_base_path(self, tmp_path):
(tmp_path / "file.txt").touch()

with pytest.raises(ValueError) as exc_info:
validate_directory_path("file.txt", str(tmp_path))

message = str(exc_info.value)
assert "file.txt" in message
assert str(tmp_path) not in message

def test_rejects_traversal(self, tmp_path):
with pytest.raises(ValueError, match="outside the allowed directory"):
validate_directory_path("../../", str(tmp_path))
Expand Down