T07 · Tool Hijacking and Spoofing
Error
- Location
- scripts/commit-msg-hook.sh:8
- Finding
- Repository-Controlled Validator Allows Arbitrary Code Execution During Git Commits<![CDATA[ ## Vulnerability Details **File Location**: `scripts/commit-msg-hook.sh`, lines 8–22 **Vulnerability Type**: Repository-controlled tool hijacking **Risk Level**: High ```bash VALIDATOR="" for candidate in \ "$SCRIPT_DIR/../../skills/commit-message-writing/scripts/validate_commit_message.py" \ "$SCRIPT_DIR/../skills/commit-message-writing/scripts/validate_commit_message.py" \ "skills/commit-message-writing/scripts/validate_commit_message.py"; do if [ -f "$candidate" ]; then VALIDATOR="$candidate" break fi done if [ -z "$VALIDATOR" ]; then echo "Warning: validate_commit_message.py not found, skipping validation" exit 0 fi python3 "$VALIDATOR" --message "$MSG" exit $? ``` ### Technical Analysis The Git commit hook searches several paths for `validate_commit_message.py` and executes the first matching file with Python. At least one candidate, `skills/commit-message-writing/scripts/validate_commit_message.py`, is resolved relative to the current working directory and can reside in the repository working tree. The other candidate paths may also resolve to mutable skill directories, depending on where the hook is installed. Repository content changes when branches are checked out and is generally controlled by repository contributors. The hook performs no canonical-path validation, ownership check, permission check, or cryptographic integrity verification before executing the selected Python file. Consequently, a malicious branch can place attacker-controlled Python code at an expected location and cause the hook to execute it when the developer attempts a commit. The hook also fails open if no validator is found. Although this does not itself provide code execution, it silently disables the validation control and may conceal installation or path-resolution errors. ### Attack Path 1. A developer installs the hook as documented by copying `scripts/commit-msg-hook.sh` into `.git/hooks/commit-msg`. 2. An attacker creates or modifi ...[truncated 1232 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Install a trusted copy of the validator outside the repository working tree, preferably alongside the installed hook under `.git/hooks`, and invoke only that fixed location. 2. Resolve the validator path from the hook's canonical installation directory rather than from the current working directory or branch-controlled content. 3. Reject the commit if the trusted validator is missing instead of returning success: ```bash if [ ! -f "$VALIDATOR" ]; then echo "Error: trusted commit-message validator not found" >&2 exit 1 fi ``` 4. If the validator must be loaded from another directory, canonicalize the path and verify that it remains under an administrator- or user-controlled trusted directory. 5. Pin and verify the validator's integrity with a trusted cryptographic digest or signed release before execution. 6. Ensure the trusted validator and its parent directories are not writable by untrusted users or modified through repository branch checkouts. 7. Add integration tests that install the hook in a temporary repository and verify that repository-provided validators are never selected. 8. Document the trust boundary and provide an installation script that atomically installs both the hook and its trusted validator. ]]>
