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

feat(dotnet): add license support for NuGet #5217

Merged
merged 7 commits into from
Sep 28, 2023

Conversation

DmitriyLewen
Copy link
Contributor

Description

packages.config and packages.lock.json files don't have information about the licenses used.

Add support of *.nuspec files from global packages folder.

notes:

  • Currently only the default path and NUGET_PACKAGES environment variable are supported.
  • licenseUrl is not supported, because this field has been deprecated.
  • license expression only supports

Example:

➜  ./trivy fs -f json --list-all-pkgs ./packages.lock.json 
2023-09-20T13:50:05.734+0600	INFO	Number of language-specific files: 1
2023-09-20T13:50:05.734+0600	INFO	Detecting nuget vulnerabilities...
2023-09-20T13:50:05.734+0600	DEBUG	Detecting library vulnerabilities, type: nuget, path: packages.lock.json
{
  ...
  "Results": [
    {
      "Target": "packages.lock.json",
      "Class": "lang-pkgs",
      "Type": "nuget",
      "Packages": [
        {
          "ID": "[email protected]",
          "Name": "Newtonsoft.Json",
          "Version": "13.0.3",
          "Licenses": [
            "MIT"
          ],
          "Layer": {},
          "Locations": [
            {
              "StartLine": 5,
              "EndLine": 10
            }
          ]
        }
      ]
    }
  ]
}

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 self-assigned this Sep 20, 2023
@DmitriyLewen DmitriyLewen marked this pull request as ready for review September 21, 2023 03:09
Copy link
Collaborator

@knqyf263 knqyf263 left a comment

Choose a reason for hiding this comment

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

Looks very nice! I left small comments.

Comment on lines 78 to 82
if license := pkg.Metadata.License; license.Type == "expression" && license.Text != "" {
return []string{license.Text}, nil
}

return nil, nil
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: I prefer the happy path getting aligned to the left edge.
https://medium.com/@matryer/line-of-sight-in-code-186dd7cdea88

Suggested change
if license := pkg.Metadata.License; license.Type == "expression" && license.Text != "" {
return []string{license.Text}, nil
}
return nil, nil
if license := pkg.Metadata.License; license.Type != "expression" || license.Text == "" {
return nil, nil
}
return []string{pkg.Metadata.License}, nil

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed in 1d0fed1

Comment on lines 78 to 82
if err != nil {
if !errors.Is(err, fs.ErrNotExist) {
return xerrors.Errorf("license find error: %w", err)
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: We might want to aggregate the statements.

Suggested change
if err != nil {
if !errors.Is(err, fs.ErrNotExist) {
return xerrors.Errorf("license find error: %w", err)
}
}
if err != nil && !errors.Is(err, fs.ErrNotExist) {
return xerrors.Errorf("license find error: %w", err)
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right! Thanks! Updated in 1d0fed1.

@knqyf263 knqyf263 enabled auto-merge September 27, 2023 10:32
@DmitriyLewen
Copy link
Contributor Author

@knqyf263 looks like this PR has not been added to merge queue.
Can you check?

@knqyf263 knqyf263 added this pull request to the merge queue Sep 28, 2023
@knqyf263
Copy link
Collaborator

knqyf263 commented Sep 28, 2023

CLA assistant didn't work. I opened the following link to trigger it.
https://cla-assistant.io/check/aquasecurity/trivy?pullRequest=5217

Merged via the queue into aquasecurity:main with commit 3dd5b1e Sep 28, 2023
16 checks passed
@DmitriyLewen DmitriyLewen deleted the feat/nuget-licenses branch September 28, 2023 08:57
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.

feat(NuGet): add license support
2 participants