T09 · Insecure Skill Coding Practices
- Location
scripts/collect_release_changes.sh:4- Finding
Unquoted Git Revision Range Allows Argument Injection
- Content
View full analysis
Vulnerability Details
File Location:
scripts/collect_release_changes.sh, lines 4-31
Vulnerability Type: Git argument injection through unquoted shell expansion
Risk Level: Mediumbash since_ref="${1:-}" until_ref="${2:-HEAD}" if [[ -z "${since_ref}" ]]; then if git describe --tags --abbrev=0 >/dev/null 2>&1; then since_ref="$(git describe --tags --abbrev=0)" fi fi range="" if [[ -n "${since_ref}" ]]; then range="${since_ref}..${until_ref}" else range="${until_ref}" fi repo_root="$(git rev-parse --show-toplevel)" printf "Repo: %s\n" "${repo_root}" if [[ -n "${since_ref}" ]]; then printf "Range: %s..%s\n" "${since_ref}" "${until_ref}" else printf "Range: start..%s (no tags found)\n" "${until_ref}" fi printf "\n== Commits ==\n" git log --reverse --date=short --pretty=format:'%h|%ad|%s' ${range} printf "\n\n== Files Touched ==\n" git log --reverse --name-only --pretty=format:'--- %h %s' ${range} | sed '/^$/d'Technical Analysis
The script accepts revision values from positional arguments and combines them into the
rangevariable. Although the assignments are quoted,${range}is expanded without quotes in bothgit logcommands.Unquoted shell expansion performs word splitting and pathname expansion. Consequently, whitespace or wildcard characters embedded in a caller-controlled revision value can turn the intended single revision expression into multiple command-line arguments. Additional tokens can then be interpreted by Git as options, path specifications, or extra revision selectors.
This is an argument-injection vulnerability rather than direct shell-command injection. The script does not use
eval, and shell metacharacters introduced through parameter expansion are not reparsed as shell syntax. Therefore, the demonstrated flaw does not independently permit arbitrary shell command execution.Attack Path
- An attacker or un ...[truncated 1338 chars]
- Remediation
View remediation
Remediation Suggestions
-
Validate each supplied revision before using it:
bash git rev-parse --verify "${since_ref}^{commit}" >/dev/null git rev-parse --verify "${until_ref}^{commit}" >/dev/null -
Reject revision inputs beginning with
-and inputs containing whitespace or control characters. -
Preserve the revision range as one quoted argument:
bash if [[ -n "${since_ref}" ]]; then range="${since_ref}..${until_ref}" else range="${until_ref}" fi git log --reverse --date=short \ --pretty=format:'%h|%ad|%s' \ "${range}" git log --reverse --name-only \ --pretty=format:'--- %h %s' \ "${range}" | sed '/^$/d' -
Prefer an argument array if the command later requires optional arguments:
bash git_args=( log --reverse --date=short "--pretty=format:%h|%ad|%s" "${range}" ) git "${git_args[@]}" -
Add regression tests using revision inputs containing spaces, wildcard characters, leading hyphens, and injected Git options, and verify that such inputs are rejected rather than interpreted as additional arguments.
-
