fix(tools): add workspace containment to todo_write and notebook_edit - #332
Open
sridhar-3009 wants to merge 1 commit into
Open
fix(tools): add workspace containment to todo_write and notebook_edit#332sridhar-3009 wants to merge 1 commit into
sridhar-3009 wants to merge 1 commit into
Conversation
The workspace containment check added to read_file/write_file/edit_file in a previous PR missed two other writing tools that accept model- controlled path arguments: - todo_write: path defaults to "TODO.md" but accepts any string. The tool joined it with context.cwd but did not resolve and validate the result, so a "../../../etc/cron.d/evil" traversal would succeed. - notebook_edit: uses the same _resolve_path() helper as the file tools (expand → absolute → resolve), so absolute paths and ../ traversals resolve to paths outside the workspace without any check. Add Path.relative_to(cwd.resolve()) containment guards to both tools, consistent with the pattern used in the three core file tools. Extends HKUDS#310
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
Extends #310 / relates to #328
The workspace containment checks added to
read_file/write_file/edit_filemissed two additional writing tools that accept model-controlled path arguments:todo_write—pathdefaults to"TODO.md"but accepts any string. The tool joined it withcontext.cwdbut never resolved the result to check for../traversal. A path like"../../../../root/.ssh/authorized_keys"would resolve and write outside the workspace.notebook_edit— uses the same_resolve_path()pattern as the three file tools: expand → make absolute →resolve(). Accepts absolute paths and../traversal sequences with no containment check.Fix: both tools now call
path.relative_to(cwd.resolve())immediately after path resolution and returnis_error=Trueif the resolved path escapes the workspace root — consistent with the check added to the core file tools.Test plan
todo_writewithpath="../../etc/passwd"— verifyis_error=Truewith containment message.notebook_editwith an absolute path outsidecwd— verify same denial.todo_writewith defaultTODO.mdstill works.notebook_editwithin the workspace still works.