Auditing and updating npm dependencies to prevent security vulnerabilities in TypeScript projects
Scans npm dependencies for security vulnerabilities using `npm audit` and updates packages to patched versions. Triggers when reviewing package.json changes, before adding new dependencies, or during security audits to prevent known CVEs from entering your codebase.
/plugin marketplace add djankies/claude-configs/plugin install typescript@claude-configsThis skill inherits all available tools. When active, it can use any tool Claude has access to.
Purpose: Prevent security vulnerabilities through proper npm dependency auditing, updating, and monitoring.
When to use: Before adding new dependencies, during security reviews, when setting up CI/CD pipelines, or when package.json changes.
Dependencies are attack vectors. Each package you add introduces potential vulnerabilities:
Default stance: Minimize dependencies. Every package is a liability.
Before installing any package:
npm audit
This shows:
Read the output carefully. Not all vulnerabilities affect your code:
Automatic fixes (use with caution):
npm audit fix
This updates packages to non-breaking versions that patch vulnerabilities.
Breaking changes:
npm audit fix --force
This updates to latest versions, potentially breaking your code. Use only after:
Manual selective updates:
npm update package-name
Update specific packages after reviewing their changelogs.
Block installations with vulnerabilities:
Create .npmrc in project root:
audit-level=moderate
This fails npm install if moderate or higher severity vulnerabilities exist.
In CI/CD:
- name: Security audit
run: |
npm audit --audit-level=moderate
if [ $? -ne 0 ]; then
echo "Security vulnerabilities found!"
exit 1
fi
GitHub Dependabot:
Enable in repository settings → Security → Dependabot alerts.
Automatically:
npm-check-updates:
npx npm-check-updates
Shows available updates for all dependencies.
npx npm-check-updates -u
Updates package.json (still need to run npm install).
Ask these questions:
Do I actually need this?
Is this package trustworthy?
Is this package maintained?
What are the transitive dependencies?
npm ls package-name
Each transitive dependency is another attack vector.
Avoid packages with:
@types/ package or no types at all)postinstall scripts (potential supply chain attack vector)Use built-in Node.js/browser features when possible:
import { randomBytes } from 'crypto';
const id = randomBytes(16).toString('hex');
Better than installing uuid package if you just need random IDs.
const url = new URL('/api/users', 'https://api.example.com');
url.searchParams.set('limit', '10');
Better than installing query string builder packages.
package-lock.json (npm) or yarn.lock (Yarn) must be committed:
Never:
.gitignorenpm install with --no-package-lockIn package.json, prefer exact versions for critical dependencies:
{
"dependencies": {
"express": "4.18.2",
"zod": "3.22.4"
}
}
Not:
{
"dependencies": {
"express": "^4.18.2",
"zod": "~3.22.4"
}
}
Rationale: Caret (^) and tilde (~) allow automatic updates that could introduce breaking changes or vulnerabilities.
Exception: Development dependencies can use ranges if you regularly update them.
Every CI pipeline must:
Run audit on every build:
- run: npm audit --audit-level=moderate
Check for outdated dependencies weekly:
schedule:
- cron: '0 0 * * 1'
jobs:
update-check:
- run: npx npm-check-updates
Prevent merging PRs with vulnerabilities:
- name: Security gate
run: npm audit --production --audit-level=moderate
name: Security Audit
on:
push:
branches: [main]
pull_request:
schedule:
- cron: '0 0 * * 1'
jobs:
audit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20'
- run: npm ci
- run: npm audit --audit-level=moderate
- name: Check for outdated packages
run: npx npm-check-updates
Options:
Find alternative package:
Assess actual risk:
Audit exception (last resort):
npm audit --json > audit-baseline.json
Document why exception is acceptable:
Never ignore vulnerabilities permanently.
npm install some-random-package
Correct approach:
bundlephobia.comnpm audit after installation"It's just a moderate severity in a dev dependency, doesn't matter."
Wrong. Development dependencies:
--force without understandingnpm install --force
This bypasses dependency resolution and can install incompatible versions.
Only use when:
Weekly:
npm auditMonthly:
npx npm-check-updatesQuarterly:
Check if types match runtime:
import { z } from 'zod';
const APIResponseSchema = z.object({
data: z.array(z.string()),
});
type APIResponse = z.infer<typeof APIResponseSchema>;
This ensures types and runtime validation stay synchronized.
import type { User } from 'huge-library';
This imports only types, not runtime code, reducing bundle size.
Tools:
npm audit - Built-in vulnerability scannernpm-check-updates - Dependency update checkerReferences:
Before merging any dependency changes:
npm audit passes at moderate level or higherRemember: The best dependency is the one you don't add. The second best is one that's actively maintained with a strong security track record.
This skill should be used when the user asks to "create a slash command", "add a command", "write a custom command", "define command arguments", "use command frontmatter", "organize commands", "create command with file references", "interactive command", "use AskUserQuestion in command", or needs guidance on slash command structure, YAML frontmatter fields, dynamic arguments, bash execution in commands, user interaction patterns, or command development best practices for Claude Code.
This skill should be used when the user asks to "create an agent", "add an agent", "write a subagent", "agent frontmatter", "when to use description", "agent examples", "agent tools", "agent colors", "autonomous agent", or needs guidance on agent structure, system prompts, triggering conditions, or agent development best practices for Claude Code plugins.
This skill should be used when the user asks to "create a hook", "add a PreToolUse/PostToolUse/Stop hook", "validate tool use", "implement prompt-based hooks", "use ${CLAUDE_PLUGIN_ROOT}", "set up event-driven automation", "block dangerous commands", or mentions hook events (PreToolUse, PostToolUse, Stop, SubagentStop, SessionStart, SessionEnd, UserPromptSubmit, PreCompact, Notification). Provides comprehensive guidance for creating and implementing Claude Code plugin hooks with focus on advanced prompt-based hooks API.