Skip to content

Commit 2894b26

Browse files
author
wangjichao
committed
fix: use validate_allowed_path in FileEditor.replace_code_block() for security
1 parent 6d6bff0 commit 2894b26

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

codebase_rag/tools/file_editor.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from ..parser_loader import load_parsers
1717
from ..schemas import EditResult
1818
from ..types_defs import FunctionMatch
19+
from ..utils.path_utils import validate_allowed_path
1920
from . import tool_descriptions as td
2021

2122

@@ -212,8 +213,9 @@ def replace_code_block(
212213

213214
logger.info(ls.TOOL_FILE_EDIT_SURGICAL.format(path=file_path))
214215
try:
215-
full_path = (self.project_root / file_path).resolve()
216-
full_path.relative_to(self.project_root)
216+
full_path = validate_allowed_path(
217+
file_path, self.project_root, self.allowed_roots
218+
)
217219

218220
if not full_path.is_file():
219221
logger.error(ls.EDITOR_FILE_NOT_FOUND.format(path=file_path))
@@ -251,7 +253,7 @@ def replace_code_block(
251253
logger.success(ls.TOOL_FILE_EDIT_SURGICAL_SUCCESS.format(path=file_path))
252254
return True
253255

254-
except ValueError:
256+
except PermissionError:
255257
logger.error(ls.FILE_OUTSIDE_ROOT.format(action=cs.FileAction.EDIT))
256258
return False
257259
except Exception as e:

0 commit comments

Comments
 (0)