-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
305 lines (298 loc) · 13.3 KB
/
false-positive-ops.yml
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
name: False Positive Ops
on:
issues:
types: [opened, edited, reopened]
permissions:
contents: read
issues: write
jobs:
issue:
runs-on: ubuntu-latest
if: contains(github.event.issue.labels.*.name, 'FP Report')
steps:
- name: Remove Labels
if: contains(github.event.issue.labels.*.name, 'pending more information')
uses: actions/[email protected]
with:
script: |
github.rest.issues.removeLabel({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
name: 'pending more information'
})
console.log(
await github.rest.issues.listLabelsOnIssue
({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo
})
)
- uses: actions/checkout@v4
with:
path: odc
- name: Parse False Positive Issue
uses: stefanbuck/github-issue-parser@v3
id: issue-parser
with:
issue-body: ${{ github.event.issue.body }}
template-path: odc/.github/ISSUE_TEMPLATE/false-positive-report.yml
- uses: actions/[email protected]
with:
node-version: 14
- name: Initialize npm
run: |
npm init -y
npm install packageurl-js
- name: Parse Package URL
id: purl-parser
uses: actions/[email protected]
env:
PURL: ${{ fromJSON(steps.issue-parser.outputs.jsonString).purl }}
with:
script: |
try {
const { PackageURL } = require('packageurl-js');
const pkg = PackageURL.fromString(process.env.PURL.trim().replaceAll(/^`|`$/g,''));
console.log(pkg);
return pkg;
} catch (ex) {
console.log(ex);
await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: 'Error parsing package url: ' + process.env.PURL + '.\n\nError: ' + ex + '\n\nPlease correct the package URL - consider copying the package url from the HTML report.'
})
github.rest.issues.addLabels({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
labels: ['pending more information']
})
throw new Error('Invalid package url');
}
- name: Setup maven fp-project
if: ${{ fromJSON(steps.purl-parser.outputs.result).type == 'maven' }}
env:
GROUPID: ${{ fromJSON(steps.purl-parser.outputs.result).namespace }}
ARTIFACTID: ${{ fromJSON(steps.purl-parser.outputs.result).name }}
VERSION: ${{ fromJSON(steps.purl-parser.outputs.result).version }}
run: |
ver=$(curl -s https://jeremylong.github.io/DependencyCheck/current.txt)
mkdir ./fp-project
cp ${{github.workspace}}/odc/.github/workflows/files/maven-pom.start ./fp-project/pom.xml
echo -n $ver >> ./fp-project/pom.xml
cat ${{github.workspace}}/odc/.github/workflows/files/maven-pom.middle >> ./fp-project/pom.xml
echo "<dependency>" >> ./fp-project/pom.xml
echo " <groupId>$GROUPID</groupId>" >> ./fp-project/pom.xml
echo " <artifactId>$ARTIFACTID</artifactId>" >> ./fp-project/pom.xml
echo " <version>$VERSION</version>" >> ./fp-project/pom.xml
echo "</dependency>" >> ./fp-project/pom.xml
cat ${{github.workspace}}/odc/.github/workflows/files/maven-pom.end >> ./fp-project/pom.xml
cd ./fp-project
## not ideal as verify would be better then using the docker image...
##mvn verify
mvn dependency:copy-dependencies --no-transfer-progress --batch-mode
cd ..
- name: Setup npm fp-project
if: ${{ fromJSON(steps.purl-parser.outputs.result).type == 'npm' }}
env:
PACKAGE: ${{ fromJSON(steps.purl-parser.outputs.result).name }}@${{ fromJSON(steps.purl-parser.outputs.result).version }}
run: |
mkdir ./fp-project
cd ./fp-project
npm init -y
npm install "$PACKAGE"
cd ..
- name: Setup dotnet
if: ${{ fromJSON(steps.purl-parser.outputs.result).type == 'nuget' }}
uses: actions/[email protected]
with:
dotnet-version: '8.0.x'
- name: Setup dotnet fp-project
if: ${{ fromJSON(steps.purl-parser.outputs.result).type == 'nuget' }}
env:
PACKAGE: ${{ fromJSON(steps.purl-parser.outputs.result).name }}
VERSION: ${{ fromJSON(steps.purl-parser.outputs.result).version }}
run: |
dotnet new classlib --language C# --name fp-project --no-update-check
cd fp-project
dotnet add package "$PACKAGE" --version "$VERSION"
dotnet publish
cd ..
- name: "Check for setup complete"
uses: andstor/file-existence-action@v3
id: check_files
with:
files: "./fp-project"
- name: Run ODC
if: steps.check_files.outputs.files_exists == 'true'
uses: dependency-check/Dependency-Check_Action@main
with:
project: 'fp-test'
path: './fp-project'
format: 'HTML'
args: >
--failOnCVSS 11
--enableExperimental
- name: Upload FP Report
if: steps.check_files.outputs.files_exists == 'true'
uses: actions/upload-artifact@v4
with:
name: FP Report
path: ${{github.workspace}}/reports
- name: Comment on maven issue
if: ${{ fromJSON(steps.purl-parser.outputs.result).type == 'maven' }}
uses: actions/[email protected]
env:
GROUPID: ${{ fromJSON(steps.purl-parser.outputs.result).namespace }}
ARTIFACTID: ${{ fromJSON(steps.purl-parser.outputs.result).name }}
VERSION: ${{ fromJSON(steps.purl-parser.outputs.result).version }}
TYPE: ${{ fromJSON(steps.purl-parser.outputs.result).type }}
CPE: ${{ fromJSON(steps.issue-parser.outputs.jsonString).cpe }}
with:
script: |
var namespace = process.env.GROUPID;
var name = process.env.ARTIFACTID;
var packageType = process.env.TYPE;
var purl = '^pkg:' + packageType;
if(namespace !== null && namespace !== '') {
purl += '/' + namespace.replaceAll('.','\\.');
}
if(name !== null && name !== '') {
purl += '/' + name.replaceAll('.','\\.');
}
purl += '@.*$';
var cpe = process.env.CPE.trim().replaceAll(/^`|`$/g,'').split(':');
var matchCpe;
if (cpe[1] == '2.3') {
matchcpe = 'cpe:/a:' + cpe[3] + ':' + cpe[4];
} else {
matchcpe = 'cpe:/a:' + cpe[2] + ':' + cpe[3];
}
await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: 'Maven Coordinates\n\n```xml\n<dependency>\n <groupId>' + process.env.GROUPID + '</groupId>\n <artifactId>' + process.env.ARTIFACTID + '</artifactId>\n <version>' + process.env.VERSION + '</version>\n</dependency>\n```\n\n' +
'Suppression rule:\n```xml\n' +
'<suppress base="true">\n' +
' <notes><![CDATA[\n' +
' FP per issue #' + context.issue.number + '\n' +
' ]]></notes>\n' +
' <packageUrl regex="true">' + purl + '</packageUrl>\n' +
' <cpe>' + matchcpe + '</cpe>\n' +
'</suppress>\n```\n\n' +
'Link to test results: ' + context.serverUrl + '/' + context.repo.owner + '/' + context.repo.repo + '/actions/runs/' + context.runId
})
github.rest.issues.addLabels({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
labels: ['maven']
})
- name: Comment on npm issue
if: ${{ fromJSON(steps.purl-parser.outputs.result).type == 'npm' }}
uses: actions/[email protected]
env:
NAME: ${{ fromJSON(steps.purl-parser.outputs.result).name }}
VERSION: ${{ fromJSON(steps.purl-parser.outputs.result).version }}
TYPE: ${{ fromJSON(steps.purl-parser.outputs.result).type }}
CPE: ${{ fromJSON(steps.issue-parser.outputs.jsonString).cpe }}
with:
script: |
var name = process.env.NAME;
var packageType = process.env.TYPE;
var purl = '^pkg:' + packageType;
if(name !== null && name !== '') {
purl += '/' + name.replaceAll('.','\\.');
}
purl += '@.*$';
var cpe = process.env.CPE.trim().replaceAll(/^`|`$/g,'').split(':');
console.log(cpe);
var matchCpe;
if (cpe[1] == '2.3') {
matchcpe = 'cpe:/a:' + cpe[3] + ':' + cpe[4];
} else {
matchcpe = 'cpe:/a:' + cpe[2] + ':' + cpe[3];
}
await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: 'Npm Coordinates\n\n```shell\nnpm -i ' + process.env.NAME + '@' + process.env.VERSION + '\n```\n\n' +
'Suppression rule:\n```xml\n' +
'<suppress base="true">\n' +
' <notes><![CDATA[\n' +
' FP per issue #' + context.issue.number + '\n' +
' ]]></notes>\n' +
' <packageUrl regex="true">' + purl + '</packageUrl>\n' +
' <cpe>' + matchcpe + '</cpe>\n' +
'</suppress>\n```\n\n' +
'Link to test results: ' + context.serverUrl + '/' + context.repo.owner + '/' + context.repo.repo + '/actions/runs/' + context.runId
})
github.rest.issues.addLabels({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
labels: ['npm']
})
- name: Comment on dotnet issue
if: ${{ fromJSON(steps.purl-parser.outputs.result).type == 'nuget' }}
uses: actions/[email protected]
env:
NAME: ${{ fromJSON(steps.purl-parser.outputs.result).name }}
VERSION: ${{ fromJSON(steps.purl-parser.outputs.result).version }}
TYPE: ${{ fromJSON(steps.purl-parser.outputs.result).type }}
CPE: ${{ fromJSON(steps.issue-parser.outputs.jsonString).cpe }}
with:
script: |
var name = process.env.NAME;
var packageType = process.env.TYPE;
var purl = '^pkg:' + packageType;
if(name !== null && name !== '') {
purl += '/' + name.replaceAll('.','\\.');
}
purl += '@.*$';
var cpe = process.env.CPE.trim().replaceAll(/^`|`$/g,'').split(':');
var matchCpe;
if (cpe[1] == '2.3') {
matchcpe = 'cpe:/a:' + cpe[3] + ':' + cpe[4];
} else {
matchcpe = 'cpe:/a:' + cpe[2] + ':' + cpe[3];
}
await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: 'Nuget Coordinates\n\n```shell\ndotnet add package ' + process.env.NAME + ' --version ' + process.env.VERSION + '\n```\n\n' +
'Suppression rule:\n```xml\n' +
'<suppress base="true">\n' +
' <notes><![CDATA[\n' +
' FP per issue #' + context.issue.number + '\n' +
' ]]></notes>\n' +
' <packageUrl regex="true">' + purl + '</packageUrl>\n' +
' <cpe>' + matchcpe + '</cpe>\n' +
'</suppress>\n```\n\n' +
'Link to test results: ' + context.serverUrl + '/' + context.repo.owner + '/' + context.repo.repo + '/actions/runs/' + context.runId
})
github.rest.issues.addLabels({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
labels: ['dotnet']
})
- name: Message failure
if: ${{ failure() }}
uses: actions/[email protected]
with:
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: 'Failed to automatically evaluate the false positive. ' +
'See: ' + context.serverUrl + '/' + context.repo.owner + '/' + context.repo.repo + '/actions/runs/' + context.runId,
});