Skip to content
Open
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
15 changes: 15 additions & 0 deletions src/kimi_cli/tools/file/glob.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,21 @@ async def _validate_pattern(self, pattern: str) -> ToolError | None:
),
brief="Unsafe pattern",
)

# Check for path traversal attempts
# We split by both forward and backward slashes to handle all platforms generically,
# though glob patterns usually use forward slashes.
parts = pattern.replace("\\", "/").split("/")
if ".." in parts:
return ToolError(
message=(
f"Pattern `{pattern}` contains '..' which is not allowed. "
"You cannot traverse up the directory tree directly in the pattern. "
"Please search within a specific directory."
),
brief="Invalid pattern",
)

return None

async def _validate_directory(self, directory: KaosPath) -> ToolError | None:
Expand Down