fix: validate paths in delete_files with validatePathWithinRepo#1006
Open
qinlongli2024-ai wants to merge 1 commit intoanthropics:mainfrom
Open
fix: validate paths in delete_files with validatePathWithinRepo#1006qinlongli2024-ai wants to merge 1 commit intoanthropics:mainfrom
qinlongli2024-ai wants to merge 1 commit intoanthropics:mainfrom
Conversation
The delete_files MCP tool used a simple startsWith(cwd) check for absolute paths and accepted relative paths without any validation. This is inconsistent with commit_files, which correctly calls validatePathWithinRepo() to prevent path-traversal via '..' segments and symlink escapes. Replace the ad-hoc check with the same validatePathWithinRepo() call used by commit_files, ensuring both tools enforce identical path safety guarantees. - Absolute paths that resolve outside the repo are now rejected - Relative paths with '..' traversal are caught by realpath resolution - Symlinks escaping the repository root are blocked - Relative path normalisation is consistent with commit_files
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
The
delete_filesMCP tool ingithub-file-ops-server.tsuses a weaker path validation thancommit_files. Whilecommit_filescorrectly callsvalidatePathWithinRepo()(which resolves symlinks and blocks..traversal),delete_filesonly checks if absolute paths start withcwdand passes relative paths through without any validation.The inconsistency
Fix
Replace the ad-hoc path processing in
delete_fileswith the samevalidatePathWithinRepo()+ relative path normalisation pattern used bycommit_files:This ensures both tools enforce identical path safety guarantees:
..traversal is caught byrealpathresolutionChecklist
validatePathWithinRepo()functioncommit_filesimplementation