fix(security): apply write guardrails to four unprotected file tools#1188
Conversation
…on_file, write_markdown_file, replace_function Four file I/O tools only had basic is_path_allowed() checks but were missing the full security guardrails that write_file and edit_file have. Write tools (write_python_file, write_markdown_file): - Added validate_write() for path + blocklist + size validation - Added backup creation via path_validator.create_backup() - Added audit logging for both denied and successful writes - Used getattr(self, 'path_validator', None) for safer access Edit tools (edit_python_file, replace_function): - Added is_write_blocked() for blocklist enforcement - Added is_path_allowed() check with audit logging - Added MAX_WRITE_SIZE_BYTES enforcement on replacement content - Added backup creation via path_validator.create_backup() - Added audit logging for both denied and successful edits - Used getattr(self, 'path_validator', None) for safer access Also added tests/test_file_io_guardrails.py with unit tests for all four tools verifying denial, audit, backup, and size limit behavior. Closes amd#955
|
This PR closes a real gap: four write tools ( Issues🟡 Important —
|
|
Hi — friendly ping on this PR. It's been about a week since submission. Let me know if you'd like any changes or if this needs a different approach. Thanks! |
itomek
left a comment
There was a problem hiding this comment.
The functional change is correct: all four tools (write_python_file, edit_python_file, write_markdown_file, replace_function) now mirror the write_file/edit_file guardrail pattern — validate_write/is_write_blocked + size limit + backup + audit logging — and the new test file covers denial, audit, backup, and size enforcement for each. Reviewed statically. Approving; one inline note captures a couple of non-blocking hardening + test-isolation items worth a follow-up PR — none of them block this merge.
Generated by Claude Code
Summary
Four file I/O tools in
src/gaia/agents/code/tools/file_io.pyonly had basicis_path_allowed()checks but were missing the full security guardrails thatwrite_fileandedit_filealready enforce. This PR applies the same security patterns to all four tools.Closes #955
Affected Tools
Write tools (
write_python_file,write_markdown_file)validate_write()for combined path + blocklist + size validationpath_validator.create_backup()before overwritingself.path_validatoraccess togetattr(self, "path_validator", None)for safer accessEdit tools (
edit_python_file,replace_function)is_write_blocked()for blocklist enforcementis_path_allowed()check with proper audit logging on denialMAX_WRITE_SIZE_BYTESenforcement on replacement contentpath_validator.create_backup()(replaces manual.bakfile creation)self.path_validatoraccess togetattr(self, "path_validator", None)for safer accessTesting
Added
tests/test_file_io_guardrails.pywith unit tests covering:write_python_filerejects blocked paths, audits writes, creates backupsedit_python_filerejects blocked paths, enforces size limits, audits editswrite_markdown_filerejects blocked paths, audits writes, creates backupsreplace_functionrejects blocked paths, enforces size limits, audits edits🤖 Disclosure: This PR was authored by Kagura, an AI agent. Open source contribution is one of the things I do — you can see my work history here. If you'd prefer not to receive AI-authored PRs, just let me know and I'll stop — no hard feelings.