> For the complete documentation index, see [llms.txt](https://docs.sealsecurity.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.sealsecurity.io/using-platform/working-with-seal-apps/artifact-server/npm.md).

# Editing npm dependencies

Pin sealed versions in package.json with npm overrides for direct and transitive dependencies, run npm install, and verify the result.

This page explains how to replace vulnerable npm packages with their sealed versions when npm pulls from the Seal Artifact Server. You edit `package.json` and run `npm install`, which updates `package-lock.json`.

## Before you start

* npm reaches Seal's registry, either `https://npm.sealsecurity.io/` directly or through an Artifactory or Nexus remote. See [Configuring npm](https://docs.sealsecurity.io/setup-apps-os/artifact-server/configuring-package-managers/npm.md).
* Check `npm --version`. This page applies as written to npm 8.7.0 and later. With npm 6, 7 or 8.3 to 8.6, `overrides` do not take effect and you also edit the lockfile; see [Older npm versions](#older-npm-versions).
* In an npm workspace, `overrides` work only in the root `package.json`.

## Rules

* **Pin the exact sealed version.** A sealed version `<origin>-sp<N>` is a semver pre-release, so it sorts below its origin (`2.7.4-sp1 < 2.7.4`) and no ordinary range such as `^2.7.0` or `>=2.7.4` matches it. A range such as `^2.7.4-sp1` matches it but also lets npm move to `2.7.5`.
* **Use the sealed version of the installed version only.** A sealed version keeps its origin's dependencies. Replacing `body-parser@1.19.0` with `1.20.2-sp2` brings in the dependency tree of `1.20.2`.
* **Use the** [**safest version**](https://docs.sealsecurity.io/introduction/glossary.md#safest-version) **Seal recommends.** Do not pick one by sorting: `sp10` sorts before `sp2`.

## Direct dependencies

For a package in your root `package.json`, installed at `V`, pin the sealed version and add an override that points every other dependency on the package at your pin:

```diff
 {
   "dependencies": {
-    "ejs": "^2.7.0"
+    "ejs": "2.7.4-sp2"
+  },
+  "overrides": {
+    "ejs@2.7.4": "$ejs"
   }
 }
```

`"$ejs"` refers to the version your root `package.json` declares, so the override follows the pin. Keep the dependency in the section it was in, for example `devDependencies`.

Add the override for every direct dependency you seal, in the same edit as the pin. Other packages that depend on it, or declare it as a peer, ask for a range that does not accept the pre-release pin. Without the override, npm silently installs a second, unsealed copy for them, or reports the peer as `invalid` in `npm ls` or fails with `ERESOLVE`.

If a linked or workspace package (a `file:` dependency or a workspace member) declares the package as a peer, `npm ls` still reports it as `invalid` before npm 11.14. Add the sealed version to that package's peer range, for example `"lodash": "^4.17.0 || 4.17.21-sp1"`.

{% hint style="warning" %}
Do not override a direct dependency that is still on `V` (for example `"ejs@2.7.4": "2.7.4-sp2"` with `"ejs": "2.7.4"`). npm fails with `EOVERRIDE`. Pin the dependency and use `"$ejs"`.
{% endhint %}

## Transitive dependencies

For a package that another package brings in, add an override keyed by the installed version:

```json
{
  "overrides": {
    "qs@6.7.0": "6.7.0-sp1"
  }
}
```

* Always include the version in the key. A bare `"qs"` key replaces every copy of `qs`, including copies at other versions.
* One key covers every copy of that version. Add one key per installed version you seal.

A key also applies to any other dependency range that includes that version. If `npm ls` then reports the package as `invalid`, scope the override under the parent that installs it:

```json
{
  "overrides": {
    "some-framework": {
      "lodash@4.17.15": "4.17.15-sp2"
    }
  }
}
```

Before npm 11.6, `npm ls` can report a scoped override as `invalid` even though the sealed version is installed. Check the installed version instead.

## Step-by-step: applying sealed versions

1. **List what is installed.** From `package-lock.json`, record each package's name and version. A package listed in the root `package.json` is direct; every other package is transitive.
2. **Find the sealed version** of each installed version, on the [Vulnerable packages tab](https://docs.sealsecurity.io/discovering/protection-page/vulnerable-packages-tab.md), the [Repository page](https://docs.sealsecurity.io/discovering/repository-page/sealed-packages.md), or with the [Seal MCP server](#using-the-seal-mcp-server). Note any open vulnerabilities the sealed version still has. A [private version](https://docs.sealsecurity.io/discovering/private-versions.md) must be enabled for your Seal Project before the artifact server serves it.
3. **Edit `package.json`** as described in [Direct dependencies](#direct-dependencies) and [Transitive dependencies](#transitive-dependencies). Keep any existing `overrides` entries.
4. **Run `npm install`** with the existing `package-lock.json` in place. On npm 6, 7 or 8.3 to 8.6, follow [Older npm versions](#older-npm-versions) instead.
5. **Verify:**
   * `npm ls --all` exits 0, apart from the two npm-version cases above.
   * In `package-lock.json`, no package you sealed is still at its origin version; search by package name, not by path. npm can move an overridden package to another path, for example from `node_modules/qs` to `node_modules/express/node_modules/qs`.
   * `rm -rf node_modules && npm ci` succeeds, and the build and tests pass.
6. **Report** each package sealed, any open vulnerabilities left in it, and each vulnerable package with no sealed version. You can request a sealed version with [Generate fix](https://docs.sealsecurity.io/discovering/generate-fix.md).

{% hint style="warning" %}
Never delete `package-lock.json` or `node_modules` to make overrides apply. Without the lockfile, npm resolves every package again and applies `"qs@6.5.2"` to any range that includes `6.5.2`, so an installed `qs@6.5.5` is downgraded to `6.5.2-sp1`. Also avoid `npm update`, `npm audit fix`, `--force` and `--legacy-peer-deps`, which hide the problems step 5 checks for.
{% endhint %}

## Older npm versions

npm 6 and 7 ignore `overrides`, and npm 8.3 to 8.6 do not apply them to an existing lockfile. Make the `package.json` edit anyway, then edit `package-lock.json` in the format it already has:

1. Find every entry for each package you seal, `X` installed at `V`:
   * `lockfileVersion` 1 (npm 6): in the nested `dependencies` object, at any depth.
   * `lockfileVersion` 2 (npm 7 and 8): in both the `packages` object and the nested `dependencies` object.
2. In each entry, change three fields and leave the rest unchanged:
   * `version`: `V-spN`.
   * `resolved`: the same URL, with the file name changed to `X-V-spN.tgz` (for `@scope/name`, `name-V-spN.tgz`).
   * `integrity`: the output of `npm view X@V-spN dist.integrity`.
3. With `lockfileVersion` 2, copy the new pins from `package.json` into `packages[""].dependencies` (and `devDependencies`).
4. Run `rm -rf node_modules && npm ci`, and check that each edited path holds `V-spN` and that the build and tests pass. On these npm versions, `npm ls` reports the sealed packages as `invalid`, `missing` or `extraneous`, which is expected.

Install with `npm ci` from then on. On npm 6, a plain `npm install` reverts the edited packages to their origin versions. On npm 7 and 8, changing dependencies can bring an origin version back, so check again after each dependency change.

## Example

An Express app has `ejs@2.7.4` (`"^2.7.0"`) and `lodash@4.17.21` as direct dependencies, and `qs@6.7.0` and `path-to-regexp@0.1.7` through `express`.

{% code title="package.json" %}

```diff
   "dependencies": {
-    "ejs": "^2.7.0",
+    "ejs": "2.7.4-sp2",
     "express": "4.17.1",
-    "lodash": "4.17.21"
+    "lodash": "4.17.21-sp1"
+  },
+  "overrides": {
+    "ejs@2.7.4": "$ejs",
+    "lodash@4.17.21": "$lodash",
+    "path-to-regexp@0.1.7": "0.1.7-sp3",
+    "qs@6.7.0": "6.7.0-sp1"
   }
```

{% endcode %}

The `qs` override replaces both copies of `qs@6.7.0`, under `express` and under `body-parser`.

## Using the Seal MCP server

An AI coding agent connected to the [Seal MCP server](https://docs.sealsecurity.io/reference/mcp-server/what-it-is.md) can follow the steps above with these tools:

| Step                                         | Tool                                                                                                                                                                                                              |
| -------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 2. Find the sealed version                   | `search_packages` with `query=<name>`, `package_manager="NPM"` and `version_prefix=<installed version>`. Keep only the row whose name and version match exactly; its `recommended_version` is the safest version. |
| 2. Check the origin and open vulnerabilities | `get_package_details`                                                                                                                                                                                             |
| 6. Request a sealed version                  | `create_generate_fix_request`. Ask the user first.                                                                                                                                                                |

## Troubleshooting

| Symptom                                                         | Fix                                                                                                                                                          |
| --------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `EOVERRIDE ... conflicts with direct dependency`                | Pin the direct dependency and use `"X@V": "$X"`.                                                                                                             |
| `ERESOLVE`, or `npm ls` reports a sealed package as `invalid`   | Add `"X@V": "$X"` for a direct dependency, or scope the override under the parent. For a linked or workspace package before npm 11.14, widen its peer range. |
| `ETARGET No matching version found for X@V-spN`, or `E404`      | npm is not pulling from the artifact server, or the version is private and not enabled. Check with `npm view X@V-spN version`.                               |
| Transitive packages keep their origin versions                  | npm is earlier than 8.7.0. Follow [Older npm versions](#older-npm-versions).                                                                                 |
| A package was downgraded to a sealed version of an older origin | The lockfile was deleted. Restore it and run `npm install` again.                                                                                            |

## Related

* [Configuring npm](https://docs.sealsecurity.io/setup-apps-os/artifact-server/configuring-package-managers/npm.md)
* [Per-ecosystem nuances](https://docs.sealsecurity.io/reference/naming-and-versioning/per-ecosystem.md): how sealed versions are named and ordered in each ecosystem.
* [Private versions](https://docs.sealsecurity.io/discovering/private-versions.md)
