Self-hosted AI workspace.
Python
fix(security): apply sensitive-file deny-list to grep tool (#5011) (#5013)
Michael1e7659853292
diff --git a/src/agent_tools/filesystem_tools.py b/src/agent_tools/filesystem_tools.pyindex 8b37278bc..d1180d53b 100644--- a/src/agent_tools/filesystem_tools.py+++ b/src/agent_tools/filesystem_tools.py@@ -348,7 +348,13 @@ class GlobTool:class GrepTool:async def execute(self, content: str, ctx: dict) -> dict:- from src.tool_execution import _resolve_tool_path, _resolve_search_root, _truncate+ from src.tool_execution import (+ _SENSITIVE_FILE_PATTERNS,+ _is_sensitive_path,+ _resolve_tool_path,+ _resolve_search_root,+ _truncate,+ )args: Dict[str, Any] = {}_s = (content or "").strip()if _s.startswith("{"):@@ -384,6 +390,8 @@ class GrepTool:cmd.append("--ignore-case")if glob_pat:cmd += ["--glob", glob_pat]+ for _pat in _SENSITIVE_FILE_PATTERNS:+ cmd += ["--glob", f"!*{_pat}*"]for _d in _CODENAV_SKIP_DIRS:cmd += ["--glob", f"!**/{_d}/**"]cmd += ["--regexp", pattern, root]@@ -414,6 +422,8 @@ class GrepTool:for fp in file_iter:if len(hits) >= max_hits:break+ if _is_sensitive_path(os.path.realpath(fp)):+ continuetry:with open(fp, "r", encoding="utf-8", errors="strict") as f:for i, line in enumerate(f, 1):