Workflow recipe
Audit and upgrade risky dependencies with an agent
Audit project dependencies with Trail of Bits' supply-chain-risk-auditor skill, group upgrades by risk, update one batch on a branch and prove tests pass.
Bookmark
Bookmarks are kept in your free account, so you can find this page again on any device.
Sign in to bookmarkOn this page
To audit and upgrade risky dependencies with an agent, run your package manager’s lockfile audit on a fresh branch, use Trail of Bits’ supply-chain-risk-auditor skill to surface advisories, install scripts and unmaintained packages, and group fixes into safe patch bumps versus major migrations. Apply one risk group at a time, inspect the lockfile and changelog diff, and merge only after your real build and test suite pass.
Running npm audit fix --force or asking an agent to “update all packages” usually produces a 4,000-line lockfile diff mixed with silent major-version breaks. Splitting audit triage from upgrades keeps every pull request small enough to review and prevents an agent from pulling in unvetted transitive packages with postinstall scripts.
TerminalAbout 10 min
1. Create a clean branch and capture baseline audit output
Start from a clean commit and record both the current test status and raw vulnerability report before changing any package:
git checkout -b chore/dependency-audit
npm audit --json > /tmp/audit-before.json || true
npm outdated --json > /tmp/outdated-before.json || true
npm testIf you use Trail of Bits’ supply-chain-risk-auditor, install it at the pinned commit we reviewed so the agent can also check abandoned upstreams and install scripts:
npx skills add trailofbits/skills@149d7b21f4067765b82e67029730b42d228ef4b4 --skill supply-chain-risk-auditor -a claude-codeUse -a codex or -a cursor for Codex or Cursor. Confirm your baseline npm test passes before touching package.json. Capturing raw JSON files first also ensures the agent cannot silently drop a moderate advisory or re-run an unpinned online scan with different flags halfway through the session.
Claude CodeAbout 15 min
2. Triage advisories and group upgrades by risk
Ask the agent to inspect the audit report and lockfile without editing anything yet. Separating analysis from edits prevents the model from rushing into a speculative major-version rewrite before you know whether an advisory even affects production code.
Read the table yourself before approving any edits. Check reachability on every high or critical item: a regex denial-of-service bug inside a dev-only linter has a very different urgency from a prototype-pollution flaw in an HTTP request parser. Move any major-version upgrade (such as a framework jump) out to its own branch so security patches are never held up by a refactor.
Claude CodeAbout 15 min
3. Apply the patch-security batch only
Have the agent upgrade only the approved patch and minor security group, keeping package.json changes minimal and lockfile churn easy to inspect.
Check git diff package.json as soon as the agent finishes. Every version change in package.json should match a row you approved in step 2. Then scan the lockfile diff for "hasInstallScript": true (in package-lock.json) or unexpected tarball hosts before running your test suite, so a freshly pulled transitive dependency cannot execute unreviewed code on your machine.
TerminalAbout 10 min
4. Prove the build, tests and audit delta
Run your build, type checks, test suite and a fresh audit yourself in the terminal rather than relying on the agent’s summary:
npm run build
npm test
npm audit --omit=devCompare npm audit --omit=dev against /tmp/audit-before.json. Confirm that every targeted high or critical production advisory is cleared, that git status shows only package.json and the lockfile (plus any intentional import fixes you approved), and that no new advisory appeared from a transitive bump. If your project has a smoke test or end-to-end check against a local dev server, run it now before opening the pull request. Remove the temporary /tmp/audit-before.json and /tmp/outdated-before.json files when you finish.
GitHubAbout 5 min
5. Open a scoped pull request with evidence
Keep the pull request description short and auditable so reviewers can approve it in five minutes instead of skimming thousands of lockfile lines:
- List every upgraded package with old and new versions and links to the relevant advisory IDs or changelogs.
- Paste the before/after
npm audit --omit=devsummary counts. - Note whether any newly added transitive package includes a lifecycle install script and why it is expected.
- Record any deferred major upgrades as separate linked follow-up issues, and state which local build and test commands passed.
Check it worked
Verification checklist
0 of 7 done
When it goes wrong
If a transitive vulnerability has no upstream fix yet, do not let the agent force a major version of an unrelated direct dependency. Check whether the vulnerable code path is actually reachable in your app (for example, a build-time-only CLI tool vs a production request handler). When a vulnerability is genuinely unreachable or awaits an upstream patch, record a short exception note with the advisory ID, why it does not apply to your runtime, and a calendar review date thirty days out so it never turns into permanent invisible debt.
If tests fail after a minor upgrade, revert that single package bump first (git checkout -- package.json package-lock.json and re-apply the rest) so one breaking minor release does not block the clean security patches. Keep the failing package in a separate branch with the exact stack trace so you can inspect its release notes calmly instead of rushing a workaround into a security pull request.
If the agent tries to run npm install with arbitrary registry flags or disables lockfile integrity checks, stop the session and check your permission rules in Permissions and sandboxing for coding agents.
Variations
For pnpm workspaces, swap npm audit for pnpm audit --json and use pnpm.onlyBuiltDependencies to keep install scripts blocked unless explicitly allowlisted in package.json.
For Python projects using uv or poetry, swap step 1 for uv pip check and pip-audit -f json (or Trail of Bits’ bundled Python advisory scripts inside supply-chain-risk-auditor), and apply the same patch-first grouping on pyproject.toml and uv.lock.
For scheduled hygiene across several repositories, run step 2 only in a read-only weekly CI job that posts the triage table to an issue, and let an engineer trigger steps 3 to 5 on a branch once the batch is approved.
For larger teams, combine this recipe with Security-review a pull request with an agent when a dependency bump also requires changing authentication, cryptography or request-parsing code.
Related security guides
Review the full capabilities of Supply chain risk auditor before installing it, pair it with Verification before completion so test evidence is never skipped, and read Reviewing AI-written code for checking agent-generated upgrade diffs.
Outcome and tools
- Outcome
- A reviewed dependency upgrade branch where high-risk advisories and install-script flags have been triaged, grouped by breaking-change risk and verified by tests.
- For
- Developers, Team leads
- Variants for
- Claude Code, Codex, Cursor
Related
- Supply chain risk auditor (Trail of Bits)
Audits a project's dependencies with bundled scripts: advisories across the lockfile, abandoned upstreams, npm publisher concentration and install scripts.
- Security-review a pull request with an agent
Run an AI security code review of one pull request with Trail of Bits' differential-review skill, then test each finding with fp-check before anyone acts on it.
- Reviewing AI-written code: what to look for
The ways agent-written diffs fail, a practical review checklist, and how to set up the work so review stays manageable.
- Permissions and sandboxing for coding agents
Set up Claude Code permission modes and rules, the Codex sandbox and approvals, and a dev container, so an agent can work without free rein.
- Upgrade a dependency with an AI coding agent, without surprises
Get an impact list from the migration guide, bump on a branch, let the agent fix with guardrails, then compare old and new output.