T09 · Insecure Skill Coding Practices
- Location
scripts/git_clone_or_update.sh:23- Finding
Existing Repository Origin Is Not Validated Against the Requested Remote URL
- Content
View full analysis
Vulnerability Details
File Location:
scripts/git_clone_or_update.sh, lines 23-29
Vulnerability Type: Repository origin confusion and unsafe update behavior
Risk Level: Mediumbash if [ -d "${GIT_LOCAL_PATH}" ]; then # Directory exists — fetch and pull latest changes cd "${GIT_LOCAL_PATH}" || { echo "ERROR: Failed to enter directory ${GIT_LOCAL_PATH}. Check: $0" exit 1 } git fetch origin "${GIT_BRANCH}" git pull origin "${GIT_BRANCH}"Technical Analysis
When
GIT_LOCAL_PATHalready exists, the script changes into that directory and fetches from its configuredorigin. It does not:- Confirm that the directory is a valid Git working tree.
- Compare
git remote get-url originwith the suppliedGIT_REMOTE_URL. - Use the supplied
GIT_REMOTE_URLduring the update. - Require a fast-forward-only update.
Consequently, the required
GIT_REMOTE_URLinput is effectively ignored for existing directories. The update source is instead determined by mutable configuration inside the selected local repository. This creates a repository-origin confusion vulnerability: a caller may believe that content is being updated from a trusted URL while the script actually retrieves it from a different or attacker-controlled origin.Attack Path
- An attacker prepares or influences an existing directory at the path later supplied through
GIT_LOCAL_PATH. - The directory is configured as a Git repository with
originpointing to an attacker-controlled repository. - A caller invokes the skill with that local path and supplies an expected trusted repository through
GIT_REMOTE_URL. - Because the local directory already exists, the script ignores the supplied URL.
git fetch originandgit pull originretrieve and integrate content from the attacker-controlled origin.- The attacker can alter files in the working tree. If the existing local reposit ...[truncated 794 chars]
- Remediation
View remediation
Remediation Suggestions
- Verify that an existing target is a valid Git working tree before updating it, for example with
git rev-parse --is-inside-work-tree. - Read the configured origin using
git remote get-url originand compare its canonicalized value withGIT_REMOTE_URL. - Reject origin mismatches by default. If changing the origin is supported, require explicit caller confirmation before using
git remote set-url origin. - Validate
GIT_BRANCHas a permitted Git branch or ref name and reject option-like or malformed input. - Use a fast-forward-only update, such as
git pull --ff-only origin "${GIT_BRANCH}", to prevent unexpected merge commits. - Consider fetching first and explicitly checking the intended commit or ref before modifying the working tree.
- Produce a clear error when an existing path is not a Git repository or does not have the expected remote.
- Verify that an existing target is a valid Git working tree before updating it, for example with
