| name | dependency-security |
| description | Dependency security scanning. Use when auditing npm packages for vulnerabilities. |
Dependency Security Skill
This skill covers security scanning for npm dependencies.
When to Use
Use this skill when:
- Auditing project dependencies
- Setting up security CI/CD
- Responding to vulnerability alerts
- Evaluating new dependencies
Core Principle
DEFENSE IN DEPTH - Use multiple tools for security scanning. No single tool catches everything.
npm audit
Basic Usage
npm audit
npm audit --json
npm audit --audit-level=high
npm audit --omit=dev
Auto-Fix
npm audit fix
npm audit fix --force
npm audit fix --dry-run
Understanding Output
# vulnerabilities found
Severity: high
Package: example-package
Dependency of: my-dep
Path: my-dep > sub-dep > example-package
More info: https://npmjs.com/advisories/XXXXX
Snyk
Installation
npm install -g snyk
snyk auth
Usage
snyk test
snyk monitor
snyk test --severity-threshold=high
snyk test --package-manager=npm
CI Integration
- name: Snyk Security Scan
uses: snyk/actions/node@master
env:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
with:
args: --severity-threshold=high
Socket.dev
Installation
npm install -g @socketsecurity/cli
Usage
npx @socketsecurity/cli scan
npx @socketsecurity/cli report
What Socket Detects
- Typosquatting attacks
- Protestware
- Malicious packages
- Unexpected behavior
- Network access
- Shell access
Severity Levels
| Level | Description | Action |
|---|
| Critical | RCE, data breach | Fix immediately |
| High | Privilege escalation | Fix within 24 hours |
| Moderate | DoS, info disclosure | Fix within 1 week |
| Low | Minor issues | Fix when convenient |
Security Audit Workflow
1. Initial Assessment
npm audit
npm outdated
2. Vulnerability Analysis
For each vulnerability:
- Check if it affects your usage
- Look for patches or updates
- Evaluate alternative packages
- Document if accepted risk
3. Remediation
npm update package-name
npm install package-name@latest
npm uninstall vulnerable-package
npm install alternative-package
4. Verification
npm audit
npm test
Lock File Security
Verify Lock File Integrity
npm ci
git diff package-lock.json
Lock File Best Practices
- Always commit lock files
- Use
npm ci in CI/CD
- Review lock file changes in PRs
- Never manually edit lock files
Dependency Evaluation
Before Adding Dependencies
- Check npm page - Downloads, maintenance, issues
- Check Snyk DB - Known vulnerabilities
- Check Socket.dev - Supply chain risks
- Check license - Compatibility
Evaluation Checklist
Automated Security
Dependabot Configuration
version: 2
updates:
- package-ecosystem: "npm"
directory: "/"
schedule:
interval: "weekly"
open-pull-requests-limit: 10
groups:
dev-dependencies:
dependency-type: "development"
Renovate Configuration
{
"extends": ["config:base"],
"packageRules": [
{
"matchUpdateTypes": ["minor", "patch"],
"automerge": true
}
]
}
CI Pipeline Security
name: Security
on:
push:
branches: [main]
pull_request:
schedule:
- cron: '0 0 * * *'
jobs:
audit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: '22'
- name: Install dependencies
run: npm ci
- name: npm audit
run: npm audit --audit-level=high
- name: Snyk scan
uses: snyk/actions/node@master
env:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
Handling Vulnerabilities
When Patch Available
npm audit fix
npm update vulnerable-package
When No Patch Available
- Check if vulnerability applies - May not affect your usage
- Use override - Force specific version
{
"overrides": {
"vulnerable-package": "2.0.0"
}
}
- Replace dependency - Find alternative
- Accept risk - Document and track
Documentation
## Security Exceptions
### vulnerable-package@1.0.0
- **Vulnerability**: CVE-2024-XXXXX
- **Reason Accepted**: Only used in tests, not production
- **Review Date**: 2024-12-01
- **Assignee**: @developer
Best Practices Summary
- Run audit regularly - At least weekly
- Use multiple tools - npm audit + Snyk + Socket
- Automate updates - Dependabot or Renovate
- Review before merge - Check lock file changes
- Document exceptions - Track accepted risks
- Monitor dependencies - Snyk monitor
- Keep dependencies minimal - Fewer deps = smaller attack surface
Code Review Checklist