---
title: npm install command without pinned version
description: Datadog, the leading service for cloud-scale monitoring.
breadcrumbs: >-
  Docs > Datadog Security > Code Security > Infrastructure as Code (IaC)
  Security > IaC Security Rules > npm install command without pinned version
---

> For the complete documentation index, see [llms.txt](https://docs.datadoghq.com/llms.txt).

# npm install command without pinned version

{% callout %}
# Important note for users on the following Datadog sites: app.ddog-gov.com, us2.ddog-gov.com

{% alert level="danger" %}
This product is not supported for your selected [Datadog site](https://docs.datadoghq.com/getting_started/site.md). ({% placeholder "user-datadog-site-name" /%}).
{% /alert %}

{% /callout %}

## Metadata{% #metadata %}

**Id:** `dockerfile-npm-install-without-pinned-version` 

**Platform:** Dockerfile

**Severity:** Medium

**Category:** Supply-Chain

#### Learn More{% #learn-more %}

- [Provider Reference](https://docs.docker.com/engine/reference/builder/#run)

### Description{% #description %}

Installing packages without pinned versions risks unintentional or malicious dependency upgrades, leading to supply-chain compromises, newly introduced vulnerabilities, or non-reproducible builds.

This rule inspects `run` command entries that invoke `npm` or `pnpm` with the `install`, `i`, or `add` subcommand, and requires each package argument (excluding command flags) to include an explicit version or tag (for example, `package@1.2.3` or `@scope/pkg@^1.2.3`) or be a git-based reference (for example, `git+https://...`). Tokens that start with `-` are allowed, as are the values of flags that take one, such as `npm install --registry <url>` and pnpm workspace filters like `pnpm add --filter <pattern>`. Lockfile-driven installs that name no package, such as `npm ci`, `npm install` and `pnpm install --frozen-lockfile`, are not reported: the lockfile is the pinning mechanism. Scoped packages must still include a version suffix and bare package names without an `@version` will be flagged.

Secure example with pinned versions:

```json
{
  "scripts": {
    "install-deps": "npm install express@4.17.1 lodash@4.17.21 @scope/pkg@1.2.3"
  }
}
```

## Compliant Code Examples{% #compliant-code-examples %}

```dockerfile
FROM node:12
RUN npm install
RUN npm install sax@latest
RUN npm install sax@0.1.1
RUN npm install sax@0.1.1 | grep fail && npm install sax@latest
RUN npm install git://github.com/npm/cli.git
RUN npm install git+ssh://git@github.com:npm/cli#semver:^5.0
RUN npm install --production --no-cache
RUN npm config set registry <internal_npm_registry> && \
    npm install && \
    npx vite build --mode $VITE_MODE
```

```dockerfile
FROM node:12
RUN npm install --registry https://registry.npmjs.org lodash@4.17.21
RUN npm install --userconfig /etc/npmrc --cache /tmp/npm-cache sax@0.1.1
RUN npm install --tag beta express@4.18.2
RUN npm install --prefix /usr/src/app --loglevel warn sax@0.1.1
RUN npm i sax@1.0.0
RUN npm add sax@1.0.0
RUN npm install -w packages/api lodash@4.17.21
```

```dockerfile
FROM node:24-slim
# pnpm pins through pnpm-lock.yaml, and its binary name must not be read as a
# package argument. Workspace filters carry scoped names that look like packages.
RUN corepack prepare pnpm@10.27.0 --activate
RUN pnpm install --frozen-lockfile
RUN pnpm i --frozen-lockfile
RUN pnpm install --filter trpc... --frozen-lockfile --shamefully-hoist
RUN pnpm install --filter @risksmart-app/tenant-deployer --filter @risksmart-app/shared --frozen-lockfile --prod --ignore-scripts
RUN pnpm add express@4.18.2
RUN pnpm --filter @scope/app add express@4.18.2
# an npm path appearing as a plain argument is not an install command
RUN rm -rf /usr/local/lib/node_modules/npm /usr/local/bin/npm /usr/local/bin/npx
# the wrapper around an install is not a package argument
RUN sudo npm install sax@1.0.0
RUN NODE_ENV=production npm install sax@1.0.0
# upgrading npm itself
RUN npm install -g npm
# a workspace named `install` is a filter value, not the subcommand
RUN pnpm --filter install i --frozen-lockfile
# quoting must not change whether a pinned install is accepted
RUN su node -c "npm install express@4.18.2"
RUN su node -c "npm install -g npm"
# pnpm accepts npm's configuration flags, which take a separate value
RUN pnpm --filter app install --fetch-timeout 60000 --frozen-lockfile
RUN pnpm install --https-proxy http://proxy:8080 --frozen-lockfile
# separators inside quoted arguments must not split the command
RUN npm install --registry 'https://registry.example.com/a;b' sax@1.0.0
RUN npm install sax@1.0.0 && grep -E 'a|b' file
```

## Non-Compliant Code Examples{% #non-compliant-code-examples %}

```dockerfile
FROM node:12
RUN npm install sax
RUN npm install sax --no-cache
RUN npm install sax | grep fail && npm install sax@latest
RUN npm install sax@latest | grep fail && npm install sax
RUN npm install sax | grep fail && npm install sax
RUN npm i -g @angular/cli
RUN ["npm","add","sax"]
```

```dockerfile
FROM node:12
RUN npm install https://example.com/packages/sax.tgz
```

```dockerfile
FROM node:12
RUN npm install npm add
RUN npm i sax add
RUN npm install --registry https://registry.npmjs.org add
```
