Skip to the main content
{}
Back to all articles

Technical article

Manage Composer and npm dependencies safely

Work from lockfiles, security audits, limited updates and reproducible builds without broad dependency changes during deployment.

By Codegenie2 minute read
  • Security & privacy
  • Manage
  • Composer
  • npm
  • dependencies
  • safely
Code window, PHP versions and software management dashboard.
In this article

Manage dependencies through locked versions, a bounded update and checks of affected behaviour. A lockfile makes installation repeatable; an audit looks for known vulnerabilities. Neither alone proves that a release works safely.

Installing and updating are different steps

Use Composer install with the reviewed composer.lock for a release. Select new versions on a development branch. For JavaScript, use the project’s package manager: npm ci belongs with package-lock.json, pnpm install --frozen-lockfile with pnpm-lock.yaml. Do not mix lockfiles to work around an error.

Example for a project using Composer and npmrelease pipelinebash
composer install --no-dev --prefer-dist --optimize-autoloader --no-interaction
composer audit --no-interaction
npm ci
npm audit --audit-level=high
npm run build

The npm commands above are not instructions to convert a pnpm project. There, use the pinned pnpm version, frozen installation, pnpm audit --audit-level high and its own build command. Stop CI on install or audit failures. Also review scripts and Composer plugins: installation can execute project code.

Illustrative single-package patch

Suppose an upload package has an advisory. Record affected versions and whether your upload path reaches the vulnerable function. Update that package, review transitive lockfile changes and test accepted and rejected uploads. Rebuild assets if frontend code changes. A low audit severity may still matter in your application; a green audit is not a general security test.

Keep the tested release together

Keep lockfiles, runtime versions, test results and artifact with the same release. Do not select new versions during production publication. A deferred advisory needs an owner, rationale and review date; do not silently disable the audit.

Bash syntax of the sample commands was checked. The commands, upgrade and production execution were not run; use them only in the suitable test environment described.

Last updated:

Need technical context for your own project?

Codegenie helps with Laravel applications, existing codebases, shared-hosting deployments and technical improvements.