npm supply chain security concerns the code you install, the automation that runs it, and the identity allowed to publish a release. A lockfile helps make an installation repeatable, but repeatability alone does not establish that the selected package is trustworthy.
The topic matters whenever a dependency update, a CI workflow, or an AI-assisted change introduces code that your team did not write. You need a way to review that boundary without assuming either that every package is dangerous or that a successful build proves everything is safe.
npm's trusted-publishing documentation and provenance guidance provide useful pieces of that workflow. They address release identity and traceability. They do not remove the need to review what a package does.
This guide uses three illustrative scenarios: reviewing a dependency update, running it in CI, and publishing an organization-owned package. None of the examples asks you to publish a package or change registry credentials while reading.
Separate installation, execution, and publication
The first boundary is installation. Your project obtains packages and may run installation lifecycle scripts, depending on its configuration. That process can do more than place passive files in a directory.
The second boundary is execution. Build commands, tests, development tools, and the application itself run code. Disabling an install hook does not prove that a later build or imported module is harmless.
The third boundary is publication. An authorized person or workflow can create a release that other people install. The security of that workflow matters even if the published library is small.
These boundaries deserve different controls. A careful package review cannot compensate for an unnecessarily exposed publishing identity. A protected publisher cannot guarantee that reviewers understood a new dependency's behaviour. Write down which boundary a proposed improvement actually addresses.
What a lockfile does and does not prove
A committed lockfile records a resolved dependency graph and associated package information. For a compatible project, npm ci installs from that lockfile and checks its alignment with the package manifest rather than quietly updating the dependency plan. See the current npm ci documentation for exact behaviour and configuration requirements.
This is useful for reproducibility. A reviewer can inspect the dependency change and CI can install the same planned graph. Integrity information helps detect content that does not match the expected package artifact.
However, an expected artifact can still contain unwanted behaviour. A lockfile can faithfully record a malicious release, an unnecessary dependency, or a package with an incompatible license. It is evidence about what you intend to install, not an endorsement of the package's quality or intent.
Review lockfile diffs alongside the manifest. If a small feature adds many packages, ask which direct dependency introduced them and why the capability is needed. Large diffs are not automatically wrong, but they deserve an explanation a maintainer can understand.
Begin a review with low-impact inspection
In an existing trusted checkout, these commands help identify the project scripts and top-level dependency set without intentionally installing or running those scripts:
npm pkg get scripts
npm ls --depth=0The first prints script definitions; it does not execute them. The second reports the installed top-level dependency tree and may return a nonzero status when the local installation is missing or inconsistent. Treat that as evidence about the checkout rather than immediately “fixing” it by installing everything.
Then inspect the proposed manifest and lockfile changes in your version-control review. Check the package name carefully, including its scope. A familiar-sounding name is not proof that it belongs to the organization you expect.
For an unfamiliar repository, inspect files and scripts before running its commands. A README instruction to execute a setup script is still a request to run code. Use an appropriate isolated environment when the source is untrusted. Do not place production credentials in that environment merely to make a review command succeed.
A worked dependency-update review
Imagine a web app needs a date-formatting improvement. A proposed update adds a helper package, and the lockfile now includes a new transitive package with an installation hook. This is an illustrative review case, not an allegation against a named real package.
The useful questions are concrete: Why is the helper necessary? Which package introduced the new dependency? What does the hook do? Is the same behaviour present in the previous release? Does the change affect the browser bundle, the build environment, or both?
If the hook downloads a binary, investigate its source and verification process. If it compiles a native module, determine which platforms require that step. A legitimate build requirement and an unexplained network request should not be treated as interchangeable merely because both appear under an install script.
Record the decision in the review. “Accepted because this dependency is required for the feature; reviewed the new build hook and verified the supported build path” is useful when backed by actual evidence. “npm install worked” does not explain the trust decision.
When the dependency adds little value, using an existing platform capability may be the easier maintenance choice. Make that decision from the feature's requirements rather than turning package count into a score with no context.
Use script suppression as one review tool
For a separate disposable review checkout, one possible first installation is:
npm ci --ignore-scriptsThis intentionally installs dependencies while suppressing package scripts for that installation. It is a mutation of the review environment, so run it in a checkout intended for this purpose, not as a supposedly read-only inspection of an important working directory.
The limitation matters: npm's documentation explains that explicitly invoked commands such as npm run still execute their intended script. Dependencies can also execute when your application or tooling imports them later. Suppressing installation scripts is not a general sandbox for arbitrary package code.
Some legitimate dependencies require a reviewed native build or setup step. Document those requirements and choose a supported policy for the team's npm version. Do not respond to a failed build by enabling every hook without understanding which one is necessary.
Configuration features and defaults vary across npm releases. Record the Node and npm versions used by local development and CI, and consult their matching documentation before adopting a script policy. A copied flag from a different major version is not a reliable organization-wide control.
Keep CI credentials away from untrusted work
CI turns repository content into executed commands. A workflow that builds a change from an untrusted source needs different privileges from a workflow that publishes an approved release.
For the illustrative web app, the pull-request build should not need an npm publishing identity or production deployment secrets merely to run unit tests. If an integration test needs a service, prefer a bounded test environment with appropriate test credentials and data.
Review workflow changes with the same attention as application code. A change to the event trigger, checkout source, permissions, or release condition can alter which code receives privileged execution. Keep privileged release steps separate from ordinary validation and use the CI provider's supported controls for approvals and protected environments where appropriate.
Third-party actions and build tools are dependencies too. Maintain an inventory of the ones that execute in release jobs, use a deliberate version-selection policy, and review updates. A release pipeline can be compromised through its automation even when the application's dependency list is unchanged.
Avoid writing secrets into logs as a debugging shortcut. A failed release should produce enough evidence to diagnose the step without printing tokens, complete environment dumps, or private package credentials.
Understand what trusted publishing changes
Trusted publishing uses an authorized CI identity and OIDC-based authentication instead of relying on a long-lived npm token for that supported publishing flow. The current npm documentation lists prerequisites and provider-specific setup. Verify them for your actual runner and tooling before planning a migration.
The important design decision is which workflow identity npm trusts. Bind that relationship to the intended repository and release workflow. Review who can change the workflow and which branches, tags, or protected environments may reach the publishing step.
This is not a reason to leave old broad credentials active indefinitely. Once a new release path is tested and adopted, inventory the credentials still in use and retire unnecessary ones through the organization's normal process. Do not revoke a credential blindly if another documented release process still requires it; resolve that dependency explicitly.
For a freelance handover, the client should own the package organization, release repository, and recovery process. A package that can only be published from a contractor's personal account creates an operational dependency even when the initial release succeeds.
Provenance gives traceability, not a clean bill of health
Provenance can connect a published artifact to source and build information. That helps a reviewer investigate where a release came from and whether it matches the expected process. npm's provenance guidance explicitly distinguishes that traceability from a guarantee that the package contains no malicious code.
Suppose an authorized workflow publishes a package after an unsafe source change is merged. The release may have genuine provenance and still contain the unsafe change. Review and workflow governance remain necessary.
Use provenance as one piece of evidence. Check the expected source repository, release workflow, and artifact relationship when the information is available. An unexpected change should produce a review question, not an automatic conclusion based on a badge alone.
Likewise, a vulnerability scan is useful evidence about known reported issues. It cannot establish that every dependency is benign or that an unpublished vulnerability does not exist. Combine scanning with dependency review, runtime boundaries, and sensible release permissions.
Prepare a recovery path before an incident
If a suspicious dependency release is discovered, first establish the affected versions, environments, and execution paths. Was it installed only in a credential-free review environment, executed in CI, or shipped to production? Those facts shape the response.
Preserve relevant logs and dependency evidence, stop the affected release path, and involve the responsible security or operations owner. Rotate credentials when exposure warrants it and review where those credentials were usable. Simply deleting a package from the manifest does not undo code that already ran.
Recover through a reviewed known-good dependency state and a clean build path. Verify the resulting artifact and deployment. Keep a record of what was confirmed, what remains uncertain, and which users or systems may need action. For a serious incident, specialist response may be necessary.
The exercise is worthwhile even without an incident. If no one knows who can pause publishing or restore a release, the organization has a handover gap that can be fixed in advance.
A compact maintenance and handover checklist
Before handing a project to another developer, document the supported Node and npm versions, the normal lockfile update process, necessary lifecycle scripts, CI privilege boundaries, package ownership, and release recovery contacts. Include how the team reviews dependency and workflow changes.
Keep that documentation practical. A maintainer should be able to explain which commands install code, which commands execute it, and which identity can publish it. If one step depends on a personal token or an undocumented workstation, resolve that dependency before calling the handover complete.
For the broader transfer process, see developer project handover. For agent workflows that may introduce dependencies or scripts, see agent skills explained. My backend development services can help structure a maintainable Node.js application and release process around these boundaries.



