-
Notifications
You must be signed in to change notification settings - Fork 0
/
script-create-security-report.sh
executable file
·170 lines (145 loc) · 5.07 KB
/
script-create-security-report.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
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#!/bin/bash
#
# Checkout and update the branch on all repos
set -e
REPO=${PWD##*/}
SCRIPT_DIR=$(cd $(dirname "${BASH_SOURCE[0]}") && pwd)
PACKAGE_VERSION=$1
HEAD_BRANCH=$1
SKIP_MAINTAINERS=$2
if [[ "$HEAD_BRANCH" = "master" ]]; then
HEAD_BRANCH=$(git symbolic-ref refs/remotes/origin/HEAD | sed 's@^refs/remotes/origin/@@')
fi
MAINTAINERS='@AndyScherzinger @sorbaugh'
if [ "$SKIP_MAINTAINERS" = "0" ]; then
MAIN_BRANCH=$(git symbolic-ref refs/remotes/origin/HEAD | sed 's@^refs/remotes/origin/@@')
echo ""
echo "Read maintainers from main branch $MAIN_BRANCH"
echo "======================"
git fetch origin $MAIN_BRANCH
git checkout $MAIN_BRANCH
git reset --hard origin/$MAIN_BRANCH
if [ ! -f CODEOWNERS ]; then
if [ ! -f .github/CODEOWNERS ]; then
if [ ! -f docs/CODEOWNERS ]; then
echo -e "\033[0;31m❌ $REPO is missing the CODEOWNERS file\033[0m"
CODEOWNER_FILE='.github/CODEOWNERS'
touch $CODEOWNER_FILE
else
CODEOWNER_FILE='docs/CODEOWNERS'
fi
else
CODEOWNER_FILE='.github/CODEOWNERS'
fi
else
CODEOWNER_FILE='CODEOWNERS'
fi
if [ -f $CODEOWNER_FILE ]; then
echo -e "\033[0;36mReading maintainers from $CODEOWNER_FILE\033[0m"
INFOXML_OWNER=$(cat $CODEOWNER_FILE | egrep -oEi '^/appinfo/info.xml\s+@(.*)' | wc -l)
if [ "$INFOXML_OWNER" = "0" ]; then
echo -e "\033[0;31m❌ $REPO is missing the CODEOWNERS for info.xml\033[0m"
fi
MAINTAINERS=$(cat $CODEOWNER_FILE | egrep -oEi '^/appinfo/info.xml\s+@(.*)' | egrep -oEi '\s+@(.*)' | xargs)
echo -e "\033[1;35mMaintainers $MAINTAINERS\033[0m"
else
echo -e "\033[0;31m❌ $REPO is missing the CODEOWNERS\033[0m"
fi
else
echo -e "\033[1;35mMaintainers skipped, falling back to $MAINTAINERS\033[0m"
fi
echo ""
echo "Detecting matching stable branch"
echo "======================"
if [ "${HEAD_BRANCH:0:6}" = "stable" ]; then
# https://github.com/nextcloud/guests/pull/1096#issuecomment-1881215509
HEAD_BRANCH=$(find-stable ${HEAD_BRANCH:6})
fi
echo ""
echo "Fetch $HEAD_BRANCH"
echo "======================"
git fetch origin $HEAD_BRANCH
echo ""
echo "Checkout $HEAD_BRANCH"
echo "======================"
git checkout $HEAD_BRANCH
echo ""
echo "Reset $HEAD_BRANCH"
echo "======================"
git reset --hard origin/$HEAD_BRANCH
echo "" >> $SCRIPT_DIR/security-report.txt
echo "## [$REPO](https://github.com/nextcloud/$REPO) - [Security tab](https://github.com/nextcloud/$REPO/security/dependabot)" >> $SCRIPT_DIR/security-report.txt
echo "" >> $SCRIPT_DIR/security-report.txt
echo ""
echo "Check composer.json"
echo "======================"
COMPOSER_AUDIT=""
if [ ! -f composer.json ]; then
echo "- [x] ⚙️ PHP: 🏳️ No composer.json" >> $SCRIPT_DIR/security-report.txt
echo ""
echo -e "\033[1;35m🏳️ No composer.json\033[0m"
echo ""
else
set +e
COMPOSER_AUDIT=$(composer audit --locked --no-ansi --no-interaction 2>&1)
AUDIT_FAILED=$?
set -e
if [ "$AUDIT_FAILED" = "0" ]; then
echo "- [x] ⚙️ PHP: 🟢 No vulnerable depdendency" >> $SCRIPT_DIR/security-report.txt
echo ""
echo -e "\033[0;32m🟢 All ⚙️ PHP packages okay!\033[0m"
echo ""
else
echo "- [ ] ⚙️ PHP: ❌ Has at least one vulnerable depdendency" >> $SCRIPT_DIR/security-report.txt
echo " - Maintainers: $MAINTAINERS" >> $SCRIPT_DIR/security-report.txt
echo ""
echo -e "\033[0;31m❌ $REPO is depending on insecure ⚙️ PHP package\033[0m"
echo ""
fi
fi
NPM_AUDIT=""
if [ ! -f package.json ]; then
echo "- [x] 🖌️ JS: 🏳️ No package.json" >> $SCRIPT_DIR/security-report.txt
echo ""
echo -e "\033[1;35m🏳️ No package.json\033[0m"
echo ""
else
set +e
NPM_AUDIT=$(npm audit --package-lock-only)
AUDIT_FAILED=$?
set -e
if [ "$AUDIT_FAILED" = "0" ]; then
echo "- [x] 🖌️ JS: 🟢 No vulnerable depdendency" >> $SCRIPT_DIR/security-report.txt
echo ""
echo -e "\033[0;32m🟢 All 🖌️ JS packages okay!\033[0m"
echo ""
else
echo "- [ ] 🖌️ JS: ❌ Has at least one vulnerable depdendency" >> $SCRIPT_DIR/security-report.txt
echo " - Maintainers: $MAINTAINERS" >> $SCRIPT_DIR/security-report.txt
echo ""
echo -e "\033[0;31m❌ $REPO is depending on insecure 🖌️ JS package\033[0m"
echo ""
fi
fi
if [ "$COMPOSER_AUDIT$NPM_AUDIT" ]; then
echo "" >> $SCRIPT_DIR/security-report.txt
echo "<details>" >> $SCRIPT_DIR/security-report.txt
echo "" >> $SCRIPT_DIR/security-report.txt
if [ "$COMPOSER_AUDIT" ]; then
echo "### Composer" >> $SCRIPT_DIR/security-report.txt
echo "\`\`\`" >> $SCRIPT_DIR/security-report.txt
echo "$COMPOSER_AUDIT" >> $SCRIPT_DIR/security-report.txt
echo "\`\`\`" >> $SCRIPT_DIR/security-report.txt
echo "" >> $SCRIPT_DIR/security-report.txt
fi
if [ "$NPM_AUDIT" ]; then
echo "### NPM" >> $SCRIPT_DIR/security-report.txt
echo "\`\`\`" >> $SCRIPT_DIR/security-report.txt
echo "$NPM_AUDIT" >> $SCRIPT_DIR/security-report.txt
echo "\`\`\`" >> $SCRIPT_DIR/security-report.txt
echo "" >> $SCRIPT_DIR/security-report.txt
fi
echo "</details>" >> $SCRIPT_DIR/security-report.txt
echo "" >> $SCRIPT_DIR/security-report.txt
fi
echo "" >> $SCRIPT_DIR/security-report.txt