<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Mike Hoskins</title>
    <description>The latest articles on Forem by Mike Hoskins (@deadlysyn).</description>
    <link>https://forem.com/deadlysyn</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F349294%2F1e342688-163e-47d4-8b2b-655429c1da53.png</url>
      <title>Forem: Mike Hoskins</title>
      <link>https://forem.com/deadlysyn</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/deadlysyn"/>
    <language>en</language>
    <item>
      <title>npm audit vs auditjs</title>
      <dc:creator>Mike Hoskins</dc:creator>
      <pubDate>Wed, 11 Mar 2020 23:32:37 +0000</pubDate>
      <link>https://forem.com/sonatype/npm-audit-vs-auditjs-2fhp</link>
      <guid>https://forem.com/sonatype/npm-audit-vs-auditjs-2fhp</guid>
      <description>&lt;p&gt;[Full disclosure: I work for Sonatype, the company who offers OSS Index and AuditJS as free tools. We do this to give back to the OpenSource community, help raise awareness through easier access to security data, and garner interest in the extended feature set of commercial DevSecOps tooling we provide.]&lt;/p&gt;

&lt;p&gt;Awhile back I wrote &lt;a href="https://blog.devopsdreams.io/beyond-npm-audit" rel="noopener noreferrer"&gt;a blog post&lt;/a&gt; after a colleague shared &lt;a href="https://www.npmjs.com/package/auditjs" rel="noopener noreferrer"&gt;a new JavaScript auditing tool called AuditJS&lt;/a&gt;. I wanted to update that based on more time with the tool, particularly since a new version was recently released!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/sonatype-nexus-community/auditjs" rel="noopener noreferrer"&gt;AuditJS&lt;/a&gt; is a free tool leveraging &lt;a href="https://ossindex.sonatype.org/" rel="noopener noreferrer"&gt;Sonatype's OSS Index&lt;/a&gt;. OSSI exposes &lt;a href="https://ossindex.sonatype.org/doc/rest" rel="noopener noreferrer"&gt;a ReST API&lt;/a&gt; aggregating several security vulnerability feeds including &lt;a href="https://cve.mitre.org" rel="noopener noreferrer"&gt;CVE&lt;/a&gt;, &lt;a href="https://cwe.mitre.org" rel="noopener noreferrer"&gt;CWE&lt;/a&gt; and &lt;a href="https://nvd.nist.gov" rel="noopener noreferrer"&gt;NVD&lt;/a&gt;. OSSI continues to evolve by adding more data sources and benefits from ongoing curation of existing feeds. The effort required to mine so much data is conveniently abstracted away as it should be by a good tool -- setup AuditJS to reap the benefits!&lt;/p&gt;

&lt;p&gt;The 4.x release brought a lot of bug fixes and usability enhancements based on community feedback... Installation is quick and easy, if you want to run AuditJS as a NPM script just &lt;code&gt;npm i auditjs -D&lt;/code&gt; to get started. I prefer running it via &lt;code&gt;npx auditjs ossi&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;You can use it as a one-off CLI or easily integrate with your CI/CD pipelines. It's possible to integrate with the commercial &lt;a href="https://help.sonatype.com/iqserver" rel="noopener noreferrer"&gt;IQ Server&lt;/a&gt; (benefits from additional curation including both human and machine intelligence), but it is completely free to use with OSSI. You might want to &lt;a href="https://ossindex.sonatype.org/user/register" rel="noopener noreferrer"&gt;register for a free account&lt;/a&gt;, but even that is not required. The one benefit of an account is removing the rate-limit which can affect larger projects. I haven't hit rate-limit issues in my typically-sized NodeJS projects. You can even submit vulnerability reports via &lt;a href="https://github.com/OSSIndex/vulns" rel="noopener noreferrer"&gt;an awesome Git-based process&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Let's see what it looks like, and talk about a couple things which might surprise you when comparing to &lt;code&gt;npm audit&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="go"&gt;➜ npx auditjs ossi
 ________   ___  ___   ________   ___   _________       ___   ________
