Closes#467. Fills the license of NuGet SBOM entries, which until now were always empty.
What it does
Local first (no network): the .nuspec of every restored package in the tree (packages/<Id>.<Version>/), read by its own <id>/<version> (templates with $id$ skipped). <license type="expression"> → SPDX, type="file" → LicenseRef-file, <licenseUrl> → SPDX for well-known pages (opensource.org, apache.org, gnu.org GPL/LGPL/AGPL, MS-PL, MPL, licenses.nuget.org/<expr>, …), otherwise kept as the URL.
Then nuget.org: registration5-gz-semver2/<id>/<version>.json (served gzip regardless of Accept-Encoding; decoded with flate2, so the workspace reqwest features are unchanged) → catalogEntry (inline object or link, followed only on https://api.nuget.org/) → licenseExpression / licenseFile / licenseUrl. aka.ms/deprecateLicenseUrl and nuget.org/packages/.../license are read as the file-license markers they are. Response shapes checked with curl against live nuget.org.
Eligibility: pkg:nuget/ purl, exact version, no range, valid NuGet id (so DLL-metadata names with spaces, #460, are skipped), no license yet. Versions normalised as nuget.org files them: 6.2.0.0 → 6.2.0, 2.0 → 2.0.0, leading zeros and +build dropped (each was a 404 otherwise).
Egress of package names
nuget.config / NuGet.Config files anywhere in the tree are read.
With <packageSourceMapping>: an id is sent only if its most specific pattern maps to a nuget.org source (a tie with another feed → not sent).
A config listing a non-nuget.org source (URL or local path) without a mapping → no nuget.org lookup for that tree at all, logged once with the reason. This is the conservative option from the review.
NUGET_LICENSE_LOOKUP=false turns the nuget.org step off (default on). It is read from the environment when the scan runs, like PW_ALLOW_PRIVATE_TARGETS, rather than added to AgentConfig.
Documented in docs/reference/tools.md (next to OSV/NVD), docs/guide/dotnet{,-en}.md, .env.example.
Network and limits
Requests go through a guarded_net::guarded_client_builder client, with NetGuard::check_url before each one, a 10 s per-request and 5 s connect timeout, and a 2 MiB body cap.
At most 8 requests at a time, at most 300 uncached packages per scan (the rest stay empty this time and get filled on a later scan through the cache), and 60 s for the whole lookup (take_until, so answers that came in before the deadline are kept and cached).
Failures leave the license empty, produce one warning per scan (counts + first error), and never fail the stage.
Cache
Mongo collection nuget_licenses in the existing cross-tenant admin database (<prefix>__admin, already used for MCP tokens), _id = <id>@<version>. TTL index on expires_at: 1 year for a license, 7 days for "none" (404 or no license declared). Transport failures are not cached. It is shared across tenants because the data is public and the key contains nothing about the tenant. The handle is created once in ComplianceAgent and passed to the scan orchestrator. The PR-review path does not run the SBOM stage, so it needs no cache.
Deviations from the issue
The issue asked to "allow api.nuget.org the way api.osv.dev is allowed". There is no code-level allowlist for OSV: CveScanner uses the plain, unguarded agent client. This lookup uses the guarded client instead, which is stricter than OSV today. OSV is unchanged.
Negative answers are cached for 7 days (not the long TTL).
Tests
Lib tests next to the code (nuget_license::tests, 18): nuspec expression / file / licenseUrl known + unknown + template; URL→SPDX table; version normalisation; eligibility (DLL names, ranges, no purl, other ecosystems); registration leaf with linked (gzip) and inline catalogEntry, off-host link refused; nuspec beats nuget.org; nuget.org fills + caches; cache hit → no request; network failure → empty and not cached; 404 → cached as none; per-scan cap and time budget; nuget.config policy (no config / private without mapping / nuget.org only / mapping with * vs Prefix.* vs exact); env switch; gzip decode.
#[ignore]d, run locally: live nuget.org through the guarded client (Newtonsoft.Json → MIT, DotNetZip → URL, EntityFramework 6.2.0.0 resolved); Mongo cache round trip (upsert, none, miss) against a local Mongo.
Closes #467. Fills the license of NuGet SBOM entries, which until now were always empty.
## What it does
- **Local first** (no network): the `.nuspec` of every restored package in the tree (`packages/<Id>.<Version>/`), read by its own `<id>`/`<version>` (templates with `$id$` skipped). `<license type="expression">` → SPDX, `type="file"` → `LicenseRef-file`, `<licenseUrl>` → SPDX for well-known pages (opensource.org, apache.org, gnu.org GPL/LGPL/AGPL, MS-PL, MPL, `licenses.nuget.org/<expr>`, …), otherwise kept as the URL.
- **Then nuget.org**: `registration5-gz-semver2/<id>/<version>.json` (served gzip regardless of Accept-Encoding; decoded with flate2, so the workspace reqwest features are unchanged) → `catalogEntry` (inline object or link, followed only on `https://api.nuget.org/`) → `licenseExpression` / `licenseFile` / `licenseUrl`. `aka.ms/deprecateLicenseUrl` and `nuget.org/packages/.../license` are read as the file-license markers they are. Response shapes checked with curl against live nuget.org.
- **Eligibility**: `pkg:nuget/` purl, exact version, no range, valid NuGet id (so DLL-metadata names with spaces, #460, are skipped), no license yet. Versions normalised as nuget.org files them: `6.2.0.0` → `6.2.0`, `2.0` → `2.0.0`, leading zeros and `+build` dropped (each was a 404 otherwise).
## Egress of package names
- `nuget.config` / `NuGet.Config` files anywhere in the tree are read.
- With `<packageSourceMapping>`: an id is sent only if its most specific pattern maps to a nuget.org source (a tie with another feed → not sent).
- A config listing a non-nuget.org source (URL or local path) **without** a mapping → no nuget.org lookup for that tree at all, logged once with the reason. This is the conservative option from the review.
- `NUGET_LICENSE_LOOKUP=false` turns the nuget.org step off (default on). It is read from the environment when the scan runs, like `PW_ALLOW_PRIVATE_TARGETS`, rather than added to `AgentConfig`.
- Documented in `docs/reference/tools.md` (next to OSV/NVD), `docs/guide/dotnet{,-en}.md`, `.env.example`.
## Network and limits
- Requests go through a `guarded_net::guarded_client_builder` client, with `NetGuard::check_url` before each one, a 10 s per-request and 5 s connect timeout, and a 2 MiB body cap.
- At most 8 requests at a time, at most 300 uncached packages per scan (the rest stay empty this time and get filled on a later scan through the cache), and 60 s for the whole lookup (`take_until`, so answers that came in before the deadline are kept and cached).
- Failures leave the license empty, produce **one** warning per scan (counts + first error), and never fail the stage.
## Cache
Mongo collection `nuget_licenses` in the existing cross-tenant admin database (`<prefix>__admin`, already used for MCP tokens), `_id = <id>@<version>`. TTL index on `expires_at`: 1 year for a license, 7 days for "none" (404 or no license declared). Transport failures are not cached. It is shared across tenants because the data is public and the key contains nothing about the tenant. The handle is created once in `ComplianceAgent` and passed to the scan orchestrator. The PR-review path does not run the SBOM stage, so it needs no cache.
## Deviations from the issue
- The issue asked to "allow api.nuget.org the way api.osv.dev is allowed". There is no code-level allowlist for OSV: `CveScanner` uses the plain, unguarded agent client. This lookup uses the guarded client instead, which is stricter than OSV today. OSV is unchanged.
- Negative answers are cached for 7 days (not the long TTL).
## Tests
- Lib tests next to the code (`nuget_license::tests`, 18): nuspec expression / file / licenseUrl known + unknown + template; URL→SPDX table; version normalisation; eligibility (DLL names, ranges, no purl, other ecosystems); registration leaf with linked (gzip) and inline catalogEntry, off-host link refused; nuspec beats nuget.org; nuget.org fills + caches; cache hit → no request; network failure → empty and not cached; 404 → cached as none; per-scan cap and time budget; nuget.config policy (no config / private without mapping / nuget.org only / mapping with `*` vs `Prefix.*` vs exact); env switch; gzip decode.
- `#[ignore]`d, run locally: live nuget.org through the guarded client (Newtonsoft.Json → MIT, DotNetZip → URL, EntityFramework `6.2.0.0` resolved); Mongo cache round trip (upsert, none, miss) against a local Mongo.
- `cargo fmt --check`, `cargo clippy -p compliance-agent --all-targets -D warnings`, `cargo test -p compliance-agent --lib` (618 passed).
Follow-ups from the issue (npm, Maven/Gradle licenses) are not part of this PR.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_01DmXxNULoSNPvjF7buKipsB
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
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Closes #467. Fills the license of NuGet SBOM entries, which until now were always empty.
What it does
.nuspecof every restored package in the tree (packages/<Id>.<Version>/), read by its own<id>/<version>(templates with$id$skipped).<license type="expression">→ SPDX,type="file"→LicenseRef-file,<licenseUrl>→ SPDX for well-known pages (opensource.org, apache.org, gnu.org GPL/LGPL/AGPL, MS-PL, MPL,licenses.nuget.org/<expr>, …), otherwise kept as the URL.registration5-gz-semver2/<id>/<version>.json(served gzip regardless of Accept-Encoding; decoded with flate2, so the workspace reqwest features are unchanged) →catalogEntry(inline object or link, followed only onhttps://api.nuget.org/) →licenseExpression/licenseFile/licenseUrl.aka.ms/deprecateLicenseUrlandnuget.org/packages/.../licenseare read as the file-license markers they are. Response shapes checked with curl against live nuget.org.pkg:nuget/purl, exact version, no range, valid NuGet id (so DLL-metadata names with spaces, #460, are skipped), no license yet. Versions normalised as nuget.org files them:6.2.0.0→6.2.0,2.0→2.0.0, leading zeros and+builddropped (each was a 404 otherwise).Egress of package names
nuget.config/NuGet.Configfiles anywhere in the tree are read.<packageSourceMapping>: an id is sent only if its most specific pattern maps to a nuget.org source (a tie with another feed → not sent).NUGET_LICENSE_LOOKUP=falseturns the nuget.org step off (default on). It is read from the environment when the scan runs, likePW_ALLOW_PRIVATE_TARGETS, rather than added toAgentConfig.docs/reference/tools.md(next to OSV/NVD),docs/guide/dotnet{,-en}.md,.env.example.Network and limits
guarded_net::guarded_client_builderclient, withNetGuard::check_urlbefore each one, a 10 s per-request and 5 s connect timeout, and a 2 MiB body cap.take_until, so answers that came in before the deadline are kept and cached).Cache
Mongo collection
nuget_licensesin the existing cross-tenant admin database (<prefix>__admin, already used for MCP tokens),_id = <id>@<version>. TTL index onexpires_at: 1 year for a license, 7 days for "none" (404 or no license declared). Transport failures are not cached. It is shared across tenants because the data is public and the key contains nothing about the tenant. The handle is created once inComplianceAgentand passed to the scan orchestrator. The PR-review path does not run the SBOM stage, so it needs no cache.Deviations from the issue
CveScanneruses the plain, unguarded agent client. This lookup uses the guarded client instead, which is stricter than OSV today. OSV is unchanged.Tests
nuget_license::tests, 18): nuspec expression / file / licenseUrl known + unknown + template; URL→SPDX table; version normalisation; eligibility (DLL names, ranges, no purl, other ecosystems); registration leaf with linked (gzip) and inline catalogEntry, off-host link refused; nuspec beats nuget.org; nuget.org fills + caches; cache hit → no request; network failure → empty and not cached; 404 → cached as none; per-scan cap and time budget; nuget.config policy (no config / private without mapping / nuget.org only / mapping with*vsPrefix.*vs exact); env switch; gzip decode.#[ignore]d, run locally: live nuget.org through the guarded client (Newtonsoft.Json → MIT, DotNetZip → URL, EntityFramework6.2.0.0resolved); Mongo cache round trip (upsert, none, miss) against a local Mongo.cargo fmt --check,cargo clippy -p compliance-agent --all-targets -D warnings,cargo test -p compliance-agent --lib(618 passed).Follow-ups from the issue (npm, Maven/Gradle licenses) are not part of this PR.
🤖 Generated with Claude Code
https://claude.ai/code/session_01DmXxNULoSNPvjF7buKipsB