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

Incorrect and duplicate versions detected of a component in the same project file when using central package management (NuGet) #970

Open
Sebazzz opened this issue Jan 15, 2024 · 2 comments
Assignees
Labels
detector:nuget The NuGet detector status:waiting-on-response Waiting on a response/more information from the user type:bug Bug fix of existing functionality

Comments

@Sebazzz
Copy link

Sebazzz commented Jan 15, 2024

I'm using Central Package Management to manage my NuGet versions centrally, and also pin subdependencies to higher versions, for instance to mitigate vulnerable transitive dependencies.

I pinned System.IdentityModel.Tokens.Jwt because it had a vulnerability, which is used by Microsoft.IdentityModel.Protocols.OpenIdConnect, which is used by Microsoft.Data.SqlClient, which is used by Microsoft.EntityFrameworkCore.SqlServer which I directly reference.

<?xml version="1.0" encoding="utf-8"?>
<Project>
  <!-- Central registry of all packages used in the project -->
  <!-- See: https://devblogs.microsoft.com/nuget/introducing-central-package-management/ -->
  <PropertyGroup>
    <ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
    <CentralPackageTransitivePinningEnabled>true</CentralPackageTransitivePinningEnabled>
  </PropertyGroup>
  <ItemGroup>
    <PackageVersion Include="Microsoft.Data.SqlClient" Version="5.1.4" />
    <PackageVersion Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.0" />
    <PackageVersion Include="Microsoft.IdentityModel.JsonWebTokens" Version="7.2.0" />
    <PackageVersion Include="System.IdentityModel.Tokens.Jwt" Version="7.2.0" />
  </ItemGroup>
</Project>
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.Data.SqlClient" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" />
  </ItemGroup>
</Project>

I'm using the sbom-tool to generate my SBOM, and the scan manifest shows:

 {
      "locationsFoundAt": [
        "/src/MyProject.Persistence/MyProject.Persistence.csproj"
      ],
      "component": {
        "name": "System.IdentityModel.Tokens.Jwt",
        "version": "6.24.0",
        "authors": null,
        "type": "NuGet",
        "id": "System.IdentityModel.Tokens.Jwt 6.24.0 - NuGet",
        "packageUrl": {
          "Scheme": "pkg",
          "Type": "nuget",
          "Namespace": null,
          "Name": "System.IdentityModel.Tokens.Jwt",
          "Version": "6.24.0",
          "Qualifiers": null,
          "Subpath": null
        }
      },
      "detectorId": "NuGetProjectCentric",
      "isDevelopmentDependency": null,
      "dependencyScope": null,
      "topLevelReferrers": [
        {
          "name": "Microsoft.Data.SqlClient",
          "version": "5.1.4",
          "authors": null,
          "type": "NuGet",
          "id": "Microsoft.Data.SqlClient 5.1.4 - NuGet",
          "packageUrl": {
            "Scheme": "pkg",
            "Type": "nuget",
            "Namespace": null,
            "Name": "Microsoft.Data.SqlClient",
            "Version": "5.1.4",
            "Qualifiers": null,
            "Subpath": null
          }
        },
        {
          "name": "Microsoft.EntityFrameworkCore.SqlServer",
          "version": "8.0.0",
          "authors": null,
          "type": "NuGet",
          "id": "Microsoft.EntityFrameworkCore.SqlServer 8.0.0 - NuGet",
          "packageUrl": {
            "Scheme": "pkg",
            "Type": "nuget",
            "Namespace": null,
            "Name": "Microsoft.EntityFrameworkCore.SqlServer",
            "Version": "8.0.0",
            "Qualifiers": null,
            "Subpath": null
          }
        }
      ],
      "containerDetailIds": [],
      "containerLayerIds": {}
    },

Interestingly, in a different project in the same solution the dependency version is correctly detected, but the project mentioned above also shows up here:

 {
      "locationsFoundAt": [
        "/src/MyProject.Web/MyProject.Web.csproj",
        "/tests/MyProject.Tests.Integration/MyProject.Tests.Integration.csproj",
        "/src/MyProject.Persistence/MyProject.Persistence.csproj"
      ],
      "component": {
        "name": "System.IdentityModel.Tokens.Jwt",
        "version": "7.2.0",
        "authors": null,
        "type": "NuGet",
        "id": "System.IdentityModel.Tokens.Jwt 7.2.0 - NuGet",
        "packageUrl": {
          "Scheme": "pkg",
          "Type": "nuget",
          "Namespace": null,
          "Name": "System.IdentityModel.Tokens.Jwt",
          "Version": "7.2.0",
          "Qualifiers": null,
          "Subpath": null
        }
      }
}

AB#2139506

@Sebazzz Sebazzz changed the title Incorrect and duplicate versions detected of a component in the same project file when usign central package management (NuGet) Incorrect and duplicate versions detected of a component in the same project file when using central package management (NuGet) Jan 15, 2024
@cobya cobya added type:bug Bug fix of existing functionality detector:nuget The NuGet detector labels Jan 17, 2024
@jcfiorenzano jcfiorenzano self-assigned this Feb 26, 2024
@swells
Copy link
Member

swells commented Feb 27, 2024

We have the same issue. Does component gov not support central package management (NuGet)?

@jcfiorenzano
Copy link
Contributor

Hello @Sebazzz

I am not able to reproduce the issue. I tried your configuration using the latest version of component detection v4.2.1 and the right components are detected. I also tried running the latest version of the sbom-tool v2.2.3 and also the correct components were reported.
These are the files that I used:

csproj

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net8.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>


  <ItemGroup>
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer"/>
    <PackageReference Include="Microsoft.Data.SqlClient" />
    <PackageReference Include="Newtonsoft.Json" />
  </ItemGroup>

</Project>

Directory.Packages.Props

<?xml version="1.0" encoding="utf-8"?>
<Project>
  <!-- Central registry of all packages used in the project -->
  <!-- See: https://devblogs.microsoft.com/nuget/introducing-central-package-management/ -->
  <PropertyGroup>
    <ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
    <CentralPackageTransitivePinningEnabled>true</CentralPackageTransitivePinningEnabled>
  </PropertyGroup>

  <ItemGroup>
    <PackageVersion Include="Microsoft.Data.SqlClient" Version="5.1.4" />
    <PackageVersion Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.0" />
    <PackageVersion Include="Microsoft.IdentityModel.JsonWebTokens" Version="7.2.0" />
    <PackageVersion Include="System.IdentityModel.Tokens.Jwt" Version="7.2.0" />
    <PackageVersion Include="Newtonsoft.Json" Version="12.0.3" />
  </ItemGroup>
</Project>

This is the manifest generated by sbom

manifest.spdx.json

Image

@cobya cobya added the status:waiting-on-response Waiting on a response/more information from the user label May 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
detector:nuget The NuGet detector status:waiting-on-response Waiting on a response/more information from the user type:bug Bug fix of existing functionality
Projects
Development

No branches or pull requests

4 participants