Repository navigation
Reject diff/file paths that escape the project root - #31
Merged
Merged
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.
Found during a Vulnops dogfood run, by manual review. Vulnops has no SAST stage yet, so its scanner didn't catch this.
save_files()in patchling/core.py,apply_diff()in patchling/applydiff.py, and the per-file path insmart_apply_patchall joined model-generated paths onto the project dir without checking they stay inside it. A diff containing+++ b/../xor an absolute path wrote a file outside the project. Prompt-injected repo content could trigger this.Fix: a new
resolve_within(root, path)resolves the path, following symlinks, and raisesUnsafePathErrorfor absolute paths,..escapes and symlink escapes.apply_diffchecks every path before it touches disk and returns False if any is unsafe.save_filesraises the error.smart_apply_patchmarks the file as failed.Tests: tests/test_path_traversal.py covers
../, nested../, absolute paths, symlink escape, and checks that in-root writes still work. Local run with mock keys: full suite 217 passed, 2 skipped.This fix awaits Ember exact-head review before merge.