Created
October 9, 2020 17:20
-
-
Save josh-hemphill/07f4745dbee1102afa6b58220ec5a37a to your computer and use it in GitHub Desktop.
NPM Security totals by depth0 package
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
'use strict'; | |
const {execSync} = require('child_process'); | |
let result = {}; | |
try { | |
result = execSync(`npm audit --json --long`); | |
} catch (error) { | |
const {stdout, stderr} = error; | |
result = {stdout, stderr}; | |
} | |
const data = JSON.parse(result.stdout.toString()); | |
const vouln = {}; | |
for (let i in data.advisories) { | |
const {url, module_name, severity, findings} = data.advisories[i]; | |
for (let f of findings) { | |
for (let path of f.paths) { | |
const vPath = path.split('>'); | |
const name = vPath[0]; | |
if (!vouln[name]) vouln[name] = {}; | |
if (!vouln[name][severity]) vouln[name][severity] = []; | |
let sev = vouln[name][severity]; | |
sev.push({ | |
url, | |
path, | |
version: f.version, | |
}); | |
} | |
} | |
} | |
let presentation = ''; | |
for (let i in vouln) { | |
let line = i + ' - '; | |
for (let sev in vouln[i]) { | |
line += `${sev}:${vouln[i][sev].length} `; | |
} | |
presentation += line + '\n'; | |
} | |
console.log(presentation); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment