Loading
feat(df): add nuget proxy matcher
Adds NuGetMatcher, the proxy classifier for the NuGet ecosystem. Nothing on main uses it yet; the glab df nuget command follows in a separate MR.
- Downloads: v3 flatcontainer URLs (
…/{id}/{version}/{id}.{version}.nupkg). A.nupkgdownload outside that shape, such as a nuget.org v2 CDN URL, fails closed. Coordinates carry the id and version as the URL spells them; NuGet clients lowercase flatcontainer paths. - Pushes: recognized by body rather than path, because each server advertises its own push URL. A multipart PUT counts as a push when one of its parts is a zip archive (
.nupkgor.snupkg). The coordinate comes from the manifest NuGet would use: the single root-level.nuspec, with exactly one<metadata>,<id>and<version>, read with a 1 MiB cap. Packages larger than the in-memory inspection window are read from the spilled body. A package without a usable manifest, or a push carrying two packages, fails closed. Multipart PUTs with no zip part are forwarded. Push coordinates keep the casing in the package's nuspec. - Not covered: v2 downloads (
…/package/{id}/{version}) and non-multipart PUTs are forwarded uninspected, since neither has a shape the matcher can tell apart from other traffic. nuget.org's v2 feed redirects downloads to a.nupkgCDN URL, which fails closed. NuGet clients always pushmultipart/form-data. - Blocked NuGet requests get a JSON 403 body (
block.go).
Known gap: the policy backend matches NuGet names case-sensitively, while most stored NuGet names are mixed case, so lowercase download coordinates can miss advisories and licenses. That needs a backend change: gitlab#633750.
Testing
End to end with real dotnet (SDK 8.0.425, Linux arm64) through a scratch build of this branch with the nuget command wiring from feat/dependency-firewall. Downloads came from nuget.org, pushes went to a local HTTPS BaGetter feed, and verdicts came from the fake policy checker.
| Scenario | Result |
|---|---|
dotnet restore Newtonsoft.Json 13.0.3 |
restored; checked newtonsoft.json@13.0.3 |
| same, with it blocked | restore fails with 403 |
| restore Serilog.Sinks.Console 5.0.1 | package and dependency serilog@3.1.1 checked |
dotnet nuget push Demo.Pkg 1.0.0 |
pushed; checked Demo.Pkg@1.0.0 |
| push Demo.Pkg 1.0.1 while blocked | 403; not stored |
push with .snupkg; the .snupkg alone while blocked |
both pushed; symbols push alone gets 403 |
| push an 84 MB package (past the 64 MiB window) | checked and stored |
| multipart PUT of a test report | forwarded |
multipart PUT of a zip with no .nuspec |
403, unparseable |
decoy package (nested Benign nuspec before root Evil), Evil blocked |
403, checked as Evil@1.0.0 |
| same decoy through the matcher before 01d2605c | pushed; the feed stored it as Evil |
Edited by Arpit Gogia