-
Notifications
You must be signed in to change notification settings - Fork 7
/
run-yarn-audit.sh
executable file
·56 lines (44 loc) · 1.89 KB
/
run-yarn-audit.sh
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
#!/bin/bash
# workaround for missing feature
# https://github.com/yarnpkg/yarn/issues/6669
set -u
cmd="yarn audit --level low --json --groups dependencies"
output=$($cmd)
result=$?
if [ $result -eq 0 ]; then
echo No known vulnerabilities
exit 0
fi
if [ -f yarn-audit-known-issues ] && echo "$output" | grep auditAdvisory | diff -q yarn-audit-known-issues - > /dev/null 2>&1; then
echo
echo Ignorning known vulnerabilities
exit 0
fi
# we compare the json output to see if they are the same list of package names and version numbers
# if so, exit without error
curr=$(cat yarn-audit-known-issues | jq -s 'map({name: .data.advisory.module_name, version: .data.advisory.findings[0].version})| unique | sort_by(.data.advisory.module_name) | tostring')
new=$(yarn audit --level low --json --groups dependencies | jq -s 'map(select(.type == "auditAdvisory")) | map({name: .data.advisory.module_name, version: .data.advisory.findings[0].version})| unique | sort_by(.data.advisory.module_name) | tostring')
if [ "$curr" = "$new" ]; then
echo
echo Ignoring previously known and accepted vulnerabilitie
exit 0
fi
echo
echo Security vulnerabilities were found that were not ignored:
echo "$output" | jq -s 'map(select(.type == "auditAdvisory")) | map({name: .data.advisory.module_name, version: .data.advisory.findings[0].version})| unique'
echo
if [ -f yarn-audit-known-issues ]; then
echo Previously ignored:
cat yarn-audit-known-issues | jq -s 'map({name: .data.advisory.module_name, version: .data.advisory.findings[0].version})| unique'
echo
fi
echo Check to see if these vulnerabilities apply to production
echo and/or if they have fixes available. If they do not have
echo fixes and they do not apply to production, you may ignore them
echo
echo To ignore these vulnerabilities, run:
echo
echo "$cmd | grep auditAdvisory > yarn-audit-known-issues"
echo
echo and commit the yarn-audit-known-issues file
exit "$result"