Skip to content

fix(tools): add workspace containment to todo_write and notebook_edit - #332

Open
sridhar-3009 wants to merge 1 commit into
HKUDS:mainfrom
sridhar-3009:fix/310b-notebook-todo-workspace-containment
Open

fix(tools): add workspace containment to todo_write and notebook_edit#332
sridhar-3009 wants to merge 1 commit into
HKUDS:mainfrom
sridhar-3009:fix/310b-notebook-todo-workspace-containment

Conversation

@sridhar-3009

Copy link
Copy Markdown

Summary

Extends #310 / relates to #328

The workspace containment checks added to read_file/write_file/edit_file missed two additional writing tools that accept model-controlled path arguments:

todo_writepath defaults to "TODO.md" but accepts any string. The tool joined it with context.cwd but 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 return is_error=True if the resolved path escapes the workspace root — consistent with the check added to the core file tools.

Test plan

  • todo_write with path="../../etc/passwd" — verify is_error=True with containment message.
  • notebook_edit with an absolute path outside cwd — verify same denial.
  • Normal todo_write with default TODO.md still works.
  • Normal notebook_edit within the workspace still works.

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant