npm-audit.1 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434
  1. .TH "NPM\-AUDIT" "1" "October 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] [\-\-production] [\-\-audit\-level=(low|moderate|high|critical)]
  9. npm audit fix [\-\-force|\-\-package\-lock\-only|\-\-dry\-run|\-\-production|\-\-only=(dev|prod)]
  10. common options: [\-\-production] [\-\-only=(dev|prod)]
  11. .fi
  12. .RE
  13. .SS Description
  14. .P
  15. The audit command submits a description of the dependencies configured in
  16. your project to your default registry and asks for a report of known
  17. vulnerabilities\. If any vulnerabilities are found, then the impact and
  18. appropriate remediation will be calculated\. If the \fBfix\fP argument is
  19. provided, then remediations will be applied to the package tree\.
  20. .P
  21. The command will exit with a 0 exit code if no vulnerabilities were found\.
  22. .P
  23. Note that some vulnerabilities cannot be fixed automatically and will
  24. require manual intervention or review\. Also note that since \fBnpm audit
  25. fix\fP runs a full\-fledged \fBnpm install\fP under the hood, all configs that
  26. apply to the installer will also apply to \fBnpm install\fP \-\- so things like
  27. \fBnpm audit fix \-\-package\-lock\-only\fP will work as expected\.
  28. .P
  29. By default, the audit command will exit with a non\-zero code if any
  30. vulnerability is found\. It may be useful in CI environments to include the
  31. \fB\-\-audit\-level\fP parameter to specify the minimum vulnerability level that
  32. will cause the command to fail\. This option does not filter the report
  33. output, it simply changes the command's failure threshold\.
  34. .SS Audit Endpoints
  35. .P
  36. There are two audit endpoints that npm may use to fetch vulnerability
  37. information: the \fBBulk Advisory\fP endpoint and the \fBQuick Audit\fP endpoint\.
  38. .SS Bulk Advisory Endpoint
  39. .P
  40. As of version 7, npm uses the much faster \fBBulk Advisory\fP endpoint to
  41. optimize the speed of calculating audit results\.
  42. .P
  43. npm will generate a JSON payload with the name and list of versions of each
  44. package in the tree, and POST it to the default configured registry at
  45. the path \fB/\-/npm/v1/security/advisories/bulk\fP\|\.
  46. .P
  47. Any packages in the tree that do not have a \fBversion\fP field in their
  48. package\.json file will be ignored\. If any \fB\-\-omit\fP options are specified
  49. (either via the \fB\-\-omit\fP config, or one of the shorthands such as
  50. \fB\-\-production\fP, \fB\-\-only=dev\fP, and so on), then packages will be omitted
  51. from the submitted payload as appropriate\.
  52. .P
  53. If the registry responds with an error, or with an invalid response, then
  54. npm will attempt to load advisory data from the \fBQuick Audit\fP endpoint\.
  55. .P
  56. The expected result will contain a set of advisory objects for each
  57. dependency that matches the advisory range\. Each advisory object contains
  58. a \fBname\fP, \fBurl\fP, \fBid\fP, \fBseverity\fP, \fBvulnerable_versions\fP, and \fBtitle\fP\|\.
  59. .P
  60. npm then uses these advisory objects to calculate vulnerabilities and
  61. meta\-vulnerabilities of the dependencies within the tree\.
  62. .SS Quick Audit Endpoint
  63. .P
  64. If the \fBBulk Advisory\fP endpoint returns an error, or invalid data, npm will
  65. attempt to load advisory data from the \fBQuick Audit\fP endpoint, which is
  66. considerably slower in most cases\.
  67. .P
  68. The full package tree as found in \fBpackage\-lock\.json\fP is submitted, along
  69. with the following pieces of additional metadata:
  70. .RS 0
  71. .IP \(bu 2
  72. \fBnpm_version\fP
  73. .IP \(bu 2
  74. \fBnode_version\fP
  75. .IP \(bu 2
  76. \fBplatform\fP
  77. .IP \(bu 2
  78. \fBarch\fP
  79. .IP \(bu 2
  80. \fBnode_env\fP
  81. .RE
  82. .P
  83. All packages in the tree are submitted to the Quick Audit endpoint\.
  84. Omitted dependency types are skipped when generating the report\.
  85. .SS Scrubbing
  86. .P
  87. Out of an abundance of caution, npm versions 5 and 6 would "scrub" any
  88. packages from the submitted report if their name contained a \fB/\fP character,
  89. so as to avoid leaking the names of potentially private packages or git
  90. URLs\.
  91. .P
  92. However, in practice, this resulted in audits often failing to properly
  93. detect meta\-vulnerabilities, because the tree would appear to be invalid
  94. due to missing dependencies, and prevented the detection of vulnerabilities
  95. in package trees that used git dependencies or private modules\.
  96. .P
  97. This scrubbing has been removed from npm as of version 7\.
  98. .SS Calculating Meta\-Vulnerabilities and Remediations
  99. .P
  100. npm uses the
  101. \fB@npmcli/metavuln\-calculator\fP \fIhttp://npm\.im/@npmcli/metavuln\-calculator\fR
  102. module to turn a set of security advisories into a set of "vulnerability"
  103. objects\. A "meta\-vulnerability" is a dependency that is vulnerable by
  104. virtue of dependence on vulnerable versions of a vulnerable package\.
  105. .P
  106. For example, if the package \fBfoo\fP is vulnerable in the range \fB>=1\.0\.2
  107. <2\.0\.0\fP, and the package \fBbar\fP depends on \fBfoo@^1\.1\.0\fP, then that version
  108. of \fBbar\fP can only be installed by installing a vulnerable version of \fBfoo\fP\|\.
  109. In this case, \fBbar\fP is a "metavulnerability"\.
  110. .P
  111. Once metavulnerabilities for a given package are calculated, they are
  112. cached in the \fB~/\.npm\fP folder and only re\-evaluated if the advisory range
  113. changes, or a new version of the package is published (in which case, the
  114. new version is checked for metavulnerable status as well)\.
  115. .P
  116. If the chain of metavulnerabilities extends all the way to the root
  117. project, and it cannot be updated without changing its dependency ranges,
  118. then \fBnpm audit fix\fP will require the \fB\-\-force\fP option to apply the
  119. remediation\. If remediations do not require changes to the dependency
  120. ranges, then all vulnerable packages will be updated to a version that does
  121. not have an advisory or metavulnerability posted against it\.
  122. .SS Exit Code
  123. .P
  124. The \fBnpm audit\fP command will exit with a 0 exit code if no vulnerabilities
  125. were found\. The \fBnpm audit fix\fP command will exit with 0 exit code if no
  126. vulnerabilities are found \fIor\fR if the remediation is able to successfully
  127. fix all vulnerabilities\.
  128. .P
  129. If vulnerabilities were found the exit code will depend on the
  130. \fBaudit\-level\fP configuration setting\.
  131. .SS Examples
  132. .P
  133. Scan your project for vulnerabilities and automatically install any compatible
  134. updates to vulnerable dependencies:
  135. .P
  136. .RS 2
  137. .nf
  138. $ npm audit fix
  139. .fi
  140. .RE
  141. .P
  142. Run \fBaudit fix\fP without modifying \fBnode_modules\fP, but still updating the
  143. pkglock:
  144. .P
  145. .RS 2
  146. .nf
  147. $ npm audit fix \-\-package\-lock\-only
  148. .fi
  149. .RE
  150. .P
  151. Skip updating \fBdevDependencies\fP:
  152. .P
  153. .RS 2
  154. .nf
  155. $ npm audit fix \-\-only=prod
  156. .fi
  157. .RE
  158. .P
  159. Have \fBaudit fix\fP install SemVer\-major updates to toplevel dependencies, not
  160. just SemVer\-compatible ones:
  161. .P
  162. .RS 2
  163. .nf
  164. $ npm audit fix \-\-force
  165. .fi
  166. .RE
  167. .P
  168. Do a dry run to get an idea of what \fBaudit fix\fP will do, and \fIalso\fR output
  169. install information in JSON format:
  170. .P
  171. .RS 2
  172. .nf
  173. $ npm audit fix \-\-dry\-run \-\-json
  174. .fi
  175. .RE
  176. .P
  177. Scan your project for vulnerabilities and just show the details, without
  178. fixing anything:
  179. .P
  180. .RS 2
  181. .nf
  182. $ npm audit
  183. .fi
  184. .RE
  185. .P
  186. Get the detailed audit report in JSON format:
  187. .P
  188. .RS 2
  189. .nf
  190. $ npm audit \-\-json
  191. .fi
  192. .RE
  193. .P
  194. Fail an audit only if the results include a vulnerability with a level of moderate or higher:
  195. .P
  196. .RS 2
  197. .nf
  198. $ npm audit \-\-audit\-level=moderate
  199. .fi
  200. .RE
  201. .SS Configuration
  202. <!\-\- AUTOGENERATED CONFIG DESCRIPTIONS START \-\->
  203. <!\-\- automatically generated, do not edit manually \-\->
  204. <!\-\- see lib/utils/config/definitions\.js \-\->
  205. .SS \fBaudit\-level\fP
  206. .RS 0
  207. .IP \(bu 2
  208. Default: null
  209. .IP \(bu 2
  210. Type: null, "info", "low", "moderate", "high", "critical", or "none"
  211. .RE
  212. .P
  213. The minimum level of vulnerability for \fBnpm audit\fP to exit with a non\-zero
  214. exit code\.
  215. <!\-\- automatically generated, do not edit manually \-\->
  216. <!\-\- see lib/utils/config/definitions\.js \-\->
  217. .SS \fBdry\-run\fP
  218. .RS 0
  219. .IP \(bu 2
  220. Default: false
  221. .IP \(bu 2
  222. Type: Boolean
  223. .RE
  224. .P
  225. Indicates that you don't want npm to make any changes and that it should
  226. only report what it would have done\. This can be passed into any of the
  227. commands that modify your local installation, eg, \fBinstall\fP, \fBupdate\fP,
  228. \fBdedupe\fP, \fBuninstall\fP, as well as \fBpack\fP and \fBpublish\fP\|\.
  229. .P
  230. Note: This is NOT honored by other network related commands, eg \fBdist\-tags\fP,
  231. \fBowner\fP, etc\.
  232. <!\-\- automatically generated, do not edit manually \-\->
  233. <!\-\- see lib/utils/config/definitions\.js \-\->
  234. .SS \fBforce\fP
  235. .RS 0
  236. .IP \(bu 2
  237. Default: false
  238. .IP \(bu 2
  239. Type: Boolean
  240. .RE
  241. .P
  242. Removes various protections against unfortunate side effects, common
  243. mistakes, unnecessary performance degradation, and malicious input\.
  244. .RS 0
  245. .IP \(bu 2
  246. Allow clobbering non\-npm files in global installs\.
  247. .IP \(bu 2
  248. Allow the \fBnpm version\fP command to work on an unclean git repository\.
  249. .IP \(bu 2
  250. Allow deleting the cache folder with \fBnpm cache clean\fP\|\.
  251. .IP \(bu 2
  252. Allow installing packages that have an \fBengines\fP declaration requiring a
  253. different version of npm\.
  254. .IP \(bu 2
  255. Allow installing packages that have an \fBengines\fP declaration requiring a
  256. different version of \fBnode\fP, even if \fB\-\-engine\-strict\fP is enabled\.
  257. .IP \(bu 2
  258. Allow \fBnpm audit fix\fP to install modules outside your stated dependency
  259. range (including SemVer\-major changes)\.
  260. .IP \(bu 2
  261. Allow unpublishing all versions of a published package\.
  262. .IP \(bu 2
  263. Allow conflicting peerDependencies to be installed in the root project\.
  264. .IP \(bu 2
  265. Implicitly set \fB\-\-yes\fP during \fBnpm init\fP\|\.
  266. .IP \(bu 2
  267. Allow clobbering existing values in \fBnpm pkg\fP
  268. .RE
  269. .P
  270. If you don't have a clear idea of what you want to do, it is strongly
  271. recommended that you do not use this option!
  272. <!\-\- automatically generated, do not edit manually \-\->
  273. <!\-\- see lib/utils/config/definitions\.js \-\->
  274. .SS \fBjson\fP
  275. .RS 0
  276. .IP \(bu 2
  277. Default: false
  278. .IP \(bu 2
  279. Type: Boolean
  280. .RE
  281. .P
  282. Whether or not to output JSON data, rather than the normal output\.
  283. .RS 0
  284. .IP \(bu 2
  285. In \fBnpm pkg set\fP it enables parsing set values with JSON\.parse() before
  286. saving them to your \fBpackage\.json\fP\|\.
  287. .RE
  288. .P
  289. Not supported by all npm commands\.
  290. <!\-\- automatically generated, do not edit manually \-\->
  291. <!\-\- see lib/utils/config/definitions\.js \-\->
  292. .SS \fBpackage\-lock\-only\fP
  293. .RS 0
  294. .IP \(bu 2
  295. Default: false
  296. .IP \(bu 2
  297. Type: Boolean
  298. .RE
  299. .P
  300. If set to true, the current operation will only use the \fBpackage\-lock\.json\fP,
  301. ignoring \fBnode_modules\fP\|\.
  302. .P
  303. For \fBupdate\fP this means only the \fBpackage\-lock\.json\fP will be updated,
  304. instead of checking \fBnode_modules\fP and downloading dependencies\.
  305. .P
  306. For \fBlist\fP this means the output will be based on the tree described by the
  307. \fBpackage\-lock\.json\fP, rather than the contents of \fBnode_modules\fP\|\.
  308. <!\-\- automatically generated, do not edit manually \-\->
  309. <!\-\- see lib/utils/config/definitions\.js \-\->
  310. .SS \fBomit\fP
  311. .RS 0
  312. .IP \(bu 2
  313. Default: 'dev' if the \fBNODE_ENV\fP environment variable is set to
  314. \|'production', otherwise empty\.
  315. .IP \(bu 2
  316. Type: "dev", "optional", or "peer" (can be set multiple times)
  317. .RE
  318. .P
  319. Dependency types to omit from the installation tree on disk\.
  320. .P
  321. Note that these dependencies \fIare\fR still resolved and added to the
  322. \fBpackage\-lock\.json\fP or \fBnpm\-shrinkwrap\.json\fP file\. They are just not
  323. physically installed on disk\.
  324. .P
  325. If a package type appears in both the \fB\-\-include\fP and \fB\-\-omit\fP lists, then
  326. it will be included\.
  327. .P
  328. If the resulting omit list includes \fB\|'dev'\fP, then the \fBNODE_ENV\fP environment
  329. variable will be set to \fB\|'production'\fP for all lifecycle scripts\.
  330. <!\-\- automatically generated, do not edit manually \-\->
  331. <!\-\- see lib/utils/config/definitions\.js \-\->
  332. .SS \fBworkspace\fP
  333. .RS 0
  334. .IP \(bu 2
  335. Default:
  336. .IP \(bu 2
  337. Type: String (can be set multiple times)
  338. .RE
  339. .P
  340. Enable running a command in the context of the configured workspaces of the
  341. current project while filtering by running only the workspaces defined by
  342. this configuration option\.
  343. .P
  344. Valid values for the \fBworkspace\fP config are either:
  345. .RS 0
  346. .IP \(bu 2
  347. Workspace names
  348. .IP \(bu 2
  349. Path to a workspace directory
  350. .IP \(bu 2
  351. Path to a parent workspace directory (will result in selecting all
  352. workspaces within that folder)
  353. .RE
  354. .P
  355. When set for the \fBnpm init\fP command, this may be set to the folder of a
  356. workspace which does not yet exist, to create the folder and set it up as a
  357. brand new workspace within the project\.
  358. .P
  359. This value is not exported to the environment for child processes\.
  360. <!\-\- automatically generated, do not edit manually \-\->
  361. <!\-\- see lib/utils/config/definitions\.js \-\->
  362. .SS \fBworkspaces\fP
  363. .RS 0
  364. .IP \(bu 2
  365. Default: null
  366. .IP \(bu 2
  367. Type: null or Boolean
  368. .RE
  369. .P
  370. Set to true to run the command in the context of \fBall\fR configured
  371. workspaces\.
  372. .P
  373. Explicitly setting this to false will cause commands like \fBinstall\fP to
  374. ignore workspaces altogether\. When not set explicitly:
  375. .RS 0
  376. .IP \(bu 2
  377. Commands that operate on the \fBnode_modules\fP tree (install, update, etc\.)
  378. will link workspaces into the \fBnode_modules\fP folder\. \- Commands that do
  379. other things (test, exec, publish, etc\.) will operate on the root project,
  380. \fIunless\fR one or more workspaces are specified in the \fBworkspace\fP config\.
  381. .RE
  382. .P
  383. This value is not exported to the environment for child processes\.
  384. <!\-\- automatically generated, do not edit manually \-\->
  385. <!\-\- see lib/utils/config/definitions\.js \-\->
  386. .SS \fBinclude\-workspace\-root\fP
  387. .RS 0
  388. .IP \(bu 2
  389. Default: false
  390. .IP \(bu 2
  391. Type: Boolean
  392. .RE
  393. .P
  394. Include the workspace root when workspaces are enabled for a command\.
  395. .P
  396. When false, specifying individual workspaces via the \fBworkspace\fP config, or
  397. all workspaces via the \fBworkspaces\fP flag, will cause npm to operate only on
  398. the specified workspaces, and not on the root project\.
  399. <!\-\- automatically generated, do not edit manually \-\->
  400. <!\-\- see lib/utils/config/definitions\.js \-\->
  401. <!\-\- AUTOGENERATED CONFIG DESCRIPTIONS END \-\->
  402. .SS See Also
  403. .RS 0
  404. .IP \(bu 2
  405. npm help install
  406. .IP \(bu 2
  407. npm help config
  408. .RE