Securing the .NET software supply chain: the attack paths (typosquatting, dependency confusion, compromised maintainers, poisoned builds), NuGet source mapping, lock files, signing and trusted signers, an internal feed, pinned actions, SBOMs and build provenance, mapped to SLSA and Australian expectations.
Supply chain security protects everything that goes into your build, not just your own code. The attacks: typosquatting (Newtonsof.Json), dependency confusion (a public package with your internal name), compromised maintainers or packages, and compromised build systems or CI actions. NuGet packages are dangerous because their MSBuild targets and analysers run code during build. My controls: package source mapping so each package id comes only from its intended feed, lock files with --locked-mode, signature validation with trusted signers where it fits, an internal feed with upstreams as a single entry point, and NuGetAudit for known vulnerabilities. For what we ship: an SBOM for every build and signed provenance attestations proving which commit and pipeline produced the artefact, aiming at SLSA build levels. Trade-off: every control adds friction to adding a dependency, which is partly the point.
"Most of the code we ship isn't ours: a typical ASP.NET Core service pulls in hundreds of transitive packages, plus base images, GitHub Actions and build tools. Supply chain attacks target that. Typosquatting relies on someone typing a near-miss name. Dependency confusion relies on NuGet picking a public package with the same name as our internal one. Compromised maintainers - think event-stream in npm or the xz-utils backdoor - put malicious code in a real, trusted package. And NuGet has a specific sharp edge: a package can include
build/*.targetsfiles and analysers that execute during restore and build, on the CI agent that holds our deployment credentials.For example, at [company] we [had an internal package prefix that wasn't reserved on nuget.org]. I [led] the hardening: a committed
nuget.configwith<clear/>, our Azure Artifacts feed with nuget.org as an upstream, package source mapping soContoso.*could only come from our feed, lock files with locked mode in CI, and we reserved our prefix on nuget.org. On the output side we generated an SBOM with Microsoft's sbom-tool in every build and added GitHub artifact attestations to container images. [When the next big CVE landed, we answered 'are we affected?' across 40 services in minutes by querying SBOMs instead of days.]The mistake I see is equating supply chain security with 'run Dependabot'. Vulnerability scanning catches known vulnerabilities in honest packages; it does nothing about a malicious package that has no CVE yet. The framework I use to explain maturity is SLSA: source integrity, a hosted, hardened build, and signed provenance that a deploy step can verify. The senior view is that you can't review every line of every dependency, so you control where code comes from, pin what you got, and prove what you shipped."
| Attack | How it works | Control |
|---|---|---|
| Typosquatting | Malicious Microsft.Extensions.Http on nuget.org |
Review new dependencies, reserved prefixes, prefer packages with verified owners, internal feed curation |
| Dependency confusion | Public Contoso.Billing 99.0.0 beats internal 1.4.0 |
Package source mapping, reserved ID prefixes, single internal feed with upstreams |
| Compromised package / maintainer | Real package gets malicious version | Lock files, delayed adoption of new versions, review diffs of build-time assets, provenance where available |
| Malicious build-time code | build/*.targets, analysers, source generators run in your build |
Restrict sources, least-privilege CI with no long-lived secrets, isolated build agents |
| Compromised CI action | Tag of a third-party action moved to malicious commit | Pin actions to full commit SHA, minimal permissions: |
| Tampered artefact | Image replaced in registry between build and deploy | Signed images and attestations verified at deploy (admission policy) |
| Level | Requirement | In practice |
|---|---|---|
| Build L1 | Provenance exists | Pipeline emits build metadata |
| Build L2 | Hosted build platform, signed provenance | GitHub-hosted runners + artifact attestations |
| Build L3 | Hardened build, provenance unforgeable by tenant | Isolated, ephemeral builds; signing keys out of reach of build steps |
After hardening [40] services, a later audit found that [3] repos still restored directly from nuget.org without mapping; a pipeline check that fails when nuget.config lacks packageSourceMapping closed the gap. When [a widely used logging package CVE] was published, SBOM queries identified [6] affected services within [20 minutes], and all were patched the same day.
Checks whether the candidate understands supply chain attacks beyond known CVEs and can apply concrete .NET and CI controls.
Green flags
Red flags
developer --commit--> source repo --trigger--> CI build ----> artefact ----> deploy
^ ^ ^ ^ ^
IDE extensions, branch protection, packages, actions, registry, admission
local tools signed commits base images, storage policy verifies
build scripts signature +
provenance
Each arrow is an attack point. SLSA organises controls by source, build and dependencies.
Without source mapping, NuGet queries every configured source for a package id, and the resolution depends on versions found and which source responds. If an internal package Contoso.Billing exists and an attacker publishes Contoso.Billing 99.0.0 publicly, a floating range or an unpinned new restore can pick the public one. Source mapping (<packageSourceMapping>) makes each id pattern resolve from exactly one source; the most specific pattern wins.
| Asset | When it runs |
|---|---|
build/<id>.props / .targets |
Imported into MSBuild for every consuming project - can run tasks and Exec |
buildTransitive/ |
Same, for transitive consumers |
| Analysers and source generators | Run inside the compiler (Roslyn) during build and in the IDE |
tools/ (legacy install.ps1) |
Ignored by PackageReference projects |
That's why a malicious package can steal environment variables on a CI agent without your app ever calling it.
nuget.config <trustedSigners> with signatureValidationMode=require makes restore reject packages not signed by listed authors or repositories, and can restrict nuget.org packages to specific owners. Powerful but high maintenance; suits regulated environments.RestorePackagesWithLockFile=true writes packages.lock.json with exact resolved versions and content hashes.--locked-mode in CI fails on any drift, so dependency changes only happen through reviewed commits.uses: actions/checkout@<sha>), and container base images by digest (mcr.microsoft.com/dotnet/aspnet:10.0@sha256:...), with Dependabot or Renovate opening PRs to bump them.A software bill of materials lists every component (name, version, licence, hash, supplier) in an artefact.
sbom-tool (SPDX), the CycloneDX .NET tool, Syft for container images.Provenance is signed metadata: which source commit, which workflow, which builder, which inputs produced an artefact. GitHub's actions/attest-build-provenance produces SLSA provenance signed via Sigstore; gh attestation verify checks it. Container registries can store signatures and attestations (Notation / Cosign), and admission controllers (Ratify with Azure Policy on AKS, Kyverno) can reject unsigned images at deploy.
The ACSC publishes guidance on cyber supply chain risk management, and the ISM includes controls on evaluating software suppliers and on application control. The Essential Eight's patch applications and application control strategies relate directly: you can't patch what you can't inventory (SBOMs), and application control limits what unknown code can run. Government and financial-sector procurement increasingly ask for SBOMs.
packageSourceMapping to a solution's nuget.config, then add a package whose id matches no pattern and read the restore error.dotnet restore --locked-mode to see NU1004.build/ and buildTransitive/ folders of packages in ~/.nuget/packages for one project; see what runs at build time.sbom-tool generate for a published app and search it for a specific package.actions/attest-build-provenance to a workflow and verify with gh attestation verify.nuget.config: one controlled feed for internal packages, mapping for everything, optional signer restrictions:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<clear />
<add key="contoso" value="https://pkgs.dev.azure.com/contoso/_packaging/internal/nuget/v3/index.json" />
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
</packageSources>
<packageSourceMapping>
<packageSource key="contoso">
<package pattern="Contoso.*" /> <!-- internal ids can ONLY come from our feed -->
</packageSource>
<packageSource key="nuget.org">
<package pattern="*" />
</packageSource>
</packageSourceMapping>
<config>
<!-- Regulated environments: reject anything not signed by a trusted signer. -->
<add key="signatureValidationMode" value="accept" />
</config>
</configuration>
Directory.Build.props: reproducible restores across the solution:
<Project>
<PropertyGroup>
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
<RestoreLockedMode Condition="'$(CI)' == 'true'">true</RestoreLockedMode>
</PropertyGroup>
</Project>
GitHub Actions: pinned actions, minimal permissions, SBOM and signed provenance for the published artefact:
name: build
on: { push: { branches: [main] } }
permissions:
contents: read
id-token: write # OIDC for Sigstore signing and Azure workload identity
attestations: write
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2, pinned by SHA
- uses: actions/setup-dotnet@67a3573c9a986a3f9c594539f4ab511d57bb3ce9 # v4.3.1
with: { global-json-file: global.json }
- run: dotnet restore --locked-mode
- run: dotnet publish src/Claims.Api -c Release -o out
- run: |
dotnet tool install --global Microsoft.Sbom.DotNetTool
sbom-tool generate -b out -bc src/Claims.Api -pn Claims.Api -pv ${{ github.sha }} -ps Contoso
- uses: actions/attest-build-provenance@v2
with: { subject-path: 'out/Claims.Api.dll' }
(Pin attest-build-provenance by SHA too in a real workflow; Dependabot can keep SHA pins updated.)
@v4). Why it is wrong: Tags are mutable; a compromised action can move them to malicious commits. Instead: Pin by full commit SHA and let Dependabot update pins.--locked-mode in CI.permissions:, deploy jobs separate from build jobs.Supply chain security is about trust boundaries in the build: deciding which sources you trust, pinning exactly what you got, limiting what build-time code can reach, and producing evidence of what you shipped. A senior engineer prioritises by cost and impact: source mapping, lock files, SHA-pinned actions and least-privilege CI credentials are cheap and close the most common paths; trusted-signer enforcement and SLSA L3 are expensive and worth it for high-assurance systems.
There's a tension with patching speed: locking everything down slows upgrades, while auto-merging every Dependabot PR invites compromised releases. A common middle ground is a short cool-down (adopting non-security updates after a few days) with fast-track security patches. Measure: percentage of repos with source mapping and lock files, SHA-pinned actions, SBOM coverage, and time to answer "are we affected?" for a new CVE.
| Control | When it fits | Cost | When not to |
|---|---|---|---|
| Source mapping + internal feed | Any team with internal packages | Low | Never skip if you have internal packages |
| Lock files + locked mode | All services | Lock file churn in PRs | Libraries published for others (lock files don't flow to consumers) |
| trustedSigners require mode | Regulated, high-assurance builds | High maintenance per new package owner | Fast-moving teams without a curation process |
| SBOM + provenance attestations | Anything deployed to production, government procurement | Pipeline steps, storage | Throwaway prototypes |
First I read the exact error. NU1301 means a source couldn't be reached, 401 or 403 means authentication, and NU1101 means the package isn't on any configured source. It works on my machine because I have cached packages and stored credentials, while CI starts clean. Then I check which nuget.config CI actually uses, since config files are merged from the repo upwards. I make the repo's config explicit with <clear />, and I authenticate CI the supported way, for example the Azure Artifacts credential provider or a token from the pipeline's secret store, never a committed password. I also add package source mapping and lock files so restores are reproducible and protected against dependency confusion.
dotnet pack builds the project and produces a .nupkg whose metadata comes from MSBuild properties in the project: PackageId, Version, Authors, Description, a licence expression, a repository URL and a README. I set the version from CI using Semantic Versioning, so a breaking change means a new major version. I publish symbols as a .snupkg with Source Link, so consumers can step into the exact source. I turn on package validation to catch accidental breaking changes. Then dotnet nuget push uploads to nuget.org or an internal feed, and organisations that need it can sign packages with dotnet nuget sign.
I use NuGetAudit, which runs during dotnet restore and reports known vulnerabilities as NU1901-NU1904 (low to critical). With the .NET 10 SDK, net10.0 projects audit transitive packages by default (NuGetAuditMode=all). For policy, I set WarningsAsErrors for NU1903 and NU1904 in CI so high and critical findings fail the build, while low and moderate stay as warnings with tickets. Reviewed false positives get a NuGetAuditSuppress entry with the advisory URL and a recorded expiry. dotnet list package --vulnerable --include-transitive --format json feeds reports. Dependabot opens grouped upgrade PRs and security updates. If restore uses only a private feed, I add <auditSources> pointing at nuget.org. And I scan container images separately. Trade-off: strict gates on transitive findings can block a release for an unreachable code path, so exceptions must be quick, visible and time-boxed.
How to tell it (STAR)
**S:** We had [about 40] services using internal `Contoso.` packages, and our feeds mixed the internal source and nuget.org with no mapping. **T:** After [a researcher reported] a look-alike public package with a higher version, I [led] closing the dependency confusion risk across the estate. **A:** I verified from restore logs and assets files that nothing had pulled it, reserved our prefix, rolled out a standard nuget.config with source mapping and lock files, and added SBOMs and signed provenance to our shared pipeline. **R:** [All 40] repos were mapped within [three weeks], and when the next major CVE arrived we found the [6] affected services in [20 minutes] from SBOMs.
Last updated 23 Nov 2026.