Skip to content
Notifications
Clear all

Walkthrough: How we got Checkmarx to play nice with our NuGet packages

1 Posts
1 Users
0 Reactions
0 Views
(@emilyk22)
Estimable Member
Joined: 1 week ago
Posts: 100
Topic starter   [#16179]

After a lengthy and somewhat frustrating evaluation period, our development security team successfully integrated Checkmarx CxSAST into our primary .NET CI/CD pipeline. The most significant technical hurdle we encountered was not with the core source code scanning itself, but with its interaction with our internally hosted NuGet package repository and the subsequent management of third-party dependencies. This post details our configuration journey, the specific roadblocks we hit with package restoration during scans, and the practical solutions we implemented to achieve a reliable, low-friction workflow.

Our initial, naive approach was to rely on the standard `nuget restore` executed within the Checkmarx scan step. This consistently failed for two interconnected reasons:

* **Authentication to our private NuGet feed:** The Checkmarx scan engine, operating within its own context, did not have access to the NuGet configuration or credentials present on the build agent. This led to persistent 401 errors for internal packages.
* **Incomplete dependency resolution:** Even when we bypassed internal packages, we observed that the Checkmarx engine's internal resolution mechanism for public packages sometimes differed from the results of a standard `dotnet restore`, leading to inconsistent scan results and "missing dependency" warnings in the Checkmarx project.

To resolve these issues, we moved away from relying on Checkmarx for package management entirely. Our solution was to pre-stage all dependencies in the scan directory *before* initiating the CxSAST scan. The process we now follow in our pipeline is as follows:

1. **Standard Restore:** Execute a full `dotnet restore` using the pipeline's authenticated agent, which has full access to both public and private feeds. This populates the local `packages` folder and generates the correct `project.assets.json` files.
2. **Directory Preparation:** We configure the Checkmarx scan to target the source directory, but we now ensure the `packages` folder and the `obj` folders (containing the assets files) are present and intact. We explicitly exclude the `packages` folder from the scan itself via the Checkmarx `CxSkipFolders` parameter to avoid unnecessary noise.
3. **Engine Configuration:** The critical step was to explicitly instruct the Checkmarx engine to *use* the already restored packages, not to try and fetch them. This was achieved by passing the following key parameter in our CxScan command: `-LocationPath %CX_LOCAL_PATH% -v -Preset "Checkmarx Default" -ProjectName "%CX_PROJECT_NAME%" -CxSkipFolders "packages" -DisableNugetRestore`. The `-DisableNugetRestore` flag was the final piece that stabilized the process.

The `-DisableNugetRestore` flag forces the Checkmarx engine to analyze the project structure as-is, leveraging the dependencies already resolved and physically present on disk. This eliminated all authentication issues and ensured the dependency tree analyzed by Checkmarx was identical to the one our build uses, thereby improving the accuracy of vulnerability tracking for third-party libraries.

From an operational standpoint, this approach added a minor but acceptable overhead: the necessity of a full restore prior to the scan. However, this was already occurring in our build stage, so we optimized by reusing the same agent workspace. The trade-off for consistent, reliable scans was well worth it. For teams considering a similar integration, I recommend evaluating your dependency restoration process early in the Checkmarx proof-of-concept. The default behavior may not be sufficient for enterprise environments with complex, multi-feed NuGet configurations.


Support is a product, not a department.


   
Quote