Gsd-skill-creator dependency-audit

Provides dependency management and supply chain security practices for auditing vulnerabilities, checking licenses, assessing dependency health, and managing upgrades safely. Use when auditing packages, reviewing security, managing dependencies, or when user mentions 'audit', 'vulnerability', 'dependency', 'supply chain', 'npm audit', 'license', 'bundle size'.

install
source · Clone the upstream repo
git clone https://github.com/Tibsfox/gsd-skill-creator
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/Tibsfox/gsd-skill-creator "$T" && mkdir -p ~/.claude/skills && cp -r "$T/examples/skills/patterns/dependency-audit" ~/.claude/skills/tibsfox-gsd-skill-creator-dependency-audit && rm -rf "$T"
manifest: examples/skills/patterns/dependency-audit/SKILL.md
source content

Dependency Audit

Read-only analysis patterns for dependency security, license compliance, and health assessment. This skill does NOT auto-upgrade packages -- it helps you understand your dependency landscape and make informed decisions.

Security-First Principles

PrinciplePractice
Audit before mergeRun security checks in CI on every PR
Understand before upgradingRead changelogs, check breaking changes
Never blindly force-fix
npm audit fix --force
can introduce breaking changes
Pin production dependenciesUse exact versions or lock files
Verify publisher identityCheck package ownership, download counts, repo activity

Security Audit Workflow

Step 1: Run the Audit

# npm (built-in)
npm audit

# npm -- JSON output for parsing
npm audit --json

# Yarn
yarn audit

# pnpm
pnpm audit

Step 2: Read the Report

# Example npm audit output
┌───────────────┬──────────────────────────────────────────────┐
│ Severity      │ high                                         │
├───────────────┼──────────────────────────────────────────────┤
│ Package       │ lodash                                       │
│ Dependency of │ my-library                                   │
│ Path          │ my-library > lodash                          │
│ More info     │ https://github.com/advisories/GHSA-xxxx-xxxx │
└───────────────┴──────────────────────────────────────────────┘

Step 3: Assess Each Vulnerability

SeverityCVSS ScoreAction
Critical9.0-10.0Fix immediately, block deployment
High7.0-8.9Fix within 24 hours
Moderate4.0-6.9Fix within 1 week, assess exploitability
Low0.1-3.9Track, fix in next maintenance window
Info0Informational, no action required

Step 4: Determine Fix Strategy

# SAFE: See what non-breaking fixes are available
npm audit fix --dry-run

# SAFE: Apply only semver-compatible fixes
npm audit fix

# DANGEROUS: Never run without understanding consequences
# npm audit fix --force    <-- CAN INTRODUCE BREAKING CHANGES

# INVESTIGATE: When audit fix doesn't resolve
npm ls <vulnerable-package>          # See dependency tree
npm explain <vulnerable-package>     # See why it's installed

Step 5: Handle Unresolvable Vulnerabilities

When a vulnerability exists in a transitive dependency with no fix available:

# Check if the vulnerable code path is actually used
# Read the advisory -- is it relevant to your usage?

# Option A: Override the transitive dependency (npm)
# In package.json:
{
  "overrides": {
    "vulnerable-package": ">=fixed-version"
  }
}

# Option B: Override the transitive dependency (yarn)
# In package.json:
{
  "resolutions": {
    "vulnerable-package": ">=fixed-version"
  }
}

# Option C: Exclude from audit (document why)
# Create .nsprc or use npm audit --omit=dev for dev-only deps

Third-Party Scanning Tools

ToolTypeBest For
npm audit
Built-inQuick check, CI integration
SnykSaaS + CLIDeep analysis, fix PRs, monitoring
Socket.devSaaS + CLISupply chain attack detection
DependabotGitHub nativeAutomated update PRs
RenovateSelf-hosted/SaaSHighly configurable update PRs
OSV-ScannerCLIGoogle's vulnerability database

Snyk CLI Usage

# Install
npm install -g snyk

# Authenticate
snyk auth

# Test for vulnerabilities (read-only)
snyk test

# Monitor project (sends to dashboard)
snyk monitor

# Test a specific package before installing
snyk test <package-name>

OSV-Scanner Usage

# Install
go install github.com/google/osv-scanner/cmd/osv-scanner@latest

# Scan lock file
osv-scanner --lockfile=package-lock.json

# Scan entire directory
osv-scanner -r .

License Compatibility

Common License Types

