PortGate

Resources · Security guides · Security guide

Commit the lockfile and install exactly what it says

Lockfiles pin every dependency to a reviewed version. Commit them, install with the lockfile-only commands in CI and deploys, and audit them on every build.

Check command

composer audit; npm audit --omit=dev

Copied.

Without a lockfile, every deploy resolves version ranges again and can pull a release that appeared minutes ago, including a hijacked one. Several 2025 and 2026 supply-chain incidents reached production that way. A committed lockfile means production runs the exact versions you tested.

Commit the lockfile

composer.lock, package-lock.json (or pnpm-lock.yaml, yarn.lock), poetry.lock or uv.lock all belong in the repository, for applications. Review changes to them in pull requests like code: a dependency update that adds an unexpected package is worth a second look.

Install from it, and only from it

# PHP: exact versions, no dev tools in production
composer install --no-dev --prefer-dist --no-interaction --optimize-autoloader

# Node: fails if package.json and the lockfile disagree
npm ci

# Python with pip: pinned requirements with hashes
pip install --require-hashes -r requirements.txt

npm install and composer update change the lockfile and should only run on a developer machine, never in CI or a deploy script.

Turn off install scripts where you can

npm packages can run code on install. For a backend build that does not need native modules:

npm ci --ignore-scripts

If something breaks, allow scripts for that one package rather than for all of them.

Audit on every build

composer audit
npm audit --omit=dev
pip-audit

Fail the build on high and critical findings in runtime dependencies. Dev-only findings matter less on a server, which is why --omit=dev is there.

Update on purpose

Lockfiles freeze known vulnerabilities as well as good versions. Schedule updates (weekly or monthly) with Dependabot or Renovate, read the changelog for anything major, and let CI run the tests before merging. Apply security fixes for things you actually run within days, not months.