|\   __  \ |\  \|\  \ |\   ___ \ |\  \ |\___   ___\    |\  \ |\   ____\
\ \  \|\  \\ \  \\\  \\ \  \_|\ \\ \  \\|___ \  \_|    \ \  \\ \  \___|_
 \ \   __  \\ \  \\\  \\ \  \ \\ \\ \  \    \ \  \   __ \ \  \\ \_____  \
  \ \  \ \  \\ \  \\\  \\ \  \_\\ \\ \  \    \ \  \ |\  \\_\  \\|____|\  \
   \ \__\ \__\\ \_______\\ \_______\\ \__\    \ \__\\ \________\ ____\_\  \
    \|__|\|__| \|_______| \|_______| \|__|     \|__| \|________||\_________\
                                                                \|_________|

  _      _                       _   _
 /_)    /_`_  _  _ _/_   _  _   (/  /_`_._  _   _/ _
/_)/_/ ._//_// //_|/ /_//_//_' (_X /  ///_'/ //_/_\
   _/                _//

  AuditJS version: 4.0.10

✔ Starting application
✔ Getting coordinates for Sonatype OSS Index
✔ Auditing your application with Sonatype OSS Index
✔ Submitting coordinates to Sonatype OSS Index
✔ Reticulating splines
✔ Removing whitelisted vulnerabilities

  Sonabot here, beep boop beep boop, here are your Sonatype OSS Index results:
  Total dependencies audited: 224

[1/224] - pkg:npm/@nodelib/fs.scandir@2.1.3 - No vulnerabilities found!
[2/224] - pkg:npm/@nodelib/fs.stat@2.0.3 - No vulnerabilities found!
[3/224] - pkg:npm/@nodelib/fs.walk@1.2.4 - No vulnerabilities found!
[4/224] - pkg:npm/@sendgrid/client@6.5.3 - No vulnerabilities found!
[5/224] - pkg:npm/@sendgrid/helpers@6.5.3 - No vulnerabilities found!
[6/224] - pkg:npm/@sendgrid/mail@6.5.4 - No vulnerabilities found!
[7/224] - pkg:npm/@testim/chrome-version@1.0.7 - No vulnerabilities found!
[8/224] - pkg:npm/@types/caseless@0.12.2 - No vulnerabilities found!
[9/224] - pkg:npm/@types/events@3.0.0 - No vulnerabilities found!

&lt;/span&gt;&lt;span class="gp"&gt;#&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;Result list trimmed...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Dependency lists can obviously be long in NodeJS projects (understatement of the decade?), but the important thing is the reference to Sonatype's OSS Index (yay it's working!) as well as the ability to whitelist.&lt;/p&gt;

&lt;p&gt;Let's say you are alerted about a vulnerability, but know it doesn’t affect you because you aren’t using the vulnerable method -- you can whitelist that! Just pass in a whitelist file containing the OSS Index IDs (the only required field, but you can add others for clarity):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="go"&gt;➜ cat my-whitelist.json
{
  "ignore": [
    { "id": "long-oss-index-guid", "reason": "I accept the risk!" },
    { "id": "another-oss-index-guid", "reason": "We totally got this!" }
  ]
}

➜ npx auditjs ossi --whitelist my-whitelist.json
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The ideal is obviously to fix all the things, but this puts control in the hands of the developer and is especially useful in larger projects or CI/CD pipelines where the risk of lower severity issues is understood and potentially annoying people or breaking builds while waiting on upstream fixes.&lt;/p&gt;

&lt;p&gt;The other thing I want to call out is the dependency count. Above we see 224 dependencies were audited. By default, AuditJS only scans production dependencies. This is similar to &lt;code&gt;--only=prod&lt;/code&gt; with NPM, but for AuditJS we need &lt;code&gt;--dev&lt;/code&gt; to force scanning everything. Let's compare:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="gp"&gt;#&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;Could also use some &lt;span class="nt"&gt;--json&lt;/span&gt; | jq fu!
&lt;span class="gp"&gt;➜ npx auditjs ossi 2&amp;gt;&lt;/span&gt;&amp;amp;1|grep &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="s1"&gt;'^\['&lt;/span&gt;|wc
&lt;span class="go"&gt;     224    1568   14428

&lt;/span&gt;&lt;span class="gp"&gt;➜ npx auditjs ossi --dev 2&amp;gt;&lt;/span&gt;&amp;amp;1|grep &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="s1"&gt;'^\['&lt;/span&gt;|wc
&lt;span class="go"&gt;     885    6195   58537

&lt;/span&gt;&lt;span class="gp"&gt;#&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;Nothing too crazy here:
&lt;span class="go"&gt;➜ jq .devDependencies &amp;lt;package.json
{
  "acorn": "^7.1.1",
  "acorn-jsx": "^5.2.0",
  "ajv": "^6.12.0",
  "auditjs": "^4.0.10",
  "eslint": "^6.8.0",
  "eslint-config-airbnb": "^18.0.1",
  "eslint-config-airbnb-base": "^14.0.0",
  "eslint-config-prettier": "^6.10.0",
  "eslint-plugin-import": "^2.20.1",
  "eslint-plugin-jsx-a11y": "^6.2.3",
  "eslint-plugin-node": "^11.0.0",
  "eslint-plugin-prettier": "^3.1.2",
  "eslint-plugin-promise": "^4.2.1",
  "eslint-plugin-react": "^7.19.0",
  "eslint-plugin-react-hooks": "^2.5.0",
  "jest": "^25.1.0",
  "nodemon": "^2.0.2",
  "prettier": "^1.19.1",
  "supertest": "^4.0.2"
}
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Even a modest set of devDependencies requires a lot of additional scanning (~75% more in this case). AuditJS scans production dependencies by default, as these are what will get shipped with your built product, making it easier to understand the risk profile. You can add devDependencies in if you want!&lt;/p&gt;

&lt;p&gt;Aside from scanning behavior, another place AuditJS attempts to be more efficient is in reporting. NPM will often over-inflate vulnerability reports (to be fair, we might call this erring on the side of caution). Often, with NPM, you'll see output similar to the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="go"&gt;➜ npm audit

&lt;/span&gt;&lt;span class="c"&gt;...
&lt;/span&gt;&lt;span class="go"&gt;
added 1405 packages from 1327 contributors and audited 896097 packages in 26.484s
found 18 moderate severity vulnerabilities
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;896,097 packages?!? Or is it 1405? What gives -- I don't write efficient code (I likes me some cowsay), but I don't see that much stuff in node_packages...&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpreview.redd.it%2Ftfugj4n3l6ez.png%3Fwidth%3D960%26crop%3Dsmart%26auto%3Dwebp%26s%3Db477bf6ac3c7bddfef1c2d483d73029437a42e30" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpreview.redd.it%2Ftfugj4n3l6ez.png%3Fwidth%3D960%26crop%3Dsmart%26auto%3Dwebp%26s%3Db477bf6ac3c7bddfef1c2d483d73029437a42e30" title="Heaviest Objects in the Universe" alt="node_modules meme"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let's break that down:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="go"&gt;➜ npm ls --parseable | wc
    1057    1057   88307

➜ npm ls --parseable --only=prod | wc
     231     231   18007
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;231 is a lot closer to AuditJS' default behavior... Where did those extra packages come from? The devil is in the details, and this can lead to confusion when comparing tools... AuditJS de-dupes, so you still get warned about any critical vulnerabilities despite potentially looking like it did less work. Here's an example of how NPM reports on the same package multiple times:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="gp"&gt;➜ npm ls --parseable|grep -E 'ms$&lt;/span&gt;&lt;span class="s1"&gt;'
&lt;/span&gt;&lt;span class="go"&gt;src/thing/node_modules/log4js/node_modules/ms
src/thing/node_modules/streamroller/node_modules/ms
src/thing/node_modules/rewire/node_modules/ms
src/thing/node_modules/eslint/node_modules/ms
src/thing/node_modules/ms
src/thing/node_modules/send/node_modules/debug/node_modules/ms
src/thing/node_modules/send/node_modules/ms
&lt;/span&gt;&lt;span class="c"&gt;...
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;ms&lt;/code&gt; is indeed used in all these different places, but in total only three versions of it exist in my project. AuditJS only reports on the distinct coordinates it finds (2.0.0, 2.1.1, 2.1.2), whereas &lt;code&gt;npm ls&lt;/code&gt; (and the associated &lt;code&gt;npm audit&lt;/code&gt; commands) count multiple times if something is duplicated.&lt;/p&gt;

&lt;p&gt;In the arms race that is security, it's nice to see new tools which help developers stay ahead of the bad guys are rapidly evolving. For your next JavaScript project, take a moment to test drive some &lt;code&gt;npm audit&lt;/code&gt; alternatives!&lt;/p&gt;

</description>
      <category>npm</category>
      <category>security</category>
      <category>javascript</category>
      <category>node</category>
    </item>
  </channel>
</rss>
