Skip to content
This repository was archived by the owner on Oct 14, 2020. It is now read-only.

Commit 4f3a4a5

Browse files
authored
Merge pull request #64 from secureCodeBox/fix/truncate-zap-otherinfo-fields
Truncate overly long fields in ZAP Findings
2 parents e70be31 + e65e6d6 commit 4f3a4a5

File tree

2 files changed

+61
-18
lines changed

2 files changed

+61
-18
lines changed

scanners/zap/parser/__snapshots__/parser.test.js.snap

Lines changed: 27 additions & 2 deletions
Large diffs are not rendered by default.

scanners/zap/parser/parser.js

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,67 @@
11
function riskToSeverity(risk) {
22
switch (parseInt(risk, 10)) {
33
case 0:
4-
return 'INFORMATIONAL';
4+
return "INFORMATIONAL";
55
case 1:
6-
return 'LOW';
6+
return "LOW";
77
case 2:
8-
return 'MEDIUM';
8+
return "MEDIUM";
99
default:
10-
return 'HIGH';
10+
return "HIGH";
1111
}
1212
}
1313

14-
function stripHtmlTags(str)
15-
{
16-
if ((!str) || ( str === null ) || ( str === '' ))
17-
return false;
18-
else
19-
str = str.toString();
20-
return str.replace(/<[^>]*>/g, '');
14+
function stripHtmlTags(str) {
15+
if (!str || str === null || str === "") {
16+
return false;
17+
} else {
18+
str = str.toString();
19+
}
20+
return str.replace(/<[^>]*>/g, "");
21+
}
22+
23+
function truncate({ text, maxLength = 2048 }) {
24+
if (!text || text.length < maxLength) {
25+
return text;
26+
}
27+
28+
return `${text.slice(0, maxLength)}...`;
2129
}
2230

2331
async function parse(fileContent) {
2432
return fileContent.site.flatMap(
25-
({ '@name': location, '@host': host, alerts }) => {
26-
return alerts.map(alert => {
33+
({ "@name": location, "@host": host, alerts }) => {
34+
return alerts.map((alert) => {
35+
const findingUrls = (alert.instances || []).map((instance) => {
36+
return {
37+
...instance,
38+
evidence: truncate({ text: instance.evidence, maxLength: 256 }),
39+
};
40+
});
41+
2742
return {
2843
name: stripHtmlTags(alert.name),
2944
description: stripHtmlTags(alert.desc),
3045
hint: alert.hint,
3146
category: alert.alert || stripHtmlTags(alert.name),
3247
location,
33-
osi_layer: 'APPLICATION',
48+
osi_layer: "APPLICATION",
3449
severity: riskToSeverity(alert.riskcode),
3550
attributes: {
3651
host: host,
3752
zap_confidence: alert.confidence || null,
3853
zap_count: alert.count || null,
3954
zap_solution: stripHtmlTags(alert.solution) || null,
40-
zap_otherinfo: stripHtmlTags(alert.otherinfo) || null,
55+
zap_otherinfo: truncate({
56+
text: stripHtmlTags(alert.otherinfo) || null,
57+
maxLength: 2048,
58+
}),
4159
zap_reference: stripHtmlTags(alert.reference) || null,
4260
zap_cweid: alert.cweid || null,
4361
zap_wascid: alert.wascid || null,
4462
zap_riskcode: alert.riskcode || null,
4563
zap_pluginid: alert.pluginid || null,
46-
zap_finding_urls: alert.instances || null,
64+
zap_finding_urls: findingUrls,
4765
},
4866
};
4967
});

0 commit comments

Comments
 (0)