T09 · Insecure Skill Coding Practices
- Location
scripts/init_games_directory.sh:19- Finding
Initialization script silently overwrites existing user records
- Content
View full analysis
"$GAMES_DIR/video/playing.md" echo "[backlog template]" > "$GAMES_DIR/video/backlog.md" echo "[board-game collection template]" > "$GAMES_DIR/board/collection.md" echo "[board-game wishlist template]" > "$GAMES_DIR/board/wishlist.md" echo "[party-game template]" > "$GAMES_DIR/party/ideas.md" echo "[children's activity template]" > "$GAMES_DIR/kids/activities.md" echo "[favorite-games template]" > "$GAMES_DIR/favorites.md" echo "[game-night log template]" > "$GAMES_DIR/game-nights.md" ``` The corresponding truncating redirections occur at lines 25, 33, 48, 52, 66, 81, 95, and 107. The script creates directories with `mkdir -p` but does not check whether any target file already exists. ### Technical Analysis The shell `>` operator opens its target with truncation enabled. If a target file already exists, its previous contents are erased before the template is written. The script is documented as a normal initialization command in `README.md` lines 42-44: ```bash bash scripts/init_games_directory.sh ``` There is no warning that the operation is destructive, no confirmation prompt, no backup mechanism, no existing-file guard, and no explicit force option. Consequently, initialization is not idempotent: running it after the user has populated the files resets the stored records instead of preserving them. This is an insecure coding practice involving unsafe handling of persistent user data. It does not provide privilege escalation or code execution, but it can cause data loss within the invoking user's account. ### Attack Path 1. A user initializes `~/games` and subsequently adds game progress, collections, favorites, wishl ...[truncated 1239 chars]- Remediation
View remediation
"$target" else printf 'Preserving existing file: %s\n' "$target" fi ``` 2. **Use shell no-clobber mode** as a defense-in-depth measure: ```bash set -o noclobber ``` Handle creation failures explicitly rather than silently continuing. 3. **Add an explicit `--force` option** if resetting data is required. Clearly warn that it destroys existing records and require deliberate user action. 4. **Create timestamped backups** before any forced replacement: ```bash cp -- "$target" "$target.backup.$(date +%Y%m%d%H%M%S)" ``` 5. **Use restrictive and predictable failure behavior:** ```bash set -euo pipefail ``` 6. **Update the README** to distinguish safe first-time initialization from destructive reset behavior. 7. **Add regression tests** that populate every target file, rerun initialization, and verify that existing content remains unchanged unless an explicit force option is supplied. ]]>
