Skip to content

Commit ec4b6a7

Browse files
committed
fix: Reject non-basename _vendor.json entries in --skills prune
The prune deletes rm "$dest/$pf" for each prior-stamp .files entry; a tampered/edited _vendor.json with a path component (e.g. ../../CANARY) would escape the skill dir. _vendor.json is a committed file any PR can edit, so refuse any entry that is not a plain basename (reject */*, ., .., _vendor.json) before the delete. Test tampers a stamp with a traversal entry and asserts the run fails and the outside file survives. clawgenti hardening suggestion on #26. Signed-off-by: Gloire Rubambiza <[email protected]> Assisted-By: Claude (Anthropic AI) <[email protected]>
1 parent 26af612 commit ec4b6a7

2 files changed

Lines changed: 19 additions & 0 deletions

File tree

‎scripts/vendor-engine.sh‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,14 @@ elif [ -n "$SKILLS" ]; then
206206
prev_files=$(jq -r '.files[]? // empty' "$dest/_vendor.json" 2>/dev/null || true)
207207
while IFS= read -r pf; do
208208
[ -n "$pf" ] || continue
209+
# Harden the prune's delete against a tampered/edited stamp: a .files
210+
# entry must be a plain basename. A path component (or . / .. / the
211+
# stamp itself) would let `rm "$dest/$pf"` escape the skill dir. _vendor.json
212+
# is a committed file any PR can edit, so refuse rather than trust it.
213+
case "$pf" in
214+
*/*|.|..|_vendor.json)
215+
echo "ERROR: refusing to prune non-basename stamp entry: $pf" >&2; exit 1 ;;
216+
esac
209217
case "$intended" in
210218
"$pf"|"$pf"$'\n'*|*$'\n'"$pf"|*$'\n'"$pf"$'\n'*) ;; # still listed -> keep
211219
*) if [ -e "$dest/$pf" ] && ! rm "$dest/$pf"; then

‎tests/test-vendor-engine.sh‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,17 @@ if [ -f "$pd/dep-bump-scanner.sh" ] && [ -f "$pd/_vendor.json" ]; then
175175
else echo "FAIL: prune removed a kept file"; fail=1; fi
176176
rm -f "$pd/my-helper.sh" # don't let it perturb later assertions on this dir
177177

178+
# A tampered stamp whose .files entry escapes the skill dir must be refused, not
179+
# obeyed: the prune's rm would otherwise delete outside $dest (path traversal).
180+
canary="$SK/CANARY-do-not-delete"
181+
echo "canary" > "$canary"
182+
tmpj=$(jq '.files += ["../../CANARY-do-not-delete"]' "$pd/_vendor.json") && printf '%s\n' "$tmpj" > "$pd/_vendor.json"
183+
if bash "$VENDOR" --source "$SRC" --skills "$SK" >/dev/null 2>&1; then
184+
echo "FAIL: --skills accepted a non-basename stamp entry"; fail=1
185+
else echo "PASS: --skills refuses a non-basename stamp entry"; fi
186+
if [ -f "$canary" ]; then echo "PASS: path-traversal prune did not escape the skill dir"; else echo "FAIL: prune deleted a file outside the skill dir"; fail=1; fi
187+
rm -f "$canary"
188+
178189
# --- --skills: a source missing for ONE skill fails loud, NO dir half-vendored ---
179190
BAD2="$TMP/bad2"; mkdir -p "$BAD2/scripts"
180191
# shellcheck disable=SC2086

0 commit comments

Comments
 (0)