-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.js
88 lines (83 loc) · 3.41 KB
/
action.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
83
84
85
86
87
88
const Netsparker = require('./netsparker');
const core = require('@actions/core')
const githubEvent = require(process.env.GITHUB_EVENT_PATH)
async function exec () {
try
{
var config = parseConfig();
netsparker = new Netsparker(config.userid, config.apitoken, config.profilename, config.targetsite);
const scanId = await netsparker.scan();
if(config.report === 'true') {
await netsparker.waitForScanToComplete(scanId);
const scanResults = await netsparker.scanResults(scanId);
core.setOutput('scanresults', scanResults);
const scanReport = await netsparker.scanReport(scanId, 'Vulnerabilities', 'Json');
core.setOutput('scanreport', scanReport);
if(config.report === 'true') {
if(config.junit) {
await this.netsparker.createJunitTestReport(scanResults, config.junit);
} else {
console.table(scanResults);
}
}
if(config.criticalthreshold || config.highthreshold || config.mediumthreshold) {
var criticalCount = 0;
var highCount = 0;
var mediumCount = 0;
for(var i = 0; i < scanReport.Vulnerabilities.length; i++) {
var v = scanReport.Vulnerabilities[i];
switch(v.Severity) {
case "Critical":
criticalCount++;
break;
case "High":
highCount++;
break;
case "Medium":
mediumCount++;
break;
}
}
var thresholdReached = false;
if(config.criticalthreshold) {
if(criticalCount > parseInt(config.criticalthreshold)) {
thresholdReached = true;
console.error(`Critical count exceeds threshold (${criticalCount}).`);
}
}
if(config.highthreshold) {
if(highCount > parseInt(config.highthreshold)) {
thresholdReached = true;
console.error(`High count exceeds threshold (${highCount}).`);
}
}
if(config.mediumthreshold) {
if(mediumCount > parseInt(config.mediumthreshold)) {
thresholdReached = true;
console.error(`Medium count exceeds threshold (${mediumCount}).`)
}
}
if(thresholdReached) {
throw new Error("One or more thresholds where reached. Please see report in Netsparker");
}
}
}
} catch (error) {
console.error(error)
process.exit(1)
}
}
function parseConfig () {
return {
userid: core.getInput('userid'),
apitoken: core.getInput('apitoken'),
profilename: core.getInput('profilename'),
targetsite: core.getInput('targetsite'),
report: core.getInput('report'),
junit: core.getInput('junit'),
criticalthreshold: core.getInput('criticalthreshold'),
highthreshold: core.getInput('highthreshold'),
mediumthreshold: core.getInput('mediumthreshold')
}
}
exec()