Automation for updating, validating, and publishing npm and NuGet packages after a CVE is detected in a security audit stage.
pipelines/cve-package-update.yml- Azure DevOps pipeline entry point.scripts/Invoke-CveNpmUpdate.ps1- npm/yarn CVE update, signature validation, and feed publish orchestration.scripts/Publish-NpmFeed.ps1- npm publish helper for TFS/Azure DevOps feeds.scripts/Invoke-CveNuGetUpdate.ps1- NuGet package download/update, signature validation, and feed publish orchestration.scripts/Publish-NuGetFeed.ps1- NuGet publish helper for TFS/Azure DevOps feeds.
Create secret pipeline variables for feed publishing:
NPM_PUBLISH_PATNUGET_PUBLISH_PAT
Run pipelines/cve-package-update.yml after the security audit detects a CVE. The audit stage can trigger this pipeline manually, through the Azure DevOps REST API, or by using it as a downstream template/stage.
Important pipeline parameters:
ecosystem:npm,nuget, orboth.cveId: CVE identifier for logging and traceability.packageName: package to update when running targeted mode.packageVersion: patched version for targeted mode. If omitted for targeted NuGet, the latest stable public version is fetched.productionReady: passesPromoteToRelease=trueto publish scripts.publishToLive: publishes to the live feed after test feed publishing.npmPackageJsonPath: path topackage.jsonwhen running npm manifest mode.npmYarnLockPath: optional path toyarn.lockfor npm manifest validation.nugetPackageConfigPath: path topackages.configor.csprojwhen running NuGet manifest mode.- Feed URL parameters for TFS Test and TFS Live npm/NuGet feeds.
The pipeline and scripts accept either targeted package input or manifest input.
Targeted mode:
- npm: provide
packageNameandpackageVersion. - NuGet: provide
packageNameand optionallypackageVersion; the latest stable public NuGet version is used whenpackageVersionis empty.
Manifest mode:
- npm: provide
npmPackageJsonPath. The script readsdependencies,devDependencies,optionalDependencies, andpeerDependencies, installs them, validates npm signatures, creates package tarballs withnpm pack, and publishes those tarballs. - NuGet: provide
nugetPackageConfigPath. The script reads every package frompackages.configor everyPackageReferencefrom.csproj, downloads each package, validates signatures, and publishes each.nupkg.
Invoke-CveNpmUpdate.ps1 performs these steps:
- Clears
C:\Temp\npmpublishandC:\Temp\yarncacheby default. - Uses either a targeted package/version or copies
package.jsonand optionalyarn.lockinto the npm staging directory. - Writes
.npmrcfor the public npm registry. - Runs
yarn add package@versionfor targeted mode, oryarn installfor manifest mode. When a lockfile is supplied, the install uses--frozen-lockfile. - Removes read-only attributes under the Yarn cache and grants permissions on the
v6cache folder when present. - Runs
npm audit signatures. - Runs
npm packfor the selected package or manifest packages. - Publishes package tarballs to the TFS Test feed and optionally the TFS Live feed.
- Runs a feed lookup after publish and writes logs to the Azure Pipelines artifact staging directory.
Targeted example:
pwsh scripts/Invoke-CveNpmUpdate.ps1 `
-PackageName lodash `
-PackageVersion 4.17.21 `
-CveId CVE-2021-23337 `
-TestFeedRegistryUrl "https://pkgs.dev.azure.com/org/project/_packaging/test/npm/registry/" `
-LiveFeedRegistryUrl "https://pkgs.dev.azure.com/org/project/_packaging/live/npm/registry/" `
-PromoteToRelease `
-PublishToLiveManifest example:
pwsh scripts/Invoke-CveNpmUpdate.ps1 `
-PackageJsonPath .\package.json `
-YarnLockPath .\yarn.lock `
-CveId CVE-2021-23337 `
-TestFeedRegistryUrl "https://pkgs.dev.azure.com/org/project/_packaging/test/npm/registry/" `
-LiveFeedRegistryUrl "https://pkgs.dev.azure.com/org/project/_packaging/live/npm/registry/" `
-PromoteToRelease `
-PublishToLiveInvoke-CveNuGetUpdate.ps1 performs these steps:
- Accepts targeted package input,
packages.configfor .NET Framework apps, or.csprojfiles for SDK-style apps. - Fetches the latest stable version from NuGet.org when targeted
-PackageVersionis not provided. - Downloads the package into
C:\Temp\DownloadNuGetPackagesby default. - Runs
nuget verify -Signatures. - Publishes to the TFS Test feed and optionally the TFS Live feed.
- Runs a feed lookup after publish and writes logs to the Azure Pipelines artifact staging directory.
Targeted example:
pwsh scripts/Invoke-CveNuGetUpdate.ps1 `
-PackageName Newtonsoft.Json `
-PackageVersion 13.0.3 `
-TargetFramework net481 `
-TestFeedSourceUrl "https://pkgs.dev.azure.com/org/project/_packaging/test/nuget/v3/index.json" `
-LiveFeedSourceUrl "https://pkgs.dev.azure.com/org/project/_packaging/live/nuget/v3/index.json" `
-PromoteToRelease `
-PublishToLiveManifest example:
pwsh scripts/Invoke-CveNuGetUpdate.ps1 `
-PackageConfigPath .\packages.config `
-TargetFramework net481 `
-TestFeedSourceUrl "https://pkgs.dev.azure.com/org/project/_packaging/test/nuget/v3/index.json" `
-LiveFeedSourceUrl "https://pkgs.dev.azure.com/org/project/_packaging/live/nuget/v3/index.json" `
-PromoteToRelease `
-PublishToLive- Store PATs as secret pipeline variables only. Do not commit them to the repository.
- The scripts map PATs through
NPM_PUBLISH_TOKENandNUGET_PUBLISH_TOKEN. - Package authenticity is checked with
npm audit signaturesandnuget verify -Signaturesbefore publishing. - Live publishing is opt-in through
publishToLive.