fix(tools): prevent command argument injection and path traversal in checkpoint manager#7919
fix(tools): prevent command argument injection and path traversal in checkpoint manager#7919Dusk1e wants to merge 1 commit into
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.
|
Merged via PR #7944 — your commit was cherry-picked onto current main with your authorship preserved in git log. Thanks for the contribution, @Dusk1e! One note for posterity: the test case |
What
Fixed a critical security vulnerability in
tools/checkpoint_manager.pywhere unsanitized user inputs were passed directly to git subprocess commands, enabling Git argument injection and path traversal._validate_commit_hash(str)to enforce strict hexadecimal patterns and reject inputs starting with-(e.g.,--patch)._validate_file_path(str, str)to reject absolute paths and prevent directory escapes (e.g.,../outside_file) usingpathlib.Path.resolve().CheckpointManager.restore()anddiff().TestSecuritysuite intest_checkpoint_manager.py.Why
The vulnerability was exposed in two main workflows:
/rollback <hash>command passed from the CLI viacli.pyparsing logic./rollbackslash command dispatched by the messaging gateway (gateway/run.py).Because user input flowed into
git checkout <hash> -- <file_path>directly, malicious payloads passed as the hash could trigger unintended git flags (argument injection). Furthermore, malicious sequences like../withinfile_pathallowed attackers to restore/overwrite arbitrary files outside the intended project boundary, leading to an environment escape.How to test