T09 · Insecure Skill Coding Practices
Warning
- Location
- scripts/publish.sh:7
- Finding
- Unrestricted Git Staging May Publish Unintended Sensitive Files## Vulnerability Details **File Location**: `scripts/publish.sh`, lines 7-54 **Vulnerability Type**: Unrestricted file staging and remote publication **Risk Level**: Medium ### Vulnerable Code ```bash SKILL_DIR="/Users/italks/WorkBuddy/Claw/.codebuddy/skills/crayfish-diary" REPO_URL="https://github.com/italks/crayfish-diary.git" if [ ! -d "$SKILL_DIR" ]; then exit 1 fi cd "$SKILL_DIR" if [ ! -d ".git" ]; then git init fi git add . if git diff --staged --quiet; then echo "No changes to commit" else git commit -m "Update diary skill" fi if ! git remote | grep -q "origin"; then git remote add origin "$REPO_URL" fi git branch -M main git push -u origin main ``` The original script includes informational output and a multiline commit message between these operations; they do not alter the vulnerable staging and publication behavior. ### Technical Analysis The publishing script changes into a hard-coded directory outside the installed artifact path and executes `git add .`. This recursively stages every eligible file beneath that directory rather than limiting publication to the intended release files. The audited project does not contain a `.gitignore`, although `PUBLISH.md` lists one as part of the expected package. Consequently, local configuration files, credentials, private notes, generated artifacts, or other unintended files placed beneath the target directory can be included in a commit. The subsequent unconditional `git push -u origin main` publishes the commit to the configured remote repository. The hard-coded path also means the script may operate on a different copy of the project than the copy from which the script is invoked. There is no validation of the repository root, staged file list, remote URL when an `origin` remote already exists, or sensitive-file patterns before publication. ### Attack Path 1. A sensitive or unintended file is created or alre ...[truncated 1563 chars]
- Remediation
- ## Remediation Suggestions 1. Derive the repository directory from the script's own location instead of using an absolute user-specific path: ```bash SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)" SKILL_DIR="$(cd -- "$SCRIPT_DIR/.." && pwd)" cd -- "$SKILL_DIR" ``` 2. Add a restrictive `.gitignore` covering secrets and generated files, including `.env`, private keys, credential files, archives, caches, and editor metadata. 3. Replace `git add .` with an explicit release allowlist: ```bash git add -- \ SKILL.md README.md README_CN.md PUBLISH.md clawhub.json \ scripts/create_diary.py scripts/publish.sh \ assets/crayfish_icon.svg .gitignore ``` 4. Reject sensitive files before committing by inspecting the staged file list and running a secret scanner such as Gitleaks or TruffleHog. 5. Display `git diff --cached --name-status` and require explicit operator confirmation before committing or pushing. 6. Validate that `git rev-parse --show-toplevel` equals the intended project directory and verify the exact `origin` URL even when that remote already exists. 7. If unintended sensitive data has already been pushed, rotate exposed credentials immediately and remove the material from repository history using an appropriate history-rewriting procedure.
