forked from MyEtherWallet/MyEtherWallet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
package-audit.js
82 lines (81 loc) · 1.6 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
const exec = require('child_process').exec;
const AUDIT_EXCEPTIONS = [
'tar',
'trim-newlines',
'css-what',
'normalize-url',
'diff',
'shelljs',
// no patches available
'ansi-html',
'minimist',
'moment',
'axios',
'async',
'nth-check',
'semver-regex',
'scss-tokenizer',
'codecov', // no package found
'loader-utils', // breaks building
'json5',
'http-cache-semantics',
'cacheable-request',
'dns-packet',
'decode-uri-component',
'@openzeppelin/contracts',
'engine.io',
'socket.io-parser',
'fast-xml-parser',
'@grpc/grpc-js',
'is_js',
'get-func-name',
'chart.js',
'browserify-sign',
'lodash.pick',
'ip',
'webpack-dev-middleware',
'web3-utils',
'@solana/web3.js',
'lodash.template',
'html-minifier',
'braces',
'ws',
// issues after new enkrypt ens lib
'lodash',
'node-forge',
'elliptic',
'protobufjs',
'minimatch',
'socket.io',
'semver'
];
const execute = (command, callback) => {
exec(
command,
{
maxBuffer: 2000 * 4096
},
(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);
console.log('AUDIT complete');
});