fix(tools): prevent git argument injection and path traversal in checkpoint manager#7944
Merged
Conversation
…checkpoint manager This commit addresses a security vulnerability where unsanitized user inputs for commit_hash and file_path were passed directly to git commands in CheckpointManager.restore() and diff(). It validates commit hashes to be strictly hexadecimal characters without leading dashes (preventing flag injection like '--patch') and enforces file paths to stay within the working directory via root resolution. Regression tests test_restore_rejects_argument_injection, test_restore_rejects_invalid_hex_chars, and test_restore_rejects_path_traversal were added.
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
Salvage of #7919 by @Dusk1e — cherry-picked onto current main with their authorship preserved.
Adds input validation to
CheckpointManager.restore()anddiff()to prevent:-(e.g.--patch,--exec) get interpreted as git flags when passed togit cat-file,git diff,git checkoutbefore the--separatorfile_pathinrestore()allowed absolute paths (/etc/passwd) and relative escapes (../../../etc/passwd)Changes
_validate_commit_hash()— enforces 4-64 hex chars, rejects leading-_validate_file_path()— rejects absolute paths, usesPath.resolve()+relative_to()for containment checkrestore()anddiff()TestSecuritytest suite covering argument injection, invalid hex, path traversal, and valid path acceptanceTest results