Repository navigation
Conversation
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.
What does this PR do?
notebook_read,notebook_editandnotebook_runnow resolve their path withfile_tools._safe_resolve(), so a notebook outside the project root is rejected instead of read, written or executed.Fixes #115
Root cause / motivation
All three tools did
target = Path(project_root) / pathand never checked the result, unlikefile_tools, which has used_within_roots()/_safe_resolve()since the sibling-prefix fix.../evil.ipynband absolute paths such as/etc/passwdresolved outside the project.notebook_run()made this an execution vector, not just a read:jupyter nbconvert --executeruns whatever the prompt points it at.Changes
devagent/tools/notebook_tools.py: a small_resolve()helper wraps_safe_resolve(project_root, path)and returns[error] path escapes project rooton aValueError. All three tools call it beforeexists()/nbformat.read()/subprocess.run().tests/test_notebook_tool_containment.py:notebook_read/notebook_edit/notebook_runall reject../evil.ipynb, absolute outside paths are rejected, and a notebook inside the project still reads.Test plan
On the unmodified checkout the four containment tests fail (the outside notebook was read/edited, and
notebook_rungot as far as looking forjupyter), and they pass with the change.python -m pytest tests/ -qpasses (no new failures introduced) — ran the new module (5 passed); the full suite needs the optional provider SDKs and Jupyter installed, which this change does not touchruff check devagent/ tests/is cleanNotes for reviewers
_safe_resolve()raisesValueErrorfor a path outside the root, which is caught here and turned into the same[error] ...string shape the tools already return.--add-dirextra roots are not passed to the notebook tools; they only ever accepted the project root, so this restores exactly the intended behaviour rather than widening it.