npm-audit.1 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. .TH "NPM\-AUDIT" "1" "August 2021" "" ""
  2. .SH "NAME"
  3. \fBnpm-audit\fR \- Run a security audit
  4. .SS Synopsis
  5. .P
  6. .RS 2
  7. .nf
  8. npm audit [\-\-json|\-\-parseable|\-\-audit\-level=(low|moderate|high|critical)]
  9. npm audit fix [\-\-force|\-\-package\-lock\-only|\-\-dry\-run]
  10. common options: [\-\-production] [\-\-only=(dev|prod)]
  11. .fi
  12. .RE
  13. .SS Examples
  14. .P
  15. Scan your project for vulnerabilities and automatically install any compatible
  16. updates to vulnerable dependencies:
  17. .P
  18. .RS 2
  19. .nf
  20. $ npm audit fix
  21. .fi
  22. .RE
  23. .P
  24. Run \fBaudit fix\fP without modifying \fBnode_modules\fP, but still updating the
  25. pkglock:
  26. .P
  27. .RS 2
  28. .nf
  29. $ npm audit fix \-\-package\-lock\-only
  30. .fi
  31. .RE
  32. .P
  33. Skip updating \fBdevDependencies\fP:
  34. .P
  35. .RS 2
  36. .nf
  37. $ npm audit fix \-\-only=prod
  38. .fi
  39. .RE
  40. .P
  41. Have \fBaudit fix\fP install semver\-major updates to toplevel dependencies, not just
  42. semver\-compatible ones:
  43. .P
  44. .RS 2
  45. .nf
  46. $ npm audit fix \-\-force
  47. .fi
  48. .RE
  49. .P
  50. Do a dry run to get an idea of what \fBaudit fix\fP will do, and \fIalso\fR output
  51. install information in JSON format:
  52. .P
  53. .RS 2
  54. .nf
  55. $ npm audit fix \-\-dry\-run \-\-json
  56. .fi
  57. .RE
  58. .P
  59. Scan your project for vulnerabilities and just show the details, without fixing
  60. anything:
  61. .P
  62. .RS 2
  63. .nf
  64. $ npm audit
  65. .fi
  66. .RE
  67. .P
  68. Get the detailed audit report in JSON format:
  69. .P
  70. .RS 2
  71. .nf
  72. $ npm audit \-\-json
  73. .fi
  74. .RE
  75. .P
  76. Get the detailed audit report in plain text result, separated by tab characters, allowing for
  77. future reuse in scripting or command line post processing, like for example, selecting
  78. some of the columns printed:
  79. .P
  80. .RS 2
  81. .nf
  82. $ npm audit \-\-parseable
  83. .fi
  84. .RE
  85. .P
  86. To parse columns, you can use for example \fBawk\fP, and just print some of them:
  87. .P
  88. .RS 2
  89. .nf
  90. $ npm audit \-\-parseable | awk \-F $'\\t' '{print $1,$4}'
  91. .fi
  92. .RE
  93. .P
  94. Fail an audit only if the results include a vulnerability with a level of moderate or higher:
  95. .P
  96. .RS 2
  97. .nf
  98. $ npm audit \-\-audit\-level=moderate
  99. .fi
  100. .RE
  101. .SS Description
  102. .P
  103. The audit command submits a description of the dependencies configured in
  104. your project to your default registry and asks for a report of known
  105. vulnerabilities\. The report returned includes instructions on how to act on
  106. this information\. The command will exit with a 0 exit code if no
  107. vulnerabilities were found\.
  108. .P
  109. You can also have npm automatically fix the vulnerabilities by running \fBnpm
  110. audit fix\fP\|\. Note that some vulnerabilities cannot be fixed automatically and
  111. will require manual intervention or review\. Also note that since \fBnpm audit fix\fP
  112. runs a full\-fledged \fBnpm install\fP under the hood, all configs that apply to the
  113. installer will also apply to \fBnpm install\fP \-\- so things like \fBnpm audit fix
  114. \-\-package\-lock\-only\fP will work as expected\.
  115. .P
  116. By default, the audit command will exit with a non\-zero code if any vulnerability
  117. is found\. It may be useful in CI environments to include the \fB\-\-audit\-level\fP parameter
  118. to specify the minimum vulnerability level that will cause the command to fail\. This
  119. option does not filter the report output, it simply changes the command's failure
  120. threshold\.
  121. .SS Content Submitted
  122. .RS 0
  123. .IP \(bu 2
  124. npm_version
  125. .IP \(bu 2
  126. node_version
  127. .IP \(bu 2
  128. platform
  129. .IP \(bu 2
  130. node_env
  131. .IP \(bu 2
  132. A scrubbed version of your package\-lock\.json or npm\-shrinkwrap\.json
  133. .RE
  134. .SS Scrubbing
  135. .P
  136. In order to ensure that potentially sensitive information is not included in
  137. the audit data bundle, some dependencies may have their names (and sometimes
  138. versions) replaced with opaque non\-reversible identifiers\. It is done for
  139. the following dependency types:
  140. .RS 0
  141. .IP \(bu 2
  142. Any module referencing a scope that is configured for a non\-default
  143. registry has its name scrubbed\. (That is, a scope you did a \fBnpm login \-\-scope=@ourscope\fP for\.)
  144. .IP \(bu 2
  145. All git dependencies have their names and specifiers scrubbed\.
  146. .IP \(bu 2
  147. All remote tarball dependencies have their names and specifiers scrubbed\.
  148. .IP \(bu 2
  149. All local directory and tarball dependencies have their names and specifiers scrubbed\.
  150. .RE
  151. .P
  152. The non\-reversible identifiers are a sha256 of a session\-specific UUID and the
  153. value being replaced, ensuring a consistent value within the payload that is
  154. different between runs\.
  155. .SS Exit Code
  156. .P
  157. The \fBnpm audit\fP command will exit with a 0 exit code if no vulnerabilities were found\.
  158. .P
  159. If vulnerabilities were found the exit code will depend on the \fBaudit\-level\fP
  160. configuration setting\.
  161. .SS See Also
  162. .RS 0
  163. .IP \(bu 2
  164. npm help install
  165. .IP \(bu 2
  166. npm help package\-locks
  167. .IP \(bu 2
  168. npm help config
  169. .RE