T09 · Insecure Skill Coding Practices
- Location
scripts/statusline.sh:42- Finding
Predictable Temporary State File Allows Symlink-Based File Overwrite
- Content
View full analysis
/dev/null; then prev_pct=$(jq -r '.last_pct // 0' "$state_file" 2>/dev/null) || prev_pct=0 compactions=$(jq -r '.compactions // 0' "$state_file" 2>/dev/null) || compactions=0 else prev_pct=$(grep -o '"last_pct":[0-9]*' "$state_file" | cut -d: -f2) || prev_pct=0 compactions=$(grep -o '"compactions":[0-9]*' "$state_file" | cut -d: -f2) || compactions=0 fi fi # Detect compaction: usage dropped by more than COMPACTION_DROP points if [[ "$prev_pct" -gt 0 ]] && [[ $((prev_pct - used_pct)) -ge "$COMPACTION_DROP" ]]; then compactions=$((compactions + 1)) fi # Save state cat > "$state_file" </dev/null; then compactions=$(jq -r '.compactions // 0' "$state_file" 2>/dev/null) || compactions=0 # If no stdin data, use stored percentage if [[ -z "$used_pct" ]]; then used_pct=$(jq -r '.last_pct // empty' "$state_file" 2>/dev/null) || true fi else compactions=$(grep -o '"compactions":[0-9]*' "$state_file" | cut -d: -f2) || compactions=0 if [[ -z "$used_pct" ]]; then used_pct=$(grep -o '"last_pct":[0-9]*' "$state_file" | cut -d: -f2) || true fi fi fi ``` ### Technical Analysis The script stores session ...[truncated 2274 chars]- Remediation
View remediation
"$tmp_file" chmod 600 "$tmp_file" mv -f -- "$tmp_file" "$state_file" ``` 5. Validate loaded fields as bounded integers before arithmetic or status decisions. Reject malformed, negative, or unreasonable percentages and compaction counts. ]]>
