📁 Sangam Dhakal - Portfolio v2.0 - Netscape Navigator 4.0
_
□
×

📚 Interview question

What is software supply chain security for a .NET team, and how do you protect your builds? Cover NuGet package source mapping and lock files, package signing and trusted signers, typosquatting and dependency confusion, SBOMs, and build provenance and attestations.

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.

Senior Theory Advanced ci-cd nuget sbom security slsa supply-chain-security

🎯 Key points

  • Attack paths, with real examples: compromised build systems (SolarWinds Orion, 2020), compromised CI tooling (Codecov bash uploader, 2021; tj-actions/changed-files tag hijack, 2025), backdoored maintainers (xz-utils, 2024), typosquatting and dependency confusion on public registries including nuget.org
  • NuGet packages can run code at build time: build/*.targets, analysers and source generators execute on the CI agent
  • Package source mapping pins each package id pattern to a source, blocking dependency confusion; reserve your ID prefix on nuget.org
  • Lock files (packages.lock.json) plus restore --locked-mode make restores reproducible and detect unexpected changes
  • Signing: nuget.org repository signatures on every package, author signatures optional; trustedSigners with signatureValidationMode=require restricts accepted signers; signed is not the same as safe
  • SBOMs (SPDX/CycloneDX via Microsoft sbom-tool) record exactly what shipped, enabling fast impact analysis for new CVEs
  • Build provenance: signed attestations (GitHub artifact attestations, SLSA build levels) verified at deploy; pin third-party actions by commit SHA; least-privilege CI with workload identity federation
  • Continuous, automated monitoring in CI/CD: NuGetAudit, Dependabot/Renovate, GitHub dependency review, or commercial tools such as Snyk or Mend; plus a habit of tracking new attack techniques (ACSC advisories, OpenSSF, GitHub Security Lab)

⏱ 30-second answer

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.

🗣 Full answer (senior)

How I would answer this in an interview

"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/*.targets files 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.config with <clear/>, our Azure Artifacts feed with nuget.org as an upstream, package source mapping so Contoso.* 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."


Attacks and controls

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)

SLSA build levels (v1.0), simplified

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

Production example

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.

🔍 What the interviewer is checking

Checks whether the candidate understands supply chain attacks beyond known CVEs and can apply concrete .NET and CI controls.

Green flags

  • Distinguishes typosquatting, dependency confusion, compromised packages and compromised builds.
  • Knows NuGet build-time code execution.
  • Source mapping, lock files, signing (and its limits), internal feeds.
  • SBOMs and provenance with a purpose (impact analysis, deploy verification), SLSA awareness.
  • Least-privilege CI and SHA-pinned actions.

Red flags

  • "We run Dependabot, so we're covered."
  • Thinks signed packages are safe.
  • No idea that packages can run code during build.

📚 Learn in depth

1. The supply chain, end to end

  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.

2. How NuGet resolves packages, and why confusion happens

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.

3. Build-time code execution in NuGet

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.

4. Signing in NuGet

  • Repository signatures: nuget.org countersigns every package, proving it came from nuget.org unmodified.
  • Author signatures: optional, prove the author's identity with a code-signing certificate.
  • 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.
  • Signing proves origin and integrity, not safety: a compromised maintainer's malicious package is validly signed.

5. Lock files and pinning

  • 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.
  • Pin GitHub Actions by commit SHA (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.

6. SBOMs

A software bill of materials lists every component (name, version, licence, hash, supplier) in an artefact.

  • Formats: SPDX (ISO/IEC 5962) and CycloneDX.
  • Tools: Microsoft sbom-tool (SPDX), the CycloneDX .NET tool, Syft for container images.
  • Uses: CVE impact analysis, licence compliance, customer and government procurement requirements, vulnerability exchange (VEX) statements.
  • Store SBOMs alongside artefacts and attach them as attestations.

7. Provenance and attestations

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.

8. Australian context

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.

Try it yourself

  1. Add packageSourceMapping to a solution's nuget.config, then add a package whose id matches no pattern and read the restore error.
  2. Enable lock files, commit them, bump a version in the csproj and run dotnet restore --locked-mode to see NU1004.
  3. List the build/ and buildTransitive/ folders of packages in ~/.nuget/packages for one project; see what runs at build time.
  4. Generate an SBOM with sbom-tool generate for a published app and search it for a specific package.
  5. Add actions/attest-build-provenance to a workflow and verify with gh attestation verify.

💻 Code

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.)

⚠ Common mistakes

  • Mistake: Treating vulnerability scanning as supply chain security. Why it is wrong: Scanners only know about published CVEs; a malicious or freshly compromised package has none. Instead: Control sources, pin versions, review new dependencies, and add provenance.
  • Mistake: Mixing internal and public feeds without source mapping. Why it is wrong: Dependency confusion can substitute a public package for your internal one. Instead: Map internal prefixes to the internal feed and reserve the prefix on nuget.org.
  • Mistake: Assuming a package is harmless if the app never calls it. Why it is wrong: MSBuild targets, analysers and source generators run during build on the CI agent. Instead: Treat every dependency as code that runs in CI; keep CI credentials short-lived and scoped.
  • Mistake: Pinning GitHub Actions by tag (@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.
  • Mistake: Floating versions without lock files. Why it is wrong: Builds change without a commit, and a malicious new version arrives automatically. Instead: Lock files with --locked-mode in CI.
  • Mistake: Believing signed means safe. Why it is wrong: Signatures prove origin and integrity; a compromised maintainer signs malware validly. Instead: Combine signing with source control, delayed adoption and review.
  • Mistake: Generating SBOMs nobody stores or queries. Why it is wrong: They add no value at CVE time if you can't find them. Instead: Store SBOMs with artefacts and make them searchable.
  • Mistake: Giving CI jobs broad, long-lived cloud credentials. Why it is wrong: Any malicious build-time code inherits them. Instead: Workload identity federation, minimal permissions:, deploy jobs separate from build jobs.

🏛 Senior insight: trade-offs

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

🔗 Follow-ups the interviewer may ask

  1. When: Candidate mentions package source mapping or private feeds. Why: Checks practical NuGet configuration: feeds, credentials, source mapping and lock files in CI.
    How to answer

    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.

  2. When: Candidate mentions package signing. Why: Checks the producer side: signing and publishing packages correctly.
    How to answer

    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.

  3. When: Candidate mentions scanning dependencies for vulnerabilities. Why: Checks the known-vulnerability side of dependency risk: NuGetAudit and failing builds on policy.
    How to answer

    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.

🛠 Real-world problems: how you handle them

Unreserved internal prefix and a near-miss dependency confusion
Situation
[A fintech] with [~40] .NET services and internal packages under a `Contoso.` prefix published to Azure Artifacts. Developers' machines and some pipelines listed both the internal feed and nuget.org without source mapping.
Signals
A security researcher's report (or an internal check) showed a public nuget.org package named like one of the internal packages, with a higher version number and an install-time `build/*.targets` file that made an outbound HTTP call.
Investigation
Searched all repos for `nuget.config` files and mapping, ran `dotnet restore -v detailed` on affected pipelines to see which source served each package, checked `obj/project.assets.json` for package sources and hashes, and reviewed CI agent egress logs for calls to the researcher's domain.
Resolution
Immediate: confirmed no pipeline had restored the public package, reported it to nuget.org for removal, and reserved the `Contoso.` prefix. Long term: a standard `nuget.config` with `<clear/>`, source mapping and the internal feed with upstreams in every repo; lock files with locked mode; SBOM generation and provenance attestations in the shared pipeline template.
Prevention
A pipeline check that fails builds whose `nuget.config` lacks source mapping, Dependabot for SHA-pinned actions, quarterly review of reserved prefixes, and SBOM-based CVE impact queries.

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.

↩ Usually asked after

More in Senior Security Topics

Last updated 23 Nov 2026.

🌐 Sangam's Webring

⏪ Previous 🏠 Main Next ⏩
💬 Chat with me