T03 · Remote Payload Retrieval and Execution
Error
- Location
- scripts/hg-to-git.sh:56
- Finding
- Unpinned Remote Dependency Is Downloaded and Executed<![CDATA[ ## Vulnerability Details **File Location**: `scripts/hg-to-git.sh`, lines 56-73 and 97-100 **Vulnerability Type**: Remote execution of an unverified, mutable dependency **Risk Level**: High ### Vulnerable Code ```bash # If still not found, clone from source if ! command -v hg-fast-export &> /dev/null && ! command -v hg-fast-export.sh &> /dev/null; then FAST_EXPORT_DIR="${HOME}/.local/share/hg-fast-export" if [ ! -d "$FAST_EXPORT_DIR" ]; then mkdir -p "$(dirname "$FAST_EXPORT_DIR")" git clone https://github.com/frej/fast-export.git "$FAST_EXPORT_DIR" fi export PATH="$FAST_EXPORT_DIR:$PATH" fi # Determine fast-export command if command -v hg-fast-export &> /dev/null; then FAST_EXPORT_CMD="hg-fast-export" elif command -v hg-fast-export.sh &> /dev/null; then FAST_EXPORT_CMD="hg-fast-export.sh" elif [ -f "${HOME}/.local/share/hg-fast-export/hg-fast-export.sh" ]; then FAST_EXPORT_CMD="${HOME}/.local/share/hg-fast-export/hg-fast-export.sh" ``` ```bash # Perform conversion echo "" echo "Converting... (this may take a while for large repos)" "$FAST_EXPORT_CMD" -r "$HG_REPO" --force ``` ### Technical Analysis When `hg-fast-export` is unavailable, the script clones the current contents of an external GitHub repository and subsequently executes `hg-fast-export.sh`. The clone is not pinned to a reviewed commit or immutable release, and no checksum or cryptographic signature is verified. Consequently, the code executed during conversion can differ from the code that existed when this Skill was audited. Compromise of the upstream repository, its default branch, its maintainers, or the network trust chain could cause attacker-controlled code to be placed in the installation directory and executed. The script also trusts an existing `${HOME}/.local/share/hg-fast-export` directory without validating its ownership, contents, or integrity. An attacker who can prepopulate that location may be able to influence the executa ...[truncated 1207 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Do not automatically download and execute code during repository conversion. Require users to install the dependency explicitly. 2. If automatic installation is retained, pin the dependency to a reviewed, immutable commit hash or signed release rather than the current default branch. 3. Verify a published cryptographic checksum or trusted signature before executing the dependency. 4. Download into a newly created, permission-restricted directory and verify that the destination is owned by the current user and is not a symbolic link. 5. Invoke the verified executable by its canonical absolute path rather than adding its directory to `PATH`. 6. Record the approved dependency version and hash in the project documentation. 7. Require explicit user consent before any dependency download or privileged package-manager operation. ]]>