LicenseTypeCan Use In CommercialMust Open Source Your CodeMust Include License
MITPermissiveYesNoYes
Apache-2.0PermissiveYesNoYes (+ NOTICE file)
BSD-2-ClausePermissiveYesNoYes
BSD-3-ClausePermissiveYesNoYes
ISCPermissiveYesNoYes
GPL-2.0CopyleftYesYes (if distributed)Yes
GPL-3.0CopyleftYesYes (if distributed)Yes
LGPL-2.1Weak CopyleftYesOnly modifications to LGPL codeYes
AGPL-3.0Strong CopyleftYesYes (even for network use)Yes
MPL-2.0Weak CopyleftYesOnly modified MPL filesYes
UnlicensePublic DomainYesNoNo
SSPLSource AvailableCheck termsYes (broad scope)Yes
BSLSource AvailableAfter change dateBefore change date, restrictedYes

Compatibility Matrix (Can A Include B?)

Your ProjectMITApache-2.0GPL-2.0GPL-3.0AGPL-3.0
MITYesYesNoNoNo
Apache-2.0YesYesNoNoNo
GPL-2.0YesNoYesNoNo
GPL-3.0YesYesYesYesNo
AGPL-3.0YesYesYesYesYes

Checking Licenses

# List all dependency licenses
npx license-checker --summary

# Check for problematic licenses
npx license-checker --failOn "GPL-2.0;GPL-3.0;AGPL-3.0"

# Export full report
npx license-checker --csv --out licenses.csv

# Production only (skip devDependencies)
npx license-checker --production --summary

CI License Check

# GitHub Actions step
- name: Check licenses
  run: |
    npx license-checker --production \
      --failOn "GPL-2.0;GPL-3.0;AGPL-3.0;SSPL-1.0" \
      --excludePackages "known-exception@1.0.0"

Dependency Health Indicators

Red Flags

IndicatorRiskCheck
No updates in 2+ yearsUnmaintained, unpatched vulns
npm view <pkg> time
Single maintainerBus factor of 1Check GitHub contributors
No tests or CIQuality unknownCheck repo for test config
Frequent ownership changesPossible supply chain riskCheck npm ownership history
Typosquat nameMalicious packageVerify exact package name
Post-install scriptsCan execute arbitrary codeCheck
scripts.postinstall
Excessive permissionsOver-scoped accessReview package contents
Many open security issuesKnown vulnerabilitiesCheck GitHub issues/advisories

Health Check Commands

# View package metadata
npm view <package-name>

# Check when last published
npm view <package-name> time --json | jq 'to_entries | sort_by(.value) | last'

# See who maintains it
npm view <package-name> maintainers

# Check download counts (popularity signal)
npm view <package-name> --json | jq '.dist-tags, .versions | length'

# List all postinstall scripts in dependencies
npm ls --json | jq '.. | .scripts?.postinstall? // empty'

# Check package size before installing
npx package-phobia <package-name>

Before Adding a New Dependency

Ask these questions before

npm install
:

  • Is this package actively maintained? (Commits in last 6 months)
  • Does it have more than one maintainer?
  • Are there open, unresolved security issues?
  • Is the license compatible with my project?
  • What is the install size and bundle size impact?
  • Does it have post-install scripts? Are they necessary?
  • Could I implement this functionality in <50 lines?
  • Is this a direct dependency or could it be a devDependency?

Safe Upgrade Strategy

The Read-Analyze-Test-Upgrade Cycle

Never upgrade blindly. Follow this cycle for each upgrade.

Step 1: Identify Available Updates

# See what's outdated (read-only)
npm outdated

# More detail
npm outdated --long

# Output:
# Package    Current  Wanted  Latest  Location
# express    4.18.2   4.18.3  5.0.0   my-app
# lodash     4.17.20  4.17.21 4.17.21 my-app

Step 2: Categorize Updates

Update TypeVersion ChangeRiskExample
Patch
x.y.Z
Low
4.18.2
->
4.18.3
(bug fixes)
Minor
x.Y.z
Medium
4.18.2
->
4.19.0
(new features)
Major
X.y.z
High
4.18.2
->
5.0.0
(breaking changes)

Step 3: Read Changelogs

# Check the changelog before upgrading
npm view <package-name> repository.url
# Then visit the repo and read CHANGELOG.md or Releases

Step 4: Upgrade in Isolation

# Upgrade one package at a time
npm install <package-name>@<version>

# Run tests immediately
npm test

# Check for type errors (TypeScript)
npx tsc --noEmit

# Check for lint issues
npm run lint

Step 5: Verify and Commit

# Verify the lock file changed as expected
git diff package-lock.json | head -50

# Commit the single upgrade
git add package.json package-lock.json
git commit -m "chore(deps): upgrade <package> to <version>"

Lock File Hygiene

Why Lock Files Matter

