Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

misc(snyk): only keep vuln data for detectable libs #6919

Merged
merged 3 commits into from
Jan 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions lighthouse-core/scripts/cleanup-vuln-snapshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@

const {readFileSync, writeFileSync} = require('fs');
const prettyJSONStringify = require('pretty-json-stringify');
const libDetectorSource = readFileSync(require.resolve('js-library-detector/library/libraries.js'),
'utf8'
);

const filename = process.argv[2];
if (!filename) throw new Error('No filename provided.');
Expand All @@ -28,6 +31,26 @@ writeFileSync(filename, output, 'utf8');
*/
function cleanAndFormat(vulnString) {
const snapshot = /** @type {!SnykDB} */ (JSON.parse(vulnString));
// Hack to deal with non-node-friendly code.
const librariesDefinition = eval(`
(() => {
${libDetectorSource}
return d41d8cd98f00b204e9800998ecf8427e_LibraryDetectorTests;
})()
`);

// Identify all npm package names that can be detected.
const detectableLibs = Object.values(librariesDefinition)
.map(lib => lib.npm)
.filter(Boolean);

// Remove any entries that aren't detectable.
for (const npmPkgName of Object.keys(snapshot.npm)) {
if (!detectableLibs.includes(npmPkgName)) {
delete snapshot.npm[npmPkgName];
}
}

for (const libEntries of Object.values(snapshot.npm)) {
libEntries.forEach((entry, i) => {
const pruned = {
Expand Down
Loading