@@ -261,14 +261,7 @@ func (s Scanner) scanLicenses(target types.ScanTarget, options types.ScanOptions
261
261
var osPkgLicenses []types.DetectedLicense
262
262
for _ , pkg := range target .Packages {
263
263
for _ , license := range pkg .Licenses {
264
- category , severity := scanner .Scan (license )
265
- osPkgLicenses = append (osPkgLicenses , types.DetectedLicense {
266
- Severity : severity ,
267
- Category : category ,
268
- PkgName : pkg .Name ,
269
- Name : license ,
270
- Confidence : 1.0 ,
271
- })
264
+ osPkgLicenses = append (osPkgLicenses , toDetectedLicense (scanner , license , pkg .Name , "" ))
272
265
}
273
266
}
274
267
results = append (results , types.Result {
@@ -282,17 +275,11 @@ func (s Scanner) scanLicenses(target types.ScanTarget, options types.ScanOptions
282
275
var langLicenses []types.DetectedLicense
283
276
for _ , lib := range app .Packages {
284
277
for _ , license := range lib .Licenses {
285
- category , severity := scanner .Scan (license )
286
- langLicenses = append (langLicenses , types.DetectedLicense {
287
- Severity : severity ,
288
- Category : category ,
289
- PkgName : lib .Name ,
290
- Name : license ,
291
- // Lock files use app.FilePath - https://github.com/aquasecurity/trivy/blob/6ccc0a554b07b05fd049f882a1825a0e1e0aabe1/pkg/fanal/types/artifact.go#L245-L246
292
- // Applications use lib.FilePath - https://github.com/aquasecurity/trivy/blob/6ccc0a554b07b05fd049f882a1825a0e1e0aabe1/pkg/fanal/types/artifact.go#L93-L94
293
- FilePath : lo .Ternary (lib .FilePath != "" , lib .FilePath , app .FilePath ),
294
- Confidence : 1.0 ,
295
- })
278
+ // Lock files use app.FilePath - https://github.com/aquasecurity/trivy/blob/6ccc0a554b07b05fd049f882a1825a0e1e0aabe1/pkg/fanal/types/artifact.go#L245-L246
279
+ // Applications use lib.FilePath - https://github.com/aquasecurity/trivy/blob/6ccc0a554b07b05fd049f882a1825a0e1e0aabe1/pkg/fanal/types/artifact.go#L93-L94
280
+ filePath := lo .Ternary (lib .FilePath != "" , lib .FilePath , app .FilePath )
281
+
282
+ langLicenses = append (langLicenses , toDetectedLicense (scanner , license , lib .Name , filePath ))
296
283
}
297
284
}
298
285
@@ -390,6 +377,29 @@ func toDetectedMisconfiguration(res ftypes.MisconfResult, defaultSeverity dbType
390
377
}
391
378
}
392
379
380
+ func toDetectedLicense (scanner licensing.Scanner , license , pkgName , filePath string ) types.DetectedLicense {
381
+ var category ftypes.LicenseCategory
382
+ var severity , licenseText string
383
+ if strings .HasPrefix (license , licensing .LicenseTextPrefix ) { // License text
384
+ licenseText = strings .TrimPrefix (license , licensing .LicenseTextPrefix )
385
+ category = ftypes .CategoryUnknown
386
+ severity = dbTypes .SeverityUnknown .String ()
387
+ license = licensing .CustomLicensePrefix + ": " + licensing .TrimLicenseText (licenseText )
388
+ } else { // License name
389
+ category , severity = scanner .Scan (license )
390
+ }
391
+
392
+ return types.DetectedLicense {
393
+ Severity : severity ,
394
+ Category : category ,
395
+ PkgName : pkgName ,
396
+ FilePath : filePath ,
397
+ Name : license ,
398
+ Text : licenseText ,
399
+ Confidence : 1.0 ,
400
+ }
401
+ }
402
+
393
403
func ShouldScanMisconfigOrRbac (scanners types.Scanners ) bool {
394
404
return scanners .AnyEnabled (types .MisconfigScanner , types .RBACScanner )
395
405
}
0 commit comments