Dependencies and Package Safety
Before adding a package, check who publishes it, what it runs, and what it adds to your lockfile. Fix advisories with targeted upgrades, not forced ones.
Content date: October 21, 2026.
Plain English
A dependency is someone else's code that your project uses. It may bring in more packages, called transitive dependencies. It may also include install scripts: programs that run during installation. A lockfile, such as npm's package-lock.json, records exact versions so installs repeat. It does not prove those versions are safe. Since September 2025, Shai-Hulud worms have stolen publishers' credentials and spread poisoned updates through popular npm packages.
Use this when
Think it through before an agent installs a package, when a security advisory affects your project, and when an upgrade changes the set of dependencies.
If you are just starting
Check whether your code or platform already does the job. If you need a package, verify its exact name; one wrong letter can mean a different package. Check its publisher, repository, release history, license, and install scripts. After installation, run `git diff` to see the changes. Read package.json and package-lock.json together. Stop and ask why if the lockfile changed much more than expected.
When your project grows
Track which versions you use and which advisories apply, and ask whether the vulnerable code is reachable. Fix one thing at a time, with a test and a way back. `npm audit` lists known advisories; a clean report isn't a security review. As of October 2026, npm 12 doesn't run dependency install scripts unless your package.json allows them, and `npm approve-scripts` lists and approves them. On older npm, `npm install --ignore-scripts` skips them. Malicious code can still run when you use the package, so this lowers risk without removing it.
Worked example
An agent suggests a package to show "posted 3 days ago" on a bakery's blog. The browser already has a built-in date formatter, so you skip it. Months later the site needs charts. You check the library's publisher and release notes, see it brings nine other packages and no install scripts, and test the order page on its own branch.
Practice
Review one dependency decision
- Pick a package in your practice project's package.json, or one an AI suggested, and write the job it does in one sentence.
- Open its page on npmjs.com and its repository. Confirm the name, publisher, license, and last release date. Look in package.json for install-related entries under "scripts," without running anything.
- Decide to keep it, remove it, or update it to a specific version, and write two sentences of reasoning.
- If you change it, use a practice branch, run `git diff` to read the package.json and lockfile changes, and test the pages that use it.
- Save your decision, the diff summary, your test results, and the commands that would revert it. Choosing not to install is a valid result.
Deliverable: A one-page dependency review: the package's identity, what changed, test results, and your decision with a way back.
Common mistakes to watch for
- An AI suggests a package whose name is one letter off, owned by an unrelated publisher.
- An install script runs on your computer, where it can read keys in your .env files.
- A package you use ships a new version after its maintainer's account is hijacked, and your next update installs it.
- You run `npm audit fix --force` to clear warnings, and a major upgrade breaks checkout.
Prompting
A weak prompt
Install whatever packages you think we need, then force-fix all the audit warnings.
A better prompt
First tell me whether we need a new package or whether the browser or our code already does this. If we do, confirm the exact name, publisher, repository, license, release history, and install scripts from the official package page. Make the smallest change, show me the package.json and lockfile diff, and check the affected pages and production build. For an advisory, say whether it affects our use and propose a targeted fix. Don't run npm audit fix --force or unreviewed scripts where they can see my keys.
Installing a package means running a stranger's code and accepting its updates, so five minutes of checking is cheap security.
Check before you move on
- You wrote down why the package is needed.
- You confirmed its exact name and publisher.
- You checked the license and install scripts.
- You read the lockfile diff for surprises.
- You tested affected pages and the production build.
- You noted when to review or remove it.
You are done when
- You can explain why each dependency is in the project, or why you avoided one.
- Any accepted change was tested, and you can restore the previous state from Git.
Questions to think about
`npm audit` reports no problems. Can you treat the package as safe?
No. Audit only knows about problems already reported. A new malicious version, hijacked account, or lookalike name won't show up.
You added one package and the lockfile gained dozens of lines. Is that a problem?
It's normal but worth reading. Each line is another package that runs on your computer or in your app.
An AI recommends a package to format phone numbers. Must you install it?
No. First check whether your platform or code already does it, because every dependency adds risk and upkeep.