1<!DOCTYPE html><html><head> 2<meta charset="utf-8"> 3<title>npm-audit</title> 4<style> 5body { 6 background-color: #ffffff; 7 color: #24292e; 8 9 margin: 0; 10 11 line-height: 1.5; 12 13 font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji"; 14} 15#rainbar { 16 height: 10px; 17 background-image: linear-gradient(139deg, #fb8817, #ff4b01, #c12127, #e02aff); 18} 19 20a { 21 text-decoration: none; 22 color: #0366d6; 23} 24a:hover { 25 text-decoration: underline; 26} 27 28pre { 29 margin: 1em 0px; 30 padding: 1em; 31 border: solid 1px #e1e4e8; 32 border-radius: 6px; 33 34 display: block; 35 overflow: auto; 36 37 white-space: pre; 38 39 background-color: #f6f8fa; 40 color: #393a34; 41} 42code { 43 font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; 44 font-size: 85%; 45 padding: 0.2em 0.4em; 46 background-color: #f6f8fa; 47 color: #393a34; 48} 49pre > code { 50 padding: 0; 51 background-color: inherit; 52 color: inherit; 53} 54h1, h2, h3 { 55 font-weight: 600; 56} 57 58#logobar { 59 background-color: #333333; 60 margin: 0 auto; 61 padding: 1em 4em; 62} 63#logobar .logo { 64 float: left; 65} 66#logobar .title { 67 font-weight: 600; 68 color: #dddddd; 69 float: left; 70 margin: 5px 0 0 1em; 71} 72#logobar:after { 73 content: ""; 74 display: block; 75 clear: both; 76} 77 78#content { 79 margin: 0 auto; 80 padding: 0 4em; 81} 82 83#table_of_contents > h2 { 84 font-size: 1.17em; 85} 86#table_of_contents ul:first-child { 87 border: solid 1px #e1e4e8; 88 border-radius: 6px; 89 padding: 1em; 90 background-color: #f6f8fa; 91 color: #393a34; 92} 93#table_of_contents ul { 94 list-style-type: none; 95 padding-left: 1.5em; 96} 97#table_of_contents li { 98 font-size: 0.9em; 99} 100#table_of_contents li a { 101 color: #000000; 102} 103 104header.title { 105 border-bottom: solid 1px #e1e4e8; 106} 107header.title > h1 { 108 margin-bottom: 0.25em; 109} 110header.title > .description { 111 display: block; 112 margin-bottom: 0.5em; 113 line-height: 1; 114} 115 116footer#edit { 117 border-top: solid 1px #e1e4e8; 118 margin: 3em 0 4em 0; 119 padding-top: 2em; 120} 121</style> 122</head> 123<body> 124<div id="banner"> 125<div id="rainbar"></div> 126<div id="logobar"> 127<svg class="logo" role="img" height="32" width="32" viewBox="0 0 700 700"> 128<polygon fill="#cb0000" points="0,700 700,700 700,0 0,0"></polygon> 129<polygon fill="#ffffff" points="150,550 350,550 350,250 450,250 450,550 550,550 550,150 150,150"></polygon> 130</svg> 131<div class="title"> 132npm command-line interface 133</div> 134</div> 135</div> 136 137<section id="content"> 138<header class="title"> 139<h1 id="npm-audit">npm-audit</h1> 140<span class="description">Run a security audit</span> 141</header> 142 143<section id="table_of_contents"> 144<h2 id="table-of-contents">Table of contents</h2> 145<div id="_table_of_contents"><ul><li><a href="#synopsis">Synopsis</a></li><li><a href="#description">Description</a></li><li><a href="#audit-signatures">Audit Signatures</a></li><li><a href="#audit-endpoints">Audit Endpoints</a></li><ul><li><a href="#bulk-advisory-endpoint">Bulk Advisory Endpoint</a></li><li><a href="#quick-audit-endpoint">Quick Audit Endpoint</a></li><li><a href="#scrubbing">Scrubbing</a></li><li><a href="#calculating-meta-vulnerabilities-and-remediations">Calculating Meta-Vulnerabilities and Remediations</a></li></ul><li><a href="#exit-code">Exit Code</a></li><li><a href="#examples">Examples</a></li><li><a href="#configuration">Configuration</a></li><ul><li><a href="#audit-level"><code>audit-level</code></a></li><li><a href="#dry-run"><code>dry-run</code></a></li><li><a href="#force"><code>force</code></a></li><li><a href="#json"><code>json</code></a></li><li><a href="#package-lock-only"><code>package-lock-only</code></a></li><li><a href="#omit"><code>omit</code></a></li><li><a href="#foreground-scripts"><code>foreground-scripts</code></a></li><li><a href="#ignore-scripts"><code>ignore-scripts</code></a></li><li><a href="#workspace"><code>workspace</code></a></li><li><a href="#workspaces"><code>workspaces</code></a></li><li><a href="#include-workspace-root"><code>include-workspace-root</code></a></li><li><a href="#install-links"><code>install-links</code></a></li></ul><li><a href="#see-also">See Also</a></li></ul></div> 146</section> 147 148<div id="_content"><h3 id="synopsis">Synopsis</h3> 149<pre><code class="language-bash">npm audit [fix|signatures] 150</code></pre> 151<h3 id="description">Description</h3> 152<p>The audit command submits a description of the dependencies configured in 153your project to your default registry and asks for a report of known 154vulnerabilities. If any vulnerabilities are found, then the impact and 155appropriate remediation will be calculated. If the <code>fix</code> argument is 156provided, then remediations will be applied to the package tree.</p> 157<p>The command will exit with a 0 exit code if no vulnerabilities were found.</p> 158<p>Note that some vulnerabilities cannot be fixed automatically and will 159require manual intervention or review. Also note that since <code>npm audit fix</code> runs a full-fledged <code>npm install</code> under the hood, all configs that 160apply to the installer will also apply to <code>npm install</code> -- so things like 161<code>npm audit fix --package-lock-only</code> will work as expected.</p> 162<p>By default, the audit command will exit with a non-zero code if any 163vulnerability is found. It may be useful in CI environments to include the 164<code>--audit-level</code> parameter to specify the minimum vulnerability level that 165will cause the command to fail. This option does not filter the report 166output, it simply changes the command's failure threshold.</p> 167<h3 id="audit-signatures">Audit Signatures</h3> 168<p>To ensure the integrity of packages you download from the public npm registry, or any registry that supports signatures, you can verify the registry signatures of downloaded packages using the npm CLI.</p> 169<p>Registry signatures can be verified using the following <code>audit</code> command:</p> 170<pre><code class="language-bash">$ npm audit signatures 171</code></pre> 172<p>The npm CLI supports registry signatures and signing keys provided by any registry if the following conventions are followed:</p> 173<ol> 174<li>Signatures are provided in the package's <code>packument</code> in each published version within the <code>dist</code> object:</li> 175</ol> 176<pre><code class="language-json">"dist":{ 177 "..omitted..": "..omitted..", 178 "signatures": [{ 179 "keyid": "SHA256:{{SHA256_PUBLIC_KEY}}", 180 "sig": "a312b9c3cb4a1b693e8ebac5ee1ca9cc01f2661c14391917dcb111517f72370809..." 181 }] 182} 183</code></pre> 184<p>See this <a href="https://registry.npmjs.org/light-cycle/1.4.3">example</a> of a signed package from the public npm registry.</p> 185<p>The <code>sig</code> is generated using the following template: <code>${package.name}@${package.version}:${package.dist.integrity}</code> and the <code>keyid</code> has to match one of the public signing keys below.</p> 186<ol start="2"> 187<li>Public signing keys are provided at <code>registry-host.tld/-/npm/v1/keys</code> in the following format:</li> 188</ol> 189<pre><code>{ 190 "keys": [{ 191 "expires": null, 192 "keyid": "SHA256:{{SHA256_PUBLIC_KEY}}", 193 "keytype": "ecdsa-sha2-nistp256", 194 "scheme": "ecdsa-sha2-nistp256", 195 "key": "{{B64_PUBLIC_KEY}}" 196 }] 197} 198</code></pre> 199<p>Keys response:</p> 200<ul> 201<li><code>expires</code>: null or a simplified extended ISO 8601 format: <code>YYYY-MM-DDTHH:mm:ss.sssZ</code></li> 202<li><code>keydid</code>: sha256 fingerprint of the public key</li> 203<li><code>keytype</code>: only <code>ecdsa-sha2-nistp256</code> is currently supported by the npm CLI</li> 204<li><code>scheme</code>: only <code>ecdsa-sha2-nistp256</code> is currently supported by the npm CLI</li> 205<li><code>key</code>: base64 encoded public key</li> 206</ul> 207<p>See this example key's response from the public npm registry.</p> 208<h3 id="audit-endpoints">Audit Endpoints</h3> 209<p>There are two audit endpoints that npm may use to fetch vulnerability 210information: the <code>Bulk Advisory</code> endpoint and the <code>Quick Audit</code> endpoint.</p> 211<h4 id="bulk-advisory-endpoint">Bulk Advisory Endpoint</h4> 212<p>As of version 7, npm uses the much faster <code>Bulk Advisory</code> endpoint to 213optimize the speed of calculating audit results.</p> 214<p>npm will generate a JSON payload with the name and list of versions of each 215package in the tree, and POST it to the default configured registry at 216the path <code>/-/npm/v1/security/advisories/bulk</code>.</p> 217<p>Any packages in the tree that do not have a <code>version</code> field in their 218package.json file will be ignored. If any <code>--omit</code> options are specified 219(either via the <a href="../using-npm/config#omit.html"><code>--omit</code> config</a>, or one of the 220shorthands such as <code>--production</code>, <code>--only=dev</code>, and so on), then packages will 221be omitted from the submitted payload as appropriate.</p> 222<p>If the registry responds with an error, or with an invalid response, then 223npm will attempt to load advisory data from the <code>Quick Audit</code> endpoint.</p> 224<p>The expected result will contain a set of advisory objects for each 225dependency that matches the advisory range. Each advisory object contains 226a <code>name</code>, <code>url</code>, <code>id</code>, <code>severity</code>, <code>vulnerable_versions</code>, and <code>title</code>.</p> 227<p>npm then uses these advisory objects to calculate vulnerabilities and 228meta-vulnerabilities of the dependencies within the tree.</p> 229<h4 id="quick-audit-endpoint">Quick Audit Endpoint</h4> 230<p>If the <code>Bulk Advisory</code> endpoint returns an error, or invalid data, npm will 231attempt to load advisory data from the <code>Quick Audit</code> endpoint, which is 232considerably slower in most cases.</p> 233<p>The full package tree as found in <code>package-lock.json</code> is submitted, along 234with the following pieces of additional metadata:</p> 235<ul> 236<li><code>npm_version</code></li> 237<li><code>node_version</code></li> 238<li><code>platform</code></li> 239<li><code>arch</code></li> 240<li><code>node_env</code></li> 241</ul> 242<p>All packages in the tree are submitted to the Quick Audit endpoint. 243Omitted dependency types are skipped when generating the report.</p> 244<h4 id="scrubbing">Scrubbing</h4> 245<p>Out of an abundance of caution, npm versions 5 and 6 would "scrub" any 246packages from the submitted report if their name contained a <code>/</code> character, 247so as to avoid leaking the names of potentially private packages or git 248URLs.</p> 249<p>However, in practice, this resulted in audits often failing to properly 250detect meta-vulnerabilities, because the tree would appear to be invalid 251due to missing dependencies, and prevented the detection of vulnerabilities 252in package trees that used git dependencies or private modules.</p> 253<p>This scrubbing has been removed from npm as of version 7.</p> 254<h4 id="calculating-meta-vulnerabilities-and-remediations">Calculating Meta-Vulnerabilities and Remediations</h4> 255<p>npm uses the 256<a href="http://npm.im/@npmcli/metavuln-calculator"><code>@npmcli/metavuln-calculator</code></a> 257module to turn a set of security advisories into a set of "vulnerability" 258objects. A "meta-vulnerability" is a dependency that is vulnerable by 259virtue of dependence on vulnerable versions of a vulnerable package.</p> 260<p>For example, if the package <code>foo</code> is vulnerable in the range <code>>=1.0.2 <2.0.0</code>, and the package <code>bar</code> depends on <code>foo@^1.1.0</code>, then that version 261of <code>bar</code> can only be installed by installing a vulnerable version of <code>foo</code>. 262In this case, <code>bar</code> is a "metavulnerability".</p> 263<p>Once metavulnerabilities for a given package are calculated, they are 264cached in the <code>~/.npm</code> folder and only re-evaluated if the advisory range 265changes, or a new version of the package is published (in which case, the 266new version is checked for metavulnerable status as well).</p> 267<p>If the chain of metavulnerabilities extends all the way to the root 268project, and it cannot be updated without changing its dependency ranges, 269then <code>npm audit fix</code> will require the <code>--force</code> option to apply the 270remediation. If remediations do not require changes to the dependency 271ranges, then all vulnerable packages will be updated to a version that does 272not have an advisory or metavulnerability posted against it.</p> 273<h3 id="exit-code">Exit Code</h3> 274<p>The <code>npm audit</code> command will exit with a 0 exit code if no vulnerabilities 275were found. The <code>npm audit fix</code> command will exit with 0 exit code if no 276vulnerabilities are found <em>or</em> if the remediation is able to successfully 277fix all vulnerabilities.</p> 278<p>If vulnerabilities were found the exit code will depend on the 279<a href="../using-npm/config#audit-level.html"><code>audit-level</code> config</a>.</p> 280<h3 id="examples">Examples</h3> 281<p>Scan your project for vulnerabilities and automatically install any compatible 282updates to vulnerable dependencies:</p> 283<pre><code class="language-bash">$ npm audit fix 284</code></pre> 285<p>Run <code>audit fix</code> without modifying <code>node_modules</code>, but still updating the 286pkglock:</p> 287<pre><code class="language-bash">$ npm audit fix --package-lock-only 288</code></pre> 289<p>Skip updating <code>devDependencies</code>:</p> 290<pre><code class="language-bash">$ npm audit fix --only=prod 291</code></pre> 292<p>Have <code>audit fix</code> install SemVer-major updates to toplevel dependencies, not 293just SemVer-compatible ones:</p> 294<pre><code class="language-bash">$ npm audit fix --force 295</code></pre> 296<p>Do a dry run to get an idea of what <code>audit fix</code> will do, and <em>also</em> output 297install information in JSON format:</p> 298<pre><code class="language-bash">$ npm audit fix --dry-run --json 299</code></pre> 300<p>Scan your project for vulnerabilities and just show the details, without 301fixing anything:</p> 302<pre><code class="language-bash">$ npm audit 303</code></pre> 304<p>Get the detailed audit report in JSON format:</p> 305<pre><code class="language-bash">$ npm audit --json 306</code></pre> 307<p>Fail an audit only if the results include a vulnerability with a level of moderate or higher:</p> 308<pre><code class="language-bash">$ npm audit --audit-level=moderate 309</code></pre> 310<h3 id="configuration">Configuration</h3> 311<h4 id="audit-level"><code>audit-level</code></h4> 312<ul> 313<li>Default: null</li> 314<li>Type: null, "info", "low", "moderate", "high", "critical", or "none"</li> 315</ul> 316<p>The minimum level of vulnerability for <code>npm audit</code> to exit with a non-zero 317exit code.</p> 318<h4 id="dry-run"><code>dry-run</code></h4> 319<ul> 320<li>Default: false</li> 321<li>Type: Boolean</li> 322</ul> 323<p>Indicates that you don't want npm to make any changes and that it should 324only report what it would have done. This can be passed into any of the 325commands that modify your local installation, eg, <code>install</code>, <code>update</code>, 326<code>dedupe</code>, <code>uninstall</code>, as well as <code>pack</code> and <code>publish</code>.</p> 327<p>Note: This is NOT honored by other network related commands, eg <code>dist-tags</code>, 328<code>owner</code>, etc.</p> 329<h4 id="force"><code>force</code></h4> 330<ul> 331<li>Default: false</li> 332<li>Type: Boolean</li> 333</ul> 334<p>Removes various protections against unfortunate side effects, common 335mistakes, unnecessary performance degradation, and malicious input.</p> 336<ul> 337<li>Allow clobbering non-npm files in global installs.</li> 338<li>Allow the <code>npm version</code> command to work on an unclean git repository.</li> 339<li>Allow deleting the cache folder with <code>npm cache clean</code>.</li> 340<li>Allow installing packages that have an <code>engines</code> declaration requiring a 341different version of npm.</li> 342<li>Allow installing packages that have an <code>engines</code> declaration requiring a 343different version of <code>node</code>, even if <code>--engine-strict</code> is enabled.</li> 344<li>Allow <code>npm audit fix</code> to install modules outside your stated dependency 345range (including SemVer-major changes).</li> 346<li>Allow unpublishing all versions of a published package.</li> 347<li>Allow conflicting peerDependencies to be installed in the root project.</li> 348<li>Implicitly set <code>--yes</code> during <code>npm init</code>.</li> 349<li>Allow clobbering existing values in <code>npm pkg</code></li> 350<li>Allow unpublishing of entire packages (not just a single version).</li> 351</ul> 352<p>If you don't have a clear idea of what you want to do, it is strongly 353recommended that you do not use this option!</p> 354<h4 id="json"><code>json</code></h4> 355<ul> 356<li>Default: false</li> 357<li>Type: Boolean</li> 358</ul> 359<p>Whether or not to output JSON data, rather than the normal output.</p> 360<ul> 361<li>In <code>npm pkg set</code> it enables parsing set values with JSON.parse() before 362saving them to your <code>package.json</code>.</li> 363</ul> 364<p>Not supported by all npm commands.</p> 365<h4 id="package-lock-only"><code>package-lock-only</code></h4> 366<ul> 367<li>Default: false</li> 368<li>Type: Boolean</li> 369</ul> 370<p>If set to true, the current operation will only use the <code>package-lock.json</code>, 371ignoring <code>node_modules</code>.</p> 372<p>For <code>update</code> this means only the <code>package-lock.json</code> will be updated, 373instead of checking <code>node_modules</code> and downloading dependencies.</p> 374<p>For <code>list</code> this means the output will be based on the tree described by the 375<code>package-lock.json</code>, rather than the contents of <code>node_modules</code>.</p> 376<h4 id="omit"><code>omit</code></h4> 377<ul> 378<li>Default: 'dev' if the <code>NODE_ENV</code> environment variable is set to 379'production', otherwise empty.</li> 380<li>Type: "dev", "optional", or "peer" (can be set multiple times)</li> 381</ul> 382<p>Dependency types to omit from the installation tree on disk.</p> 383<p>Note that these dependencies <em>are</em> still resolved and added to the 384<code>package-lock.json</code> or <code>npm-shrinkwrap.json</code> file. They are just not 385physically installed on disk.</p> 386<p>If a package type appears in both the <code>--include</code> and <code>--omit</code> lists, then 387it will be included.</p> 388<p>If the resulting omit list includes <code>'dev'</code>, then the <code>NODE_ENV</code> environment 389variable will be set to <code>'production'</code> for all lifecycle scripts.</p> 390<h4 id="foreground-scripts"><code>foreground-scripts</code></h4> 391<ul> 392<li>Default: false</li> 393<li>Type: Boolean</li> 394</ul> 395<p>Run all build scripts (ie, <code>preinstall</code>, <code>install</code>, and <code>postinstall</code>) 396scripts for installed packages in the foreground process, sharing standard 397input, output, and error with the main npm process.</p> 398<p>Note that this will generally make installs run slower, and be much noisier, 399but can be useful for debugging.</p> 400<h4 id="ignore-scripts"><code>ignore-scripts</code></h4> 401<ul> 402<li>Default: false</li> 403<li>Type: Boolean</li> 404</ul> 405<p>If true, npm does not run scripts specified in package.json files.</p> 406<p>Note that commands explicitly intended to run a particular script, such as 407<code>npm start</code>, <code>npm stop</code>, <code>npm restart</code>, <code>npm test</code>, and <code>npm run-script</code> 408will still run their intended script if <code>ignore-scripts</code> is set, but they 409will <em>not</em> run any pre- or post-scripts.</p> 410<h4 id="workspace"><code>workspace</code></h4> 411<ul> 412<li>Default:</li> 413<li>Type: String (can be set multiple times)</li> 414</ul> 415<p>Enable running a command in the context of the configured workspaces of the 416current project while filtering by running only the workspaces defined by 417this configuration option.</p> 418<p>Valid values for the <code>workspace</code> config are either:</p> 419<ul> 420<li>Workspace names</li> 421<li>Path to a workspace directory</li> 422<li>Path to a parent workspace directory (will result in selecting all 423workspaces within that folder)</li> 424</ul> 425<p>When set for the <code>npm init</code> command, this may be set to the folder of a 426workspace which does not yet exist, to create the folder and set it up as a 427brand new workspace within the project.</p> 428<p>This value is not exported to the environment for child processes.</p> 429<h4 id="workspaces"><code>workspaces</code></h4> 430<ul> 431<li>Default: null</li> 432<li>Type: null or Boolean</li> 433</ul> 434<p>Set to true to run the command in the context of <strong>all</strong> configured 435workspaces.</p> 436<p>Explicitly setting this to false will cause commands like <code>install</code> to 437ignore workspaces altogether. When not set explicitly:</p> 438<ul> 439<li>Commands that operate on the <code>node_modules</code> tree (install, update, etc.) 440will link workspaces into the <code>node_modules</code> folder. - Commands that do 441other things (test, exec, publish, etc.) will operate on the root project, 442<em>unless</em> one or more workspaces are specified in the <code>workspace</code> config.</li> 443</ul> 444<p>This value is not exported to the environment for child processes.</p> 445<h4 id="include-workspace-root"><code>include-workspace-root</code></h4> 446<ul> 447<li>Default: false</li> 448<li>Type: Boolean</li> 449</ul> 450<p>Include the workspace root when workspaces are enabled for a command.</p> 451<p>When false, specifying individual workspaces via the <code>workspace</code> config, or 452all workspaces via the <code>workspaces</code> flag, will cause npm to operate only on 453the specified workspaces, and not on the root project.</p> 454<p>This value is not exported to the environment for child processes.</p> 455<h4 id="install-links"><code>install-links</code></h4> 456<ul> 457<li>Default: false</li> 458<li>Type: Boolean</li> 459</ul> 460<p>When set file: protocol dependencies will be packed and installed as regular 461dependencies instead of creating a symlink. This option has no effect on 462workspaces.</p> 463<h3 id="see-also">See Also</h3> 464<ul> 465<li><a href="../commands/npm-install.html">npm install</a></li> 466<li><a href="../using-npm/config.html">config</a></li> 467</ul></div> 468 469<footer id="edit"> 470<a href="https://github.com/npm/cli/edit/latest/docs/content/commands/npm-audit.md"> 471<svg role="img" viewBox="0 0 16 16" width="16" height="16" fill="currentcolor" style="vertical-align: text-bottom; margin-right: 0.3em;"> 472<path fill-rule="evenodd" d="M11.013 1.427a1.75 1.75 0 012.474 0l1.086 1.086a1.75 1.75 0 010 2.474l-8.61 8.61c-.21.21-.47.364-.756.445l-3.251.93a.75.75 0 01-.927-.928l.929-3.25a1.75 1.75 0 01.445-.758l8.61-8.61zm1.414 1.06a.25.25 0 00-.354 0L10.811 3.75l1.439 1.44 1.263-1.263a.25.25 0 000-.354l-1.086-1.086zM11.189 6.25L9.75 4.81l-6.286 6.287a.25.25 0 00-.064.108l-.558 1.953 1.953-.558a.249.249 0 00.108-.064l6.286-6.286z"></path> 473</svg> 474Edit this page on GitHub 475</a> 476</footer> 477</section> 478 479 480 481</body></html>