Description
Both npm install sax and a global installation without a version can resolve to a different release on the next build.
Potential impact
An application can fail if the deployment image contains a different dependency version from the one tested.
Remediation
- For packages installed directly, including global tools, specify an exact version with
package@version. - For project dependencies, review the lock file, including transitive dependencies, and install with
npm ci.
Examples
Supply an exact, reviewed version compatible with the Node.js environment through ANGULAR_CLI_VERSION. A tag or version range is not an exact pin. sax@0.1.1 is a historical syntax example, not a production recommendation. Pin Git dependencies to a verified commit rather than a range such as #semver:^5.0.
Before
dockerfile
FROM node:22
RUN npm install sax
RUN npm i -g @angular/cli
After
dockerfile
FROM node:22
ARG ANGULAR_CLI_VERSION
RUN npm install sax@0.1.1
RUN test -n "$ANGULAR_CLI_VERSION" && npm i -g "@angular/cli@${ANGULAR_CLI_VERSION}"
Explanation:
- Before: Neither
saxnor the global@angular/cliinstall specifies a version. - After: The command specifies the version of
saxdirectly and gets the global CLI version fromANGULAR_CLI_VERSION.