Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(sbom): use nuget purl type for dotnet-core #2990

Merged
merged 3 commits into from
Oct 11, 2022
Merged

Conversation

DmitriyLewen
Copy link
Contributor

@DmitriyLewen DmitriyLewen commented Oct 3, 2022

Description

use nuget purl type for dotnet-core

Before:

{
  "bomFormat": "CycloneDX",
  "specVersion": "1.4",
  "serialNumber": "urn:uuid:fa54af43-7447-4a82-af53-b9f2e4130097",
  "version": 1,
  "metadata": {
    "timestamp": "2022-10-03T06:51:30+00:00",
    "tools": [
      {
        "vendor": "aquasecurity",
        "name": "trivy",
        "version": "0.32.1"
      }
    ],
    "component": {
      "bom-ref": "b41bce6c-bb5e-4429-ad43-7db3522c0219",
      "type": "application",
      "name": "datacollector.deps.json",
      "properties": [
        {
          "name": "aquasecurity:trivy:SchemaVersion",
          "value": "2"
        }
      ]
    }
  },
  "components": [
    {
      "bom-ref": "pkg:dotnet-core/Newtonsoft.Json@9.0.1",
      "type": "library",
      "name": "Newtonsoft.Json",
      "version": "9.0.1",
      "purl": "pkg:dotnet-core/Newtonsoft.Json@9.0.1",
      "properties": [
        {
          "name": "aquasecurity:trivy:PkgType",
          "value": "dotnet-core"
        }
      ]
    },
    {
      "bom-ref": "7c2c5f96-f93a-4f14-be8b-328cc416fc1e",
      "type": "application",
      "name": "datacollector.deps.json",
      "properties": [
        {
          "name": "aquasecurity:trivy:Type",
          "value": "dotnet-core"
        },
        {
          "name": "aquasecurity:trivy:Class",
          "value": "lang-pkgs"
        }
      ]
    }
  ],
  "dependencies": [
    {
      "ref": "7c2c5f96-f93a-4f14-be8b-328cc416fc1e",
      "dependsOn": [
        "pkg:dotnet-core/Newtonsoft.Json@9.0.1"
      ]
    },
    {
      "ref": "b41bce6c-bb5e-4429-ad43-7db3522c0219",
      "dependsOn": [
        "7c2c5f96-f93a-4f14-be8b-328cc416fc1e"
      ]
    }
  ],
  "vulnerabilities": []
}

After:

{
  "bomFormat": "CycloneDX",
  "specVersion": "1.4",
  "serialNumber": "urn:uuid:962826f6-cd5b-409f-95b0-ab7469aeb24b",
  "version": 1,
  "metadata": {
    "timestamp": "2022-10-03T07:12:14+00:00",
    "tools": [
      {
        "vendor": "aquasecurity",
        "name": "trivy",
        "version": "0.32.0-1-g3233dbd0"
      }
    ],
    "component": {
      "bom-ref": "54aafb2e-9042-4a28-b07c-09148179dfb1",
      "type": "application",
      "name": "datacollector.deps.json",
      "properties": [
        {
          "name": "aquasecurity:trivy:SchemaVersion",
          "value": "2"
        }
      ]
    }
  },
  "components": [
    {
      "bom-ref": "pkg:nuget/Newtonsoft.Json@9.0.1",
      "type": "library",
      "name": "Newtonsoft.Json",
      "version": "9.0.1",
      "purl": "pkg:nuget/Newtonsoft.Json@9.0.1",
      "properties": [
        {
          "name": "aquasecurity:trivy:PkgType",
          "value": "dotnet-core"
        }
      ]
    },
    {
      "bom-ref": "5327f4f7-0954-4559-9a1e-13dd9da0a939",
      "type": "application",
      "name": "datacollector.deps.json",
      "properties": [
        {
          "name": "aquasecurity:trivy:Type",
          "value": "dotnet-core"
        },
        {
          "name": "aquasecurity:trivy:Class",
          "value": "lang-pkgs"
        }
      ]
    }
  ],
  "dependencies": [
    {
      "ref": "5327f4f7-0954-4559-9a1e-13dd9da0a939",
      "dependsOn": [
        "pkg:nuget/Newtonsoft.Json@9.0.1"
      ]
    },
    {
      "ref": "54aafb2e-9042-4a28-b07c-09148179dfb1",
      "dependsOn": [
        "5327f4f7-0954-4559-9a1e-13dd9da0a939"
      ]
    }
  ],
  "vulnerabilities": []
}
 

Related issues

Checklist

  • I've read the guidelines for contributing to this repository.
  • I've followed the conventions in the PR title.
  • I've added tests that prove my fix is effective or that my feature works.
  • I've updated the documentation with the relevant information (if needed).
  • I've added usage information (if the PR introduces new options)
  • I've included a "before" and "after" example to the description (if the PR is a user interface change).

@DmitriyLewen DmitriyLewen marked this pull request as ready for review October 3, 2022 08:53
@DmitriyLewen DmitriyLewen self-assigned this Oct 3, 2022
pkg/purl/purl.go Outdated
@@ -290,6 +290,8 @@ func purlType(t string) string {
return packageurl.TypeMaven
case string(analyzer.TypeBundler), string(analyzer.TypeGemSpec):
return packageurl.TypeGem
case string(analyzer.TypeNuget), string(ftypes.DotNetCore):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be TypeDotNetDeps, no?

Suggested change
case string(analyzer.TypeNuget), string(ftypes.DotNetCore):
case string(analyzer.TypeNuget), string(analyzer. TypeDotNetDeps):

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I think we need to add TypeNuget here.

trivy/pkg/purl/purl.go

Lines 80 to 98 in 4c32b47

func (p *PackageURL) AppType() string {
switch p.Type {
case packageurl.TypeComposer:
return string(analyzer.TypeComposer)
case packageurl.TypeMaven:
return string(analyzer.TypeJar)
case packageurl.TypeGem:
return string(analyzer.TypeGemSpec)
case packageurl.TypePyPi:
return string(analyzer.TypePythonPkg)
case packageurl.TypeGolang:
return string(analyzer.TypeGoBinary)
case packageurl.TypeNPM:
return string(analyzer.TypeNodePkg)
case packageurl.TypeCargo:
return string(analyzer.TypeRustBinary)
}
return p.Type
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@knqyf263 knqyf263 added this to the v0.33.0 milestone Oct 11, 2022
@knqyf263 knqyf263 merged commit be78da6 into main Oct 11, 2022
@knqyf263 knqyf263 deleted the fix/purl-nuget branch October 11, 2022 09:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

PURL format for nuget missing type
2 participants