ConcernWithout Lock FileWith Lock File
ReproducibilityDifferent versions on each installExact same versions every time
SecurityCan get compromised newer versionPinned to known-good versions
CI reliability"Works on my machine"Same everywhere
Audit accuracyAudit results varyConsistent audit results

Lock File Rules

RuleRationale
Always commit lock filesEnsures reproducible builds
Use
npm ci
in CI, not
npm install
ci
respects lock file exactly
Review lock file diffs in PRsCatch unexpected transitive changes
Regenerate periodicallyClear accumulated cruft
Never manually edit lock filesUse npm/yarn commands instead
# CORRECT: Clean install from lock file (CI)
npm ci

# CORRECT: Install and update lock file (development)
npm install

# WRONG: Deleting lock file to "fix" issues
# rm package-lock.json && npm install   <-- loses pinned versions

Bundle Size Analysis

Measuring Impact

# Check bundle size of a package (before installing)
npx bundlephobia <package-name>

# Analyze your bundle
npx webpack-bundle-analyzer dist/stats.json

# Check what's in node_modules
npx cost-of-modules

# Compare alternatives
npx bundlephobia lodash vs ramda vs lodash-es

Size Budget Rules

MetricBudgetTool
Initial JS bundle< 200KB gzippedWebpack/Vite analyzer
Single dependency< 50KB gzippedbundlephobia
Total node_modulesMonitor trend
du -sh node_modules
Install time< 30s
time npm ci

Reducing Bundle Size

StrategyExample
Import specific functions
import debounce from 'lodash/debounce'
not
import { debounce } from 'lodash'
Use tree-shakeable packages
lodash-es
instead of
lodash
Check for smaller alternatives
date-fns
vs
moment
(tree-shakeable)
Lazy load heavy dependencies
const lib = await import('heavy-lib')
Avoid duplicate packagesCheck
npm ls <pkg>
for multiple versions

CI Integration

Audit in CI Pipeline

name: Dependency Audit
on:
  pull_request:
    paths:
      - 'package.json'
      - 'package-lock.json'
  schedule:
    # Run weekly audit on Monday mornings
    - cron: '0 8 * * 1'

jobs:
  audit:
    runs-on: ubuntu-latest
    permissions:
      contents: read
    steps:
      - uses: actions/checkout@v4

      - uses: actions/setup-node@v4
        with:
          node-version: 20
          cache: npm

      - run: npm ci

      - name: Security audit
        run: npm audit --audit-level=high

      - name: License check
        run: npx license-checker --production --failOn "GPL-2.0;GPL-3.0;AGPL-3.0"

      - name: Check for outdated (informational)
        run: npm outdated || true

Anti-Patterns

Anti-PatternProblemFix
npm audit fix --force
Introduces breaking major version bumpsUse
npm audit fix
(safe) and handle majors manually
Ignoring audit warningsVulnerabilities accumulateTriage every audit finding, document accepted risks
"*"
or
""
version ranges
Installs any version, including maliciousUse exact versions or
^
ranges with lock file
Not committing lock fileNon-reproducible buildsAlways commit
package-lock.json
/
yarn.lock
Deleting lock file to fix issuesLoses all version pinsDiagnose the actual issue, regenerate carefully
Installing without reviewingSupply chain attack vectorCheck package health before
npm install
Bulk upgrading all at onceHard to diagnose breakageUpgrade one package at a time, test between each
Running
npx
with unknown packages
Executes unreviewed codeVerify package before first
npx
usage
Ignoring post-install scriptsArbitrary code executionReview scripts, use
--ignore-scripts
when cautious
No CI audit stepVulnerabilities ship to productionAdd
npm audit
to CI pipeline
Using deprecated packagesNo security patchesFind maintained alternatives
devDependencies
in production
Larger attack surface, bigger imageUse
npm ci --omit=dev
for production builds

Quick Reference: Audit Decision Tree

npm audit reports vulnerability
  |
  +--> Is it in a devDependency only?
  |      YES --> Lower priority (not in production)
  |      NO  --> Continue
  |
  +--> Is there a patch/minor fix available?
  |      YES --> npm audit fix (safe)
  |      NO  --> Continue
  |
  +--> Is the vulnerable code path used in your app?
  |      NO  --> Document accepted risk, revisit monthly
  |      YES --> Continue
  |
  +--> Is there a major version fix?
  |      YES --> Read changelog, test upgrade in branch
  |      NO  --> Continue
  |
  +--> Can you use overrides/resolutions?
  |      YES --> Pin transitive dep to fixed version
  |      NO  --> Continue
  |
  +--> Find alternative package or implement inline