Repository navigation
fix(file-io): scope delete, move and frontmatter_delete to allowed paths - #729
Open
RerankerGuo wants to merge 1 commit into
Open
RerankerGuo wants to merge 1 commit into
RerankerGuo wants to merge 1 commit into
Conversation
DeleteStep, MoveStep and FrontmatterDeleteStep mutated any workspace path without consulting the request-scoped _allowed_paths constraint, so a scope-limited agent session could still unlink or rmtree paths outside its scope, move files in or out of it, or drop frontmatter keys from other notes. Enforce the same fail-closed check the other file I/O steps already apply: delete checks the target, move checks both the source and the destination, and frontmatter_delete mirrors frontmatter_update. Without an injected constraint the steps keep their unrestricted behavior.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
_allowed_pathsis the request-scoped permission constraint that hosts inject (viainjected_job_kwargs) to bound what an agent session may touch.ReadStep,EditStep,WriteStep,FrontmatterReadStepandFrontmatterUpdateStepenforce it, but three mutating file I/O steps silently ignored it:delete_stepunlinked files andshutil.rmtreed whole folders anywhere in the workspace.move_stepcopied any file to any destination and unlinked the source.frontmatter_delete_stepremoved frontmatter keys from any Markdown file.A session scoped to a single note (for example
AutoMemoryStepupdate rounds injecting_allowed_paths: [note_path]) could therefore still delete other notes or entire folders, move files in or out of the scope, or tamper with other notes' frontmatter — which is exactly the hole theFrontmatterUpdateStepdocstring says the constraint exists to close.Fix
DeleteStep._delete: fail withno permission to delete this pathwhen the resolved target is outside the scope (before anyunlink/rmtree). Directory scope semantics are unchanged: deleting a folder inside the allowed directory works, deleting an ancestor of the scope does not.MoveStep._move: check both endpoints — the source (which gets unlinked) and the destination (which gets written) — and fail closed withno permission to move this filebefore the copy.FrontmatterDeleteStep: mirrorFrontmatterUpdateStep(same placement, sameno permission to update this filemessage).Without an injected constraint (
_allowed_paths is None) the steps keep their unrestricted behavior, so existing jobs are unaffected; invalid constraints already fail closed in_check_path_permission.Tests
Four regression tests in
tests/unit/test_path_permission.py(all fail onmainbefore the fix):The full
tests/unitsuite passes except the pre-existingtest_index_update_loop_retries_source_changed_during_initial_scan, which fails identically on unmodifiedmainon this machine (timing-sensitive watcher waits; unrelated to this change).