forked from MyEtherWallet/MyEtherWallet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
package-audit.js
49 lines (47 loc) · 1.09 KB
/
package-audit.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
const exec = require('child_process').exec;
const AUDIT_EXCEPTIONS = [
'decompress',
'http-proxy',
'findings',
'elliptic',
'dot-prop',
'serialize-javascript',
'handlebars',
'cryptiles',
'bl',
'axios',
'xmlhttprequest-ssl',
'url-parse', // added 5-10-21
'underscore', // added 5-10-21
'lodash', // added 5-10-21,
'dns-packet' // added 5-25-21 (could be related to an @ensdomains internal dependency)
];
const execute = (command, callback) => {
exec(
command,
{
maxBuffer: 100000 * 1024
},
(error, stdout, stderr) => {
callback(stdout);
}
);
};
execute('npm audit --json', json => {
const advisories = JSON.parse(json).advisories;
if (!advisories) {
console.info('Most likely npm audit is unavailable', json);
process.exit(0);
}
let auditPass = true;
for (const id in advisories) {
if (
advisories[id].severity === 'high' &&
!AUDIT_EXCEPTIONS.includes(advisories[id].module_name)
) {
console.error('AUDIT Failed', advisories[id]);
auditPass = false;
}
}
if (!auditPass) process.exit(1);
});