| name | package-audit |
| description | Scan for security vulnerabilities using pnpm audit, Snyk, and automated tools. Use when checking security, before deployments, or resolving CVEs. |
| allowed-tools | Read, Edit, Write, Bash, Grep |
Package Audit Skill
This skill helps you scan for and fix security vulnerabilities in npm dependencies.
When to Use This Skill
- Scanning for security vulnerabilities
- Before production deployments
- Resolving CVE alerts
- Regular security audits
- Dependency health checks
- Compliance requirements
- Pre-commit security checks
Security Audit Tools
pnpm audit
Built-in vulnerability scanner:
pnpm audit
Snyk
Advanced vulnerability scanning:
pnpm add -g snyk
snyk auth
snyk test
snyk monitor
snyk fix
Running Audits
Basic Audit
pnpm audit
pnpm -F @sgcarstrends/api audit
pnpm audit --prod
pnpm audit --json > audit-report.json
Severity Levels
pnpm audit --audit-level=high
Automated Fix
pnpm audit --fix
pnpm audit --fix --dry-run
Understanding Audit Results
Vulnerability Report
┌───────────────┬──────────────────────────────────────────────────────────────┐
│ High │ Regular Expression Denial of Service │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package │ semver │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Vulnerable │ <5.7.2 || >=6.0.0 <6.3.1 || >=7.0.0 <7.5.2 │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Patched in │ >=5.7.2 <6.0.0 || >=6.3.1 <7.0.0 || >=7.5.2 │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info │ https://github.com/advisories/GHSA-c2qf-rxjj-qqgw │
└───────────────┴──────────────────────────────────────────────────────────────┘
Key Information:
- Severity: critical, high, moderate, low, info
- Package: Affected package name
- Vulnerable: Vulnerable version range
- Patched in: Fixed version range
- Path: Dependency path (direct or transitive)
JSON Report Analysis
pnpm audit --json > audit.json
cat audit.json | jq '.vulnerabilities | length'
cat audit.json | jq '.vulnerabilities | group_by(.severity)'
cat audit.json | jq '.vulnerabilities[] | select(.severity == "critical")'
Fixing Vulnerabilities
Direct Dependencies
pnpm audit
pnpm view package-name versions
catalog:
lodash: ^4.17.21
pnpm install
pnpm audit
Transitive Dependencies
pnpm why vulnerable-package
catalog:
parent-package: ^2.0.0
{
"pnpm": {
"overrides": {
"vulnerable-package": "^3.1.0"
}
}
}
Using Overrides
{
"pnpm": {
"overrides": {
"lodash": "^4.17.21",
"semver@<7.5.2": "^7.5.2",
"some-package>vulnerable-dep": "^2.0.0"
}
}
}
Snyk Integration
Setup
pnpm add -g snyk
snyk auth
snyk test
snyk monitor
Snyk Commands
snyk test
snyk test --severity-threshold=high
snyk test --file=package.json
snyk ignore --id=SNYK-JS-LODASH-1018905
snyk test --json | snyk-to-html -o snyk-report.html
Snyk Configuration
version: v1.25.0
ignore:
'SNYK-JS-LODASH-1018905':
- '*':
reason: Low severity, no fix available
expires: 2024-12-31
'SNYK-JS-AXIOS-1234567':
- 'dev-dependency > axios':
reason: Dev dependency only
expires: never
CI Integration
GitHub Actions
name: Security Audit
on:
push:
branches: [main]
pull_request:
branches: [main]
schedule:
- cron: '0 0 * * 1'
jobs:
audit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v2
- uses: actions/setup-node@v4
with:
node-version: 20
cache: "pnpm"
- run: pnpm install
- run: pnpm audit --audit-level=moderate
- name: Check for high/critical vulnerabilities
run: |
AUDIT_OUTPUT=$(pnpm audit --json)
HIGH=$(echo $AUDIT_OUTPUT | jq '.metadata.vulnerabilities.high // 0')
CRITICAL=$(echo $AUDIT_OUTPUT | jq '.metadata.vulnerabilities.critical // 0')
[ ] [ ]
Automated Dependency Updates
Dependabot
version: 2
updates:
- package-ecosystem: "npm"
directory: "/"
schedule:
interval: "weekly"
open-pull-requests-limit: 10
groups:
security:
patterns:
- "*"
update-types:
- "patch"
ignore:
- dependency-name: "*"
update-types: ["version-update:semver-major"]
Renovate
{
"extends": ["config:base"],
"vulnerabilityAlerts": {
"enabled": true,
"automerge": true
},
"packageRules": [
{
"matchUpdateTypes": ["patch"],
"matchCurrentVersion": "!/^0/",
"automerge": true,
"automergeType": "branch"
},
{
"matchDepTypes": ["devDependencies"],
"matchUpdateTypes": ["minor",
Best Practices
1. Regular Audits
pnpm audit
2. Prioritize Fixes
pnpm audit --fix
3. Verify Fixes
pnpm audit --fix
git push
pnpm audit --fix
pnpm test
pnpm build
pnpm dev
git commit && git push
4. Document Decisions
ignore:
'SNYK-JS-LODASH-1018905':
- '*':
reason: >
Low severity prototype pollution.
Package only used in dev scripts.
No fix available yet.
Monitoring for updates.
expires: 2024-12-31
created: 2024-01-15
Handling Common Scenarios
No Fix Available
snyk monitor
pnpm remove vulnerable-package
pnpm add alternative-package
Breaking Changes in Fix
pnpm view package-name changelog
git checkout -b upgrade/package-name
catalog:
package-name: ^2.0.0
pnpm install
pnpm test
False Positives
ignore:
'SNYK-ID':
- 'package-name':
reason: >
False positive.
Vulnerable code path not used in our application.
Only affects feature X which we don't use.
expires: never
Security Audit Checklist
References
Best Practices Summary
- Regular Audits: Run audits daily in CI, weekly manually
- Prioritize Severity: Fix critical/high first, then moderate/low
- Automate Security: Use Dependabot or Renovate
- Test Fixes: Always test after applying security patches
- Document Decisions: Explain ignored vulnerabilities
- Monitor Continuously: Use Snyk monitor for ongoing tracking
- Review Dependencies: Regularly review and remove unused packages
- Stay Informed: Subscribe to security advisories for key packages