Skip to content

Commit 83af301

Browse files
author
CarrJ
committed
- run a proper npm audit rather than just a dependency review to highlight issues in existing packages as wall, not just changed/updated
- pin actions
1 parent 5f6ad9c commit 83af301

2 files changed

Lines changed: 45 additions & 13 deletions

File tree

Lines changed: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
name: NPM vulnerability scanner
1+
name: NPM Audit Security Check
2+
23
on:
34
workflow_call:
45
workflow_dispatch:
@@ -10,14 +11,45 @@ jobs:
1011
npm-audit:
1112
runs-on: ubuntu-latest
1213
steps:
13-
- name: 'Checkout Repository'
14-
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
15-
- name: 'Dependency Review'
16-
uses: actions/dependency-review-action@a1d282b36b6f3519aa1f3fc636f609c47dddb294 #5.0.0
14+
- name: Checkout Code
15+
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1
16+
17+
- name: Setup Node.js
18+
uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020
1719
with:
18-
# If it's a PR, use the target branch. If it's a push, use 'main'.
19-
base-ref: ${{ github.event.pull_request.base.ref || 'main' }}
20-
# If it's a PR, use the source branch. If it's a push, use the current commit.
21-
head-ref: ${{ github.event.pull_request.head.ref || github.sha }}
22-
fail-on-severity: high
23-
show-patched-versions: true
20+
node-version: '20'
21+
cache: 'npm'
22+
23+
- name: Run NPM Audit & Generate Summary
24+
run: |
25+
# 1. Run npm audit in JSON mode to capture raw audit metadata
26+
AUDIT_JSON=$(npm audit --audit-level=high --json 2>/dev/null) || true
27+
28+
# 2. Extract counts using node's built-in JSON parser
29+
CRITICAL_COUNT=$(echo "$AUDIT_JSON" | node -e "let d=''; process.stdin.on('data', c => d += c); process.stdin.on('end', () => { try { console.log(JSON.parse(d).metadata.vulnerabilities.critical || 0) } catch { console.log(0) } })")
30+
HIGH_COUNT=$(echo "$AUDIT_JSON" | node -e "let d=''; process.stdin.on('data', c => d += c); process.stdin.on('end', () => { try { console.log(JSON.parse(d).metadata.vulnerabilities.high || 0) } catch { console.log(0) } })")
31+
32+
# 3. Build GitHub Job Summary Markdown
33+
echo "## 🛡️ NPM Dependency Audit Summary" >> $GITHUB_STEP_SUMMARY
34+
echo "" >> $GITHUB_STEP_SUMMARY
35+
36+
if [ "$CRITICAL_COUNT" -eq 0 ] && [ "$HIGH_COUNT" -eq 0 ]; then
37+
echo "✅ **No high or critical vulnerabilities found!** All JS packages passed security checks." >> $GITHUB_STEP_SUMMARY
38+
else
39+
echo "⚠️ **High/Critical Vulnerabilities Detected in npm Dependencies**" >> $GITHUB_STEP_SUMMARY
40+
echo "" >> $GITHUB_STEP_SUMMARY
41+
echo "| Vulnerability Severity | Total Count |" >> $GITHUB_STEP_SUMMARY
42+
echo "| :--- | :--- |" >> $GITHUB_STEP_SUMMARY
43+
echo "| 🔴 **Critical** | $CRITICAL_COUNT \vert{}" >> $GITHUB_STEP_SUMMARY
44+
echo "| 🟠 **High** | $HIGH_COUNT \vert{}" >> $GITHUB_STEP_SUMMARY
45+
echo "" >> $GITHUB_STEP_SUMMARY
46+
echo "### Detailed Audit Report" >> $GITHUB_STEP_SUMMARY
47+
echo '```text' >> $GITHUB_STEP_SUMMARY
48+
# Output human-readable audit text into the summary block
49+
npm audit --audit-level=high 2>/dev/null || true
50+
echo '```' >> $GITHUB_STEP_SUMMARY
51+
52+
# 4. Fail the workflow step
53+
echo "::error::npm audit detected $CRITICAL_COUNT critical and $HIGH_COUNT high vulnerabilities."
54+
exit 1
55+
fi

.github/workflows/ruby-vulnerability-scanner.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ jobs:
1212
runs-on: ubuntu-latest
1313
steps:
1414
- name: Checkout Code
15-
uses: actions/checkout@v4
15+
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1
1616

1717
- name: Setup Ruby
18-
uses: ruby/setup-ruby@v1
18+
uses: ruby/setup-ruby@95ef2b042f9d7a56d8268cba8559e2842e2ad01b
1919
with:
2020
ruby-version: '3.3'
2121
bundler-cache: true

0 commit comments

Comments
 (0)