feat(sbom): NuGet licenses from .nuspec files, then nuget.org (#468)

NuGet SBOM entries carried no license: none of the files they come from
names one. Fill it in after the NuGet components are merged (#467):

- local first: the .nuspec of a restored package; <license
  type="expression"> as SPDX, type="file" as LicenseRef-file, an old
  <licenseUrl> mapped to SPDX for well-known license pages, else kept
- then nuget.org: registration leaf (gzip) -> catalogEntry (inline or
  linked on api.nuget.org) -> licenseExpression / licenseFile / licenseUrl
- only real ids at exact versions (no ranges, no DLL-metadata names);
  versions normalised as nuget.org files them (6.2.0.0 -> 6.2.0, 2.0 ->
  2.0.0)
- ids a nuget.config maps to another feed are never sent; a tree whose
  nuget.config lists another feed without a mapping is not looked up
- through guarded_net, 8 at once, 10 s per request, 60 s and 300
  uncached packages per scan; failures stay empty, one warning per scan
- cached across tenants in the admin database (nuget_licenses, TTL: a
  year for a license, a week for none)
- NUGET_LICENSE_LOOKUP=false turns the nuget.org step off

Closes #467

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DmXxNULoSNPvjF7buKipsB
This commit is contained in:
sharangandClaude Opus 5.5 committed 2026-10-05 21:50:32 +00:00
1 parent 04b4f32807
commit b1607fe91b
9 files changed
+1582 -5

No files matched your search

+4
View File
@@ -45,6 +45,10 @@ CVE_MONITOR_SCHEDULE=0 0 0 * * *
# GIT_SOURCE_SYNC_MINUTES=30
# WEBHOOK_PUBLIC_URL=https://pruefwerk-hooks.example.com
GIT_CLONE_BASE_PATH=/tmp/compliance-scanner/repos
# NuGet licenses (#467): look up licenses the tree's .nuspec files do not give
# on api.nuget.org (package id and version only; never for ids a nuget.config
# routes to another feed). Set to false to keep the lookup offline.
NUGET_LICENSE_LOOKUP=true
# Dynamic PLC testing — ephemeral soft-PLC provisioning (#183). Off unless
# enabled; requires the agent container to have Docker access (socket mount).
+9 -1
View File
@@ -44,6 +44,9 @@ pub struct ComplianceAgent {
pub secrets: SecretBox,
/// Managed git sources (#439): allowed hosts, sync interval, webhook origin.
pub git_source: Arc<crate::git_source::Settings>,
/// NuGet licenses looked up on nuget.org, for every tenant (#467): public
/// metadata keyed by package and version, in the admin database.
pub(crate) nuget_license_cache: Arc<crate::pipeline::sbom::MongoLicenseCache>,
}
impl ComplianceAgent {
@@ -69,6 +72,9 @@ impl ComplianceAgent {
tracing::error!("{e}; using the default git source settings");
crate::git_source::Settings::default()
}));
let nuget_license_cache = Arc::new(crate::pipeline::sbom::MongoLicenseCache::new(
&db_pool.admin_db(),
));
Self {
config,
db_pool,
@@ -82,6 +88,7 @@ impl ComplianceAgent {
scan_gate,
secrets,
git_source,
nuget_license_cache,
}
}
@@ -197,7 +204,8 @@ impl ComplianceAgent {
db.clone(),
self.llm.clone(),
self.http.clone(),
);
)
.with_nuget_license_cache(self.nuget_license_cache.clone());
let started = chrono::Utc::now();
orchestrator.run_target(target_id, trigger.clone()).await?;
// Support's scans are ours, not the customer's usage.
+15 -2
View File
@@ -19,7 +19,7 @@ use crate::pipeline::mobsfscan::MobsfscanScanner;
use crate::pipeline::patterns::{GdprPatternScanner, OAuthPatternScanner};
use crate::pipeline::plan::build_scan_plan;
use crate::pipeline::repo_view::RepoView;
use crate::pipeline::sbom::SbomScanner;
use crate::pipeline::sbom::{LicenseCache, NugetRegistry, SbomScanner};
use crate::pipeline::semgrep::SemgrepScanner;
use crate::secrets::SecretBox;
@@ -46,6 +46,8 @@ pub struct PipelineOrchestrator {
pub(super) secrets: SecretBox,
/// Where clones and tracker calls may connect (#256, #294).
pub(super) net_guard: NetGuard,
/// The cross-tenant cache of NuGet licenses (#467).
pub(super) nuget_license_cache: Option<Arc<dyn LicenseCache>>,
}
impl PipelineOrchestrator {
@@ -66,9 +68,16 @@ impl PipelineOrchestrator {
http,
secrets,
net_guard,
nuget_license_cache: None,
}
}
/// Cache the NuGet licenses looked up on nuget.org in `cache` (#467).
pub(crate) fn with_nuget_license_cache(mut self, cache: Arc<dyn LicenseCache>) -> Self {
self.nuget_license_cache = Some(cache);
self
}
#[tracing::instrument(skip_all, fields(repo_id = repo.name.as_str()))]
async fn run_pipeline(
&self,
@@ -287,7 +296,11 @@ impl PipelineOrchestrator {
.await;
let (mut sbom_entries, syft_failure) = async {
let sbom_scanner =
SbomScanner::new(compliance_core::ExecPolicy::from_env(self.config.app_env));
SbomScanner::new(compliance_core::ExecPolicy::from_env(self.config.app_env))
.with_nuget_registry(NugetRegistry::from_env(
self.net_guard,
self.nuget_license_cache.clone(),
));
sbom_scanner.generate(&repo_path, &repo_id).await
}
.instrument(tracing::info_span!("stage_sbom_generation"))
+18 -1
View File
@@ -2,10 +2,12 @@ mod cargo_audit;
mod gradle;
mod mobile;
mod nuget;
mod nuget_license;
pub(crate) use nuget::is_restored_package;
#[cfg(test)]
pub(crate) use nuget::nuget_components;
pub(crate) use nuget_license::{LicenseCache, MongoLicenseCache, NugetRegistry};
mod syft;
pub(crate) mod unity;
@@ -19,11 +21,23 @@ use crate::pipeline::tool_cmd::{run_bounded, tool_in, CARGO_ENV, NPM_ENV};
pub struct SbomScanner {
exec: ExecPolicy,
/// Where NuGet licenses missing from the tree are looked up (#467);
/// `None` reads only the tree's `.nuspec` files.
nuget_registry: Option<NugetRegistry>,
}
impl SbomScanner {
pub fn new(exec: ExecPolicy) -> Self {
Self { exec }
Self {
exec,
nuget_registry: None,
}
}
/// Look up the NuGet licenses the tree does not carry on nuget.org.
pub(crate) fn with_nuget_registry(mut self, registry: Option<NugetRegistry>) -> Self {
self.nuget_registry = registry;
self
}
}
@@ -98,6 +112,9 @@ impl SbomScanner {
// NuGet packages from packages.config, project files and restored
// package folders, which Syft does not read (#445).
nuget::merge_nuget(&mut entries, nuget::nuget_components(repo_path, repo_id));
// Their licenses: from the restored packages' .nuspec, then nuget.org.
nuget_license::enrich_nuget_licenses(repo_path, &mut entries, self.nuget_registry.as_ref())
.await;
// Enrich Cargo entries with license info from cargo metadata
enrich_cargo_licenses(repo_path, &mut entries, self.exec).await;
+1 -1
View File
@@ -136,7 +136,7 @@ pub(crate) fn unresolved_projects(root: &Path) -> Vec<UnlockedEcosystem> {
/// A version NuGet would restore exactly: `1.2.3`, `[1.2.3]`, `1.2.3-beta`.
/// `None` for a floating version or a range (`1.*`, `[1.0,2.0)`).
fn exact_version(raw: &str) -> Option<String> {
pub(super) fn exact_version(raw: &str) -> Option<String> {
let v = raw.trim();
let v = v
.strip_prefix('[')
File diff suppressed because it is too large. Load diff
+13
View File
@@ -32,6 +32,19 @@ Every package with an exact version gets the purl `pkg:nuget/<Id>@<Version>`
and is matched against OSV (ecosystem NuGet). A version range (`7.*`,
`[1.0,2.0)`) is listed without a purl, with the range as its requirement.
**Licenses of NuGet packages.** First from the `.nuspec` of a restored package
(`packages/<Id>.<Version>/`): `<license type="expression">` as an SPDX
expression, `<license type="file">` as `LicenseRef-file`, an older
`<licenseUrl>` as an SPDX id when it points at a well-known license (MIT,
Apache-2.0, BSD, MS-PL, LGPL, …), otherwise as the URL. What is still missing
is looked up on nuget.org (the registration API on `api.nuget.org`, package id
and version only, no packages). Packages a `nuget.config` maps to another
source with `<packageSourceMapping>` are never looked up; when a `nuget.config`
lists another source without a mapping, nothing of that tree is looked up, as
a package id may be an internal one. Answers are cached for all tenants
(public data). `NUGET_LICENSE_LOOKUP=false` turns the lookup off for a
deployment.
**Dependencies not fully resolved.** A project with `<PackageReference>` items
and neither `packages.lock.json` nor `obj/project.assets.json` names only its
direct packages. The scan lists it under **Nicht ausgeführt**
+14
View File
@@ -33,6 +33,20 @@ wird gegen OSV (Ökosystem NuGet) abgeglichen. Ein Versionsbereich (`7.*`,
`[1.0,2.0)`) steht ohne purl in der Stückliste, mit dem Bereich als
Anforderung.
**Lizenzen der NuGet-Pakete.** Zuerst aus der `.nuspec` eines
wiederhergestellten Pakets (`packages/<Id>.<Version>/`): `<license
type="expression">` als SPDX-Ausdruck, `<license type="file">` als
`LicenseRef-file`, eine ältere `<licenseUrl>` als SPDX-Kennung, wenn sie auf
eine bekannte Lizenz zeigt (MIT, Apache-2.0, BSD, MS-PL, LGPL, …), sonst als
URL. Was dort fehlt, wird bei nuget.org nachgeschlagen (Registration-API auf
`api.nuget.org`, nur Paket-Id und Version, keine Pakete). Nicht gefragt wird
nach Paketen, die eine `nuget.config` per `<packageSourceMapping>` einer
anderen Quelle zuordnet; nennt eine `nuget.config` eine andere Quelle ohne
Zuordnung, wird für diesen Baum gar nicht nachgeschlagen, denn eine Paket-Id
kann die eines internen Pakets sein. Die Antworten werden für alle Mandanten
zwischengespeichert (öffentliche Daten). `NUGET_LICENSE_LOOKUP=false` schaltet
die Abfrage für eine Installation ab.
**Unvollständig aufgelöste Abhängigkeiten.** Ein Projekt mit
`<PackageReference>` ohne `packages.lock.json` und ohne
`obj/project.assets.json` nennt nur seine direkten Pakete. Die Prüfung führt
+4
View File
@@ -109,6 +109,10 @@ Prüfwerk matches every SBOM component directly against two public vulnerability
Matches are stored as CVE alerts with CVSS scores and re-checked hourly, so newly published CVEs against an unchanged dependency still raise a notification.
## nuget.org -- NuGet Licenses
Licenses of NuGet packages that no `.nuspec` in the tree gives are read from the [nuget.org registration API](https://learn.microsoft.com/nuget/api/registration-base-url-resource) (`api.nuget.org`). Only the package id and version are sent, never for an id a `nuget.config` routes to another feed (see [.NET projects](/guide/dotnet-en)). The lookup is bounded per scan (8 requests at once, 10 s per request, 60 s and 300 uncached packages in total); answers are cached for all tenants. Set `NUGET_LICENSE_LOOKUP=false` to keep the agent from contacting nuget.org.
## Custom OAuth Scanner
A purpose-built scanner that detects OAuth and OIDC misconfigurations in your code, including: