T09 · Insecure Skill Coding Practices
- Location
audit.sh:18- Finding
npm audit failures are incorrectly reported as clean results
- Content
View full analysis
/dev/null > /tmp/vibe-npm-audit.json; then critical=$(python3 -c "import json; d=json.load(open('/tmp/vibe-npm-audit.json')); print(sum(1 for v in d.get('vulnerabilities',{}).values() if v.get('severity')=='critical'))" 2>/dev/null || echo "0") high=$(python3 -c "import json; d=json.load(open('/tmp/vibe-npm-audit.json')); print(sum(1 for v in d.get('vulnerabilities',{}).values() if v.get('severity')=='high'))" 2>/dev/null || echo "0") moderate=$(python3 -c "import json; d=json.load(open('/tmp/vibe-npm-audit.json')); print(sum(1 for v in d.get('vulnerabilities',{}).values() if v.get('severity')=='moderate'))" 2>/dev/null || echo "0") echo " 🔴 Critical: $critical" echo " 🟠 High: $high" echo " 🟡 Moderate: $moderate" if [ "$critical" -gt 0 ]; then echo " ⚠️ Critical vulnerabilities found! DO NOT DEPLOY." ISSUES=$((ISSUES + critical)) fi else echo " ✅ No issues (or audit unavailable)" fi ``` ### Technical Analysis `npm audit` returns a nonzero status when vulnerabilities at or above its configured audit level are found. The script only parses the generated JSON when `npm audit` returns zero. Consequently, the branch intended to count critical vulnerabilities is generally skipped precisely when vulnerabilities exist. The `else` branch conflates a vulnerability result, network failure, malformed response, and unavailable audit service with a clean result. `ISSUES` remains unchanged, allowing the final status to print `CLEAN — safe to proceed` and return success. The script also counts only critical findings toward `ISSUES`; reported high and moderate findings do not affect the final result, despite the audit being presented as a deployment-safety check. ### Attack Path 1. A ...[truncated 1035 chars]- Remediation
View remediation
"$audit_file" 2>/dev/null audit_status=$? set -e if ! python3 -m json.tool "$audit_file" >/dev/null 2>&1; then echo " ❌ npm audit failed or returned invalid JSON" ISSUES=$((ISSUES + 1)) else # Parse and count all configured severities here. fi ``` Distinguish documented vulnerability exit codes from operational failures. Treat invalid JSON, network errors, and unavailable tooling as scan failures rather than clean results. Define an explicit policy for critical, high, and moderate findings, and ensure every policy-violating severity increments `ISSUES`. Add regression tests using fixture reports and mocked exit statuses of both zero and nonzero. ]]>
