|
1 | 1 | function riskToSeverity(risk) { |
2 | 2 | switch (parseInt(risk, 10)) { |
3 | 3 | case 0: |
4 | | - return 'INFORMATIONAL'; |
| 4 | + return "INFORMATIONAL"; |
5 | 5 | case 1: |
6 | | - return 'LOW'; |
| 6 | + return "LOW"; |
7 | 7 | case 2: |
8 | | - return 'MEDIUM'; |
| 8 | + return "MEDIUM"; |
9 | 9 | default: |
10 | | - return 'HIGH'; |
| 10 | + return "HIGH"; |
11 | 11 | } |
12 | 12 | } |
13 | 13 |
|
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)}...`; |
21 | 29 | } |
22 | 30 |
|
23 | 31 | async function parse(fileContent) { |
24 | 32 | 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 | + |
27 | 42 | return { |
28 | 43 | name: stripHtmlTags(alert.name), |
29 | 44 | description: stripHtmlTags(alert.desc), |
30 | 45 | hint: alert.hint, |
31 | 46 | category: alert.alert || stripHtmlTags(alert.name), |
32 | 47 | location, |
33 | | - osi_layer: 'APPLICATION', |
| 48 | + osi_layer: "APPLICATION", |
34 | 49 | severity: riskToSeverity(alert.riskcode), |
35 | 50 | attributes: { |
36 | 51 | host: host, |
37 | 52 | zap_confidence: alert.confidence || null, |
38 | 53 | zap_count: alert.count || null, |
39 | 54 | 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 | + }), |
41 | 59 | zap_reference: stripHtmlTags(alert.reference) || null, |
42 | 60 | zap_cweid: alert.cweid || null, |
43 | 61 | zap_wascid: alert.wascid || null, |
44 | 62 | zap_riskcode: alert.riskcode || null, |
45 | 63 | zap_pluginid: alert.pluginid || null, |
46 | | - zap_finding_urls: alert.instances || null, |
| 64 | + zap_finding_urls: findingUrls, |
47 | 65 | }, |
48 | 66 | }; |
49 | 67 | }); |
|
0 commit comments