@@ -59,29 +59,29 @@ func scanPullRequest(repoConfig *utils.FrogbotRepoConfig, client vcsclient.VcsCl
59
59
xrayScanParams := createXrayScanParams (repoConfig .Watches , repoConfig .JFrogProjectKey )
60
60
var vulnerabilitiesRows []formats.VulnerabilityOrViolationRow
61
61
for _ , project := range repoConfig .Projects {
62
- currentScan , err := auditSource (xrayScanParams , project , & repoConfig .Server )
62
+ currentScan , isMultipleRoot , err := auditSource (xrayScanParams , project , & repoConfig .Server )
63
63
if err != nil {
64
64
return err
65
65
}
66
66
if repoConfig .IncludeAllVulnerabilities {
67
67
log .Info ("Frogbot is configured to show all vulnerabilities" )
68
- allIssuesRows , err := createAllIssuesRows (currentScan )
68
+ allIssuesRows , err := createAllIssuesRows (currentScan , isMultipleRoot )
69
69
if err != nil {
70
70
return err
71
71
}
72
72
vulnerabilitiesRows = append (vulnerabilitiesRows , allIssuesRows ... )
73
- } else {
74
- // Audit target code
75
- previousScan , err := auditTarget (client , xrayScanParams , project , repoConfig .Branches [0 ], & repoConfig .Git , & repoConfig .Server )
76
- if err != nil {
77
- return err
78
- }
79
- newIssuesRows , err := createNewIssuesRows (previousScan , currentScan )
80
- if err != nil {
81
- return err
82
- }
83
- vulnerabilitiesRows = append (vulnerabilitiesRows , newIssuesRows ... )
73
+ continue
74
+ }
75
+ // Audit target code
76
+ previousScan , isMultipleRoot , err := auditTarget (client , xrayScanParams , project , repoConfig .Branches [0 ], & repoConfig .Git , & repoConfig .Server )
77
+ if err != nil {
78
+ return err
79
+ }
80
+ newIssuesRows , err := createNewIssuesRows (previousScan , currentScan , isMultipleRoot )
81
+ if err != nil {
82
+ return err
84
83
}
84
+ vulnerabilitiesRows = append (vulnerabilitiesRows , newIssuesRows ... )
85
85
}
86
86
87
87
log .Info ("Xray scan completed" )
@@ -142,18 +142,18 @@ func getCommentFunctions(simplifiedOutput bool) (utils.GetTitleFunc, utils.GetSe
142
142
}
143
143
144
144
// Create vulnerabilities rows. The rows should contain only the new issues added by this PR
145
- func createNewIssuesRows (previousScan , currentScan []services.ScanResponse ) (vulnerabilitiesRows []formats.VulnerabilityOrViolationRow , err error ) {
145
+ func createNewIssuesRows (previousScan , currentScan []services.ScanResponse , isMultipleRoot bool ) (vulnerabilitiesRows []formats.VulnerabilityOrViolationRow , err error ) {
146
146
previousScanAggregatedResults := aggregateScanResults (previousScan )
147
147
currentScanAggregatedResults := aggregateScanResults (currentScan )
148
148
149
149
if len (currentScanAggregatedResults .Violations ) > 0 {
150
- newViolations , err := getNewViolations (previousScanAggregatedResults , currentScanAggregatedResults )
150
+ newViolations , err := getNewViolations (previousScanAggregatedResults , currentScanAggregatedResults , isMultipleRoot )
151
151
if err != nil {
152
152
return vulnerabilitiesRows , err
153
153
}
154
154
vulnerabilitiesRows = append (vulnerabilitiesRows , newViolations ... )
155
155
} else if len (currentScanAggregatedResults .Vulnerabilities ) > 0 {
156
- newVulnerabilities , err := getNewVulnerabilities (previousScanAggregatedResults , currentScanAggregatedResults )
156
+ newVulnerabilities , err := getNewVulnerabilities (previousScanAggregatedResults , currentScanAggregatedResults , isMultipleRoot )
157
157
if err != nil {
158
158
return vulnerabilitiesRows , err
159
159
}
@@ -175,28 +175,22 @@ func aggregateScanResults(scanResults []services.ScanResponse) services.ScanResp
175
175
return aggregateResults
176
176
}
177
177
178
- // Create vulnerabilities rows. The rows should contain All the issues that were found in this module scan.
179
- func getScanVulnerabilitiesRows (currentScan services.ScanResponse ) ([]formats.VulnerabilityOrViolationRow , error ) {
180
- if len (currentScan . Violations ) > 0 {
181
- violationsRows , _ , _ , err := xrayutils .PrepareViolations (currentScan . Violations , false )
178
+ // Create vulnerabilities rows. The rows should contain all the issues that were found in this module scan.
179
+ func getScanVulnerabilitiesRows (violations [] services.Violation , vulnerabilities []services. Vulnerability , isMultipleRoot bool ) ([]formats.VulnerabilityOrViolationRow , error ) {
180
+ if len (violations ) > 0 {
181
+ violationsRows , _ , _ , err := xrayutils .PrepareViolations (violations , isMultipleRoot , true )
182
182
return violationsRows , err
183
- } else if len (currentScan .Vulnerabilities ) > 0 {
184
- return xrayutils .PrepareVulnerabilities (currentScan .Vulnerabilities , false )
183
+ }
184
+ if len (vulnerabilities ) > 0 {
185
+ return xrayutils .PrepareVulnerabilities (vulnerabilities , isMultipleRoot , true )
185
186
}
186
187
return []formats.VulnerabilityOrViolationRow {}, nil
187
188
}
188
189
189
- // Create vulnerabilities rows. The rows should contain All the issues that were found in this PR
190
- func createAllIssuesRows (currentScan []services.ScanResponse ) ([]formats.VulnerabilityOrViolationRow , error ) {
191
- var vulnerabilitiesRows []formats.VulnerabilityOrViolationRow
192
- for i := 0 ; i < len (currentScan ); i += 1 {
193
- newVulnerabilitiesRows , err := getScanVulnerabilitiesRows (currentScan [i ])
194
- if err != nil {
195
- return vulnerabilitiesRows , err
196
- }
197
- vulnerabilitiesRows = append (vulnerabilitiesRows , newVulnerabilitiesRows ... )
198
- }
199
- return vulnerabilitiesRows , nil
190
+ // Create vulnerabilities rows. The rows should contain all the issues that were found in this PR
191
+ func createAllIssuesRows (currentScan []services.ScanResponse , isMultipleRoot bool ) ([]formats.VulnerabilityOrViolationRow , error ) {
192
+ violations , vulnerabilities , _ := xrayutils .SplitScanResults (currentScan )
193
+ return getScanVulnerabilitiesRows (violations , vulnerabilities , isMultipleRoot )
200
194
}
201
195
202
196
func createXrayScanParams (watches []string , project string ) (params services.XrayGraphScanParams ) {
@@ -215,10 +209,10 @@ func createXrayScanParams(watches []string, project string) (params services.Xra
215
209
return
216
210
}
217
211
218
- func auditSource (xrayScanParams services.XrayGraphScanParams , project utils.Project , server * coreconfig.ServerDetails ) ([]services.ScanResponse , error ) {
212
+ func auditSource (xrayScanParams services.XrayGraphScanParams , project utils.Project , server * coreconfig.ServerDetails ) ([]services.ScanResponse , bool , error ) {
219
213
wd , err := os .Getwd ()
220
214
if err != nil {
221
- return []services.ScanResponse {}, err
215
+ return []services.ScanResponse {}, false , err
222
216
}
223
217
fullPathWds := getFullPathWorkingDirs (& project , wd )
224
218
return runInstallAndAudit (xrayScanParams , & project , server , true , fullPathWds ... )
@@ -240,7 +234,7 @@ func getFullPathWorkingDirs(project *utils.Project, baseWd string) []string {
240
234
return fullPathWds
241
235
}
242
236
243
- func auditTarget (client vcsclient.VcsClient , xrayScanParams services.XrayGraphScanParams , project utils.Project , branch string , git * utils.Git , server * coreconfig.ServerDetails ) (res []services.ScanResponse , err error ) {
237
+ func auditTarget (client vcsclient.VcsClient , xrayScanParams services.XrayGraphScanParams , project utils.Project , branch string , git * utils.Git , server * coreconfig.ServerDetails ) (res []services.ScanResponse , isMultipleRoot bool , err error ) {
244
238
// First download the target repo to temp dir
245
239
log .Info ("Auditing " + git .RepoName + " " + branch )
246
240
wd , cleanup , err := utils .DownloadRepoToTempDir (client , branch , git )
@@ -258,19 +252,19 @@ func auditTarget(client vcsclient.VcsClient, xrayScanParams services.XrayGraphSc
258
252
return runInstallAndAudit (xrayScanParams , & project , server , false , fullPathWds ... )
259
253
}
260
254
261
- func runInstallAndAudit (xrayScanParams services.XrayGraphScanParams , project * utils.Project , server * coreconfig.ServerDetails , failOnInstallationErrors bool , workDirs ... string ) (results []services.ScanResponse , err error ) {
255
+ func runInstallAndAudit (xrayScanParams services.XrayGraphScanParams , project * utils.Project , server * coreconfig.ServerDetails , failOnInstallationErrors bool , workDirs ... string ) (results []services.ScanResponse , isMultipleRoot bool , err error ) {
262
256
for _ , wd := range workDirs {
263
257
if err = runInstallIfNeeded (project , wd , failOnInstallationErrors ); err != nil {
264
- return nil , err
258
+ return nil , false , err
265
259
}
266
260
}
267
261
268
- results , _ , err = audit .GenericAudit (xrayScanParams , server , false , project .UseWrapper , false ,
262
+ results , isMultipleRoot , err = audit .GenericAudit (xrayScanParams , server , false , project .UseWrapper , false ,
269
263
nil , nil , project .PipRequirementsFile , false , workDirs , []string {}... )
270
264
if err != nil {
271
- return nil , err
265
+ return nil , false , err
272
266
}
273
- return results , err
267
+ return results , isMultipleRoot , err
274
268
}
275
269
276
270
func runInstallIfNeeded (project * utils.Project , workDir string , failOnInstallationErrors bool ) (err error ) {
@@ -297,16 +291,16 @@ func runInstallIfNeeded(project *utils.Project, workDir string, failOnInstallati
297
291
return
298
292
}
299
293
300
- func getNewViolations (previousScan , currentScan services.ScanResponse ) (newViolationsRows []formats.VulnerabilityOrViolationRow , err error ) {
294
+ func getNewViolations (previousScan , currentScan services.ScanResponse , isMultipleRoot bool ) (newViolationsRows []formats.VulnerabilityOrViolationRow , err error ) {
301
295
existsViolationsMap := make (map [string ]formats.VulnerabilityOrViolationRow )
302
- violationsRows , _ , _ , err := xrayutils .PrepareViolations (previousScan .Violations , false )
296
+ violationsRows , _ , _ , err := xrayutils .PrepareViolations (previousScan .Violations , isMultipleRoot , true )
303
297
if err != nil {
304
298
return violationsRows , err
305
299
}
306
300
for _ , violation := range violationsRows {
307
301
existsViolationsMap [getUniqueID (violation )] = violation
308
302
}
309
- violationsRows , _ , _ , err = xrayutils .PrepareViolations (currentScan .Violations , false )
303
+ violationsRows , _ , _ , err = xrayutils .PrepareViolations (currentScan .Violations , isMultipleRoot , true )
310
304
if err != nil {
311
305
return newViolationsRows , err
312
306
}
@@ -318,16 +312,16 @@ func getNewViolations(previousScan, currentScan services.ScanResponse) (newViola
318
312
return
319
313
}
320
314
321
- func getNewVulnerabilities (previousScan , currentScan services.ScanResponse ) (newVulnerabilitiesRows []formats.VulnerabilityOrViolationRow , err error ) {
315
+ func getNewVulnerabilities (previousScan , currentScan services.ScanResponse , isMultipleRoot bool ) (newVulnerabilitiesRows []formats.VulnerabilityOrViolationRow , err error ) {
322
316
existsVulnerabilitiesMap := make (map [string ]formats.VulnerabilityOrViolationRow )
323
- vulnerabilitiesRows , err := xrayutils .PrepareVulnerabilities (previousScan .Vulnerabilities , false )
317
+ vulnerabilitiesRows , err := xrayutils .PrepareVulnerabilities (previousScan .Vulnerabilities , isMultipleRoot , true )
324
318
if err != nil {
325
319
return newVulnerabilitiesRows , err
326
320
}
327
321
for _ , vulnerability := range vulnerabilitiesRows {
328
322
existsVulnerabilitiesMap [getUniqueID (vulnerability )] = vulnerability
329
323
}
330
- vulnerabilitiesRows , err = xrayutils .PrepareVulnerabilities (currentScan .Vulnerabilities , false )
324
+ vulnerabilitiesRows , err = xrayutils .PrepareVulnerabilities (currentScan .Vulnerabilities , isMultipleRoot , true )
331
325
if err != nil {
332
326
return newVulnerabilitiesRows , err
333
327
}
@@ -340,7 +334,7 @@ func getNewVulnerabilities(previousScan, currentScan services.ScanResponse) (new
340
334
}
341
335
342
336
func getUniqueID (vulnerability formats.VulnerabilityOrViolationRow ) string {
343
- return vulnerability .ImpactedPackageName + vulnerability .ImpactedPackageVersion + vulnerability .IssueId
337
+ return vulnerability .ImpactedDependencyName + vulnerability .ImpactedDependencyVersion + vulnerability .IssueId
344
338
}
345
339
346
340
func createPullRequestMessage (vulnerabilitiesRows []formats.VulnerabilityOrViolationRow , getBanner utils.GetTitleFunc , getSeverityTag utils.GetSeverityTagFunc ) string {
@@ -349,17 +343,27 @@ func createPullRequestMessage(vulnerabilitiesRows []formats.VulnerabilityOrViola
349
343
}
350
344
var tableContent string
351
345
for _ , vulnerability := range vulnerabilitiesRows {
352
- var componentName , componentVersion , cve string
346
+ var cve string
347
+ var directDependencies , directDependenciesVersions strings.Builder
353
348
if len (vulnerability .Components ) > 0 {
354
- componentName = vulnerability .ImpactedPackageName
355
- componentVersion = vulnerability .ImpactedPackageVersion
349
+ for _ , dependency := range vulnerability .Components {
350
+ directDependencies .WriteString (fmt .Sprintf ("%s; " , dependency .Name ))
351
+ directDependenciesVersions .WriteString (fmt .Sprintf ("%s; " , dependency .Version ))
352
+ }
356
353
}
357
354
if len (vulnerability .Cves ) > 0 {
358
355
cve = vulnerability .Cves [0 ].Id
359
356
}
360
357
fixedVersionString := strings .Join (vulnerability .FixedVersions , " " )
361
- tableContent += fmt .Sprintf ("\n | %s%8s | %s | %s | %s | %s | %s | %s " , getSeverityTag (utils .IconName (vulnerability .Severity )), vulnerability .Severity , vulnerability .ImpactedPackageName ,
362
- vulnerability .ImpactedPackageVersion , fixedVersionString , componentName , componentVersion , cve )
358
+ tableContent += fmt .Sprintf ("\n | %s%8s | %s | %s | %s | %s | %s | %s " ,
359
+ getSeverityTag (utils .IconName (vulnerability .Severity )),
360
+ vulnerability .Severity ,
361
+ strings .TrimSuffix (directDependencies .String (), "; " ),
362
+ strings .TrimSuffix (directDependenciesVersions .String (), "; " ),
363
+ vulnerability .ImpactedDependencyName ,
364
+ vulnerability .ImpactedDependencyVersion ,
365
+ fixedVersionString ,
366
+ cve )
363
367
}
364
368
return getBanner (utils .VulnerabilitiesBannerSource ) + utils .WhatIsFrogbotMd + utils .TableHeader + tableContent
365
369
}
0 commit comments