Skip to content

Commit ce80541

Browse files
committed
Fix openapi
1 parent d0078a4 commit ce80541

File tree

1 file changed

+72
-66
lines changed

1 file changed

+72
-66
lines changed

cmd/vulcan-zap/main.go

Lines changed: 72 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"github.com/adevinta/vulcan-check-sdk/helpers/command"
2121
checkstate "github.com/adevinta/vulcan-check-sdk/state"
2222
report "github.com/adevinta/vulcan-report"
23+
"github.com/sirupsen/logrus"
2324
)
2425

2526
const (
@@ -70,8 +71,8 @@ jobs:
7071
{{ if .OpenapiUrl }}
7172
- type: openapi
7273
parameters:
73-
apiUrl: {{ .OpenapiUrl }}
74-
targetUrl: ""
74+
apiUrl: "{{ .OpenapiUrl }}"
75+
targetUrl: "{{ .OpenapiHost }}"
7576
{{ end }}
7677
- type: passiveScan-config
7778
parameters:
@@ -264,80 +265,85 @@ func main() {
264265
return fmt.Errorf("unable to parse report: %v", err)
265266
}
266267

267-
if len(r.Site) != 1 {
268-
return fmt.Errorf("unexecpected site len in report %d", len(r.Site))
269-
}
270-
271268
vulnerabilities := make(map[string]*report.Vulnerability)
272269
vulnSummary2PluginID := make(map[string]string)
273-
for _, a := range r.Site[0].Alerts {
274-
275-
cwe := 0
276-
if a.Cweid != "-1" {
277-
cwe, err = strconv.Atoi(a.Cweid)
278-
if err != nil {
279-
logger.Warnf("Wrong number Cweid %d", cwe)
280-
}
270+
for _, site := range r.Site {
271+
logger.WithFields(logrus.Fields{
272+
"site.host": site.Host,
273+
"site.num_alerts": len(site.Alerts)}).Info("alerts")
274+
if !strings.Contains(target, site.Host) {
275+
// This can happen i.e. when the openapi target url is other than the target.
276+
// DOUBT: Filter? exclude?
277+
logger.Warnf("Reporting alerts from an outside target %s %s", target, site.Host)
281278
}
282-
v := report.Vulnerability{
283-
Summary: a.Name,
284-
Description: trimP(a.Desc),
285-
Details: a.Otherinfo,
286-
Recommendations: splitP(a.Solution),
287-
References: splitP(a.Reference),
288-
Labels: []string{"issue", "web", "zap", a.Pluginid}, // DOUBT: Added Pluginid as label.
289-
CWEID: uint32(cwe),
290-
Score: func(risk string) float32 {
291-
switch risk {
292-
case "0":
293-
return report.SeverityThresholdNone
294-
case "1":
295-
return report.SeverityThresholdLow
296-
case "2":
297-
return report.SeverityThresholdMedium
298-
case "3":
299-
return report.SeverityThresholdHigh
279+
for _, a := range site.Alerts {
280+
281+
cwe := 0
282+
if a.Cweid != "-1" {
283+
cwe, err = strconv.Atoi(a.Cweid)
284+
if err != nil {
285+
logger.Warnf("Wrong number Cweid %d", cwe)
300286
}
301-
return float32(report.SeverityNone)
302-
}(a.Riskcode),
303-
}
287+
}
288+
v := report.Vulnerability{
289+
Summary: a.Name,
290+
Description: trimP(a.Desc),
291+
Details: a.Otherinfo,
292+
Recommendations: splitP(a.Solution),
293+
References: splitP(a.Reference),
294+
Labels: []string{"issue", "web", "zap", a.Pluginid}, // DOUBT: Added Pluginid as label.
295+
CWEID: uint32(cwe),
296+
Score: func(risk string) float32 {
297+
switch risk {
298+
case "0":
299+
return report.SeverityThresholdNone
300+
case "1":
301+
return report.SeverityThresholdLow
302+
case "2":
303+
return report.SeverityThresholdMedium
304+
case "3":
305+
return report.SeverityThresholdHigh
306+
}
307+
return float32(report.SeverityNone)
308+
}(a.Riskcode),
309+
}
304310

305-
// DOUBT: Only the fist instance?
306-
if len(a.Instances) > 0 {
307-
i := a.Instances[0]
308-
v.Resources = []report.ResourcesGroup{
309-
{
310-
Name: "Affected Requests",
311-
Header: []string{
312-
"Method",
313-
"URL",
314-
"Parameter",
315-
"Attack",
316-
"Evidence",
317-
},
318-
Rows: []map[string]string{
319-
{
320-
"Method": i.Method,
321-
"URL": i.URI,
322-
"Parameter": i.Param,
323-
"Attack": i.Attack,
324-
"Evidence": i.Evidence,
311+
// DOUBT: Only the fist instance?
312+
if len(a.Instances) > 0 {
313+
i := a.Instances[0]
314+
v.Resources = []report.ResourcesGroup{
315+
{
316+
Name: "Affected Requests",
317+
Header: []string{
318+
"Method",
319+
"URL",
320+
"Parameter",
321+
"Attack",
322+
"Evidence",
323+
},
324+
Rows: []map[string]string{
325+
{
326+
"Method": i.Method,
327+
"URL": i.URI,
328+
"Parameter": i.Param,
329+
"Attack": i.Attack,
330+
"Evidence": i.Evidence,
331+
},
325332
},
326333
},
327-
},
334+
}
335+
}
336+
vulnSummary2PluginID[v.Summary] = a.Pluginid
337+
if _, ok := vulnerabilities[v.Summary]; ok {
338+
vulnerabilities[v.Summary].Resources[0].Rows = append(
339+
vulnerabilities[v.Summary].Resources[0].Rows,
340+
v.Resources[0].Rows...,
341+
)
342+
} else {
343+
vulnerabilities[v.Summary] = &v
328344
}
329-
}
330-
vulnSummary2PluginID[v.Summary] = a.Pluginid
331-
if _, ok := vulnerabilities[v.Summary]; ok {
332-
vulnerabilities[v.Summary].Resources[0].Rows = append(
333-
vulnerabilities[v.Summary].Resources[0].Rows,
334-
v.Resources[0].Rows...,
335-
)
336-
} else {
337-
vulnerabilities[v.Summary] = &v
338345
}
339346
}
340-
341347
for _, v := range vulnerabilities {
342348
// NOTE: Due to a signifcant number of false positive findings
343349
// reported for low severity issues by ZAP, the MinScore option

0 commit comments

Comments
 (0)