ASP.NET Core Health Checks and Supply Chain Security
On this page
Learning Objective
Implement liveness and readiness health checks that do not leak information, alert on symptoms tied to service objectives rather than on every cause, automate dependency vulnerability scanning for NuGet and npm, and harden the build supply chain against dependency confusion, compromised actions and tampered artifacts.
Concept Explanation
Orchestrators and load balancers need a cheap way to ask an application whether it is fine. ASP.NET Core health checks answer with an HTTP endpoint and distinguish three questions. A liveness check asks whether the process is running and not deadlocked; if it fails, the platform restarts the instance. A readiness check asks whether the instance can serve traffic right now, including whether its database and cache are reachable; if it fails, the load balancer stops sending it requests without restarting it. A startup check gives slow-starting applications time to initialize. Conflating liveness with readiness causes outages: if liveness includes the database, a database blip makes the platform restart every instance simultaneously, turning a small problem into a complete one.
Health endpoints have a security dimension. A detailed health response listing the versions, database names, and dependency states of your system is reconnaissance material for an attacker. Keep the public endpoint minimal, returning only a status, and serve detailed results on an internal port, behind authentication, or only to the platform's probe addresses. The same applies to the diagnostic endpoints that frameworks offer. Remember that a readiness check that does expensive work can itself be abused to load the system, so keep checks cheap and cache their results briefly.
Alerting is the difference between telemetry that exists and telemetry that helps. The guidance from site reliability engineering is to alert on symptoms that affect users, such as an elevated error rate or latency measured against a service level objective, and to page a human only when action is needed now. Cause-based alerts, such as CPU above 80 percent, fire constantly without user impact and train people to ignore pages, the pattern known as alert fatigue. Multi-window burn-rate alerts on an error budget catch both sudden outages and slow degradation. Every alert should link to a runbook explaining what it means and what to do, and each should be reviewed after incidents: alerts that never led to action are deleted. Security-relevant alerts, such as spikes in failed logins, authorization denials, or role changes, belong in the same system.
Your application is mostly other people's code, so the supply chain is part of your attack surface. The practices form a chain. Scan for known vulnerabilities continuously: NuGet audit reports vulnerable packages during restore, npm audit does the same for JavaScript, and Dependabot or Renovate open pull requests for updates so patches are small and routine. Prevent dependency confusion, the attack where a public package with the same name as your private one and a higher version is installed instead, by configuring NuGet package source mapping so each package ID can come from only one source, and by using scoped registries in npm. Pin the GitHub Actions your pipeline uses to full commit SHAs, since tags can be moved, as the March 2025 compromise of the popular tj-actions changed-files action showed. Generate a software bill of materials so you can quickly answer which of your services contain a newly disclosed vulnerable library, and sign or attest your build artifacts so what you deploy is provably what you built.
| Practice | Protects against | Note |
|---|---|---|
| Separate liveness and readiness | Restart storms from dependency blips | Liveness never includes external dependencies |
| Minimal public health output | Reconnaissance | Detail only on internal or authenticated routes |
| Symptom-based, burn-rate alerts | Alert fatigue and missed degradation | Runbook linked to every alert |
| NuGet audit, npm audit, Dependabot | Known vulnerabilities | Automate updates so they stay small |
| Package source mapping | Dependency confusion | One trusted source per package ID |
| Pinned action SHAs, SBOM, attestation | Compromised actions, unknown exposure, tampered artifacts | Verify what you build and deploy |
Worked Example: Health Endpoints, Auditing, Source Mapping, Dependabot and a Pinned Pipeline
The code separates the health checks and hides the detail. The configuration files harden dependencies and the workflow.
builder.Services.AddHealthChecks()
.AddCheck("self", () => HealthCheckResult.Healthy(), tags: ["live"]) // process is up: nothing external here
.AddSqlServer(builder.Configuration.GetConnectionString("Default")!, name: "sql", tags: ["ready"], timeout: TimeSpan.FromSeconds(2))
.AddRedis(builder.Configuration["Redis:Configuration"]!, name: "redis", tags: ["ready"], timeout: TimeSpan.FromSeconds(2));
// Public and minimal: a status word, no details.
app.MapHealthChecks("/health/live", new() { Predicate = r => r.Tags.Contains("live"), ResponseWriter = (c, _) => c.Response.WriteAsync("ok") })
.AllowAnonymous();
app.MapHealthChecks("/health/ready", new() { Predicate = r => r.Tags.Contains("ready"), ResponseWriter = (c, r) => c.Response.WriteAsync(r.Status.ToString()) })
.AllowAnonymous();
// Detailed results: authenticated administrators only, or an internal port.
app.MapHealthChecks("/health/details", new() { ResponseWriter = WriteDetailedJson }).RequireAuthorization("SiteAdmin");<!-- Directory.Build.props: fail the build on known vulnerable packages, including transitive ones. -->
<Project>
<PropertyGroup>
<NuGetAudit>true</NuGetAudit>
<NuGetAuditMode>all</NuGetAuditMode>
<NuGetAuditLevel>low</NuGetAuditLevel>
<WarningsAsErrors>$(WarningsAsErrors);NU1901;NU1902;NU1903;NU1904</WarningsAsErrors>
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
</PropertyGroup>
</Project><!-- nuget.config: package source mapping stops dependency confusion. Each ID comes from exactly one source. -->
<configuration>
<packageSources>
<clear />
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
<add key="company" value="https://pkgs.dev.azure.com/example/_packaging/internal/nuget/v3/index.json" />
</packageSources>
<packageSourceMapping>
<packageSource key="company"><package pattern="Example.*" /></packageSource>
<packageSource key="nuget.org"><package pattern="*" /></packageSource>
</packageSourceMapping>
</configuration># .github/dependabot.yml: routine, small updates for every ecosystem, grouped to keep noise low.
version: 2
updates:
- package-ecosystem: nuget
directory: /
schedule: { interval: weekly }
groups: { minor-and-patch: { update-types: [minor, patch] } }
- package-ecosystem: npm
directory: /web
schedule: { interval: weekly }
groups: { minor-and-patch: { update-types: [minor, patch] } }
- package-ecosystem: github-actions
directory: /
schedule: { interval: weekly }# Workflow hardening: least-privilege token, actions pinned to full SHAs, SBOM and provenance for the artifact.
permissions: { contents: read }
jobs:
build:
runs-on: ubuntu-latest
permissions: { contents: read, id-token: write, attestations: write }
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2, pinned to a commit, not a movable tag
- run: npm ci --ignore-scripts && npm audit --audit-level=high && npm audit signatures
- run: dotnet build -warnaserror && dotnet list package --vulnerable --include-transitive
- run: dotnet tool run dotnet-CycloneDX TaskBoard.sln -o sbom --json # software bill of materials
- uses: actions/attest-build-provenance@v2 # verifiable link from artifact to source
with: { subject-path: artifacts/api.zip }# Alert design: symptoms tied to an objective, each with a runbook.
SLO: 99.5% of API requests succeed and 95% complete in under 500 ms, over 30 days.
Page: error-budget burn rate > 14x over 5 min AND 1 h -> runbook: /runbooks/api-errors (fast burn: outage)
Ticket: error-budget burn rate > 2x over 6 h AND 24 h -> runbook: /runbooks/slow-burn (slow degradation)
Security page: failed-login rate > 10x baseline for 10 min, or any role change outside a deployment window
Do NOT page on: CPU > 80%, a single pod restart, a single 500 response.The alert rules also state what not to page on. Lowering the number of pages a person receives is a reliability and security improvement, because an on-call engineer who trusts the pager responds quickly when it does ring.
Real-World Examples
- In 2021 security researcher Alex Birsan disclosed dependency confusion, showing that by publishing public packages named like internal ones to npm, PyPI, and RubyGems he could get code executed inside more than 35 companies including Microsoft, Apple, and PayPal. The attack drove the introduction of NuGet package source mapping and scoped registries as standard defenses.
- In March 2025, the widely used GitHub Action tj-actions/changed-files was compromised, and its tags were repointed to a malicious commit that printed secrets from runner memory into workflow logs, affecting thousands of repositories that referenced it by tag. Pinning actions to a full commit SHA, the practice shown above, would have protected workflows that had not updated to the poisoned version.
Review Questions & Answers
A liveness failure tells the platform to restart the instance. If a brief database problem fails liveness on every instance, they all restart together, causing a full outage and a reconnection stampede when the database returns. Dependencies belong in readiness, which only removes the instance from rotation without killing it.
Symptoms such as elevated errors or latency directly reflect what users experience, so every page corresponds to real impact and demands action. Cause-based alerts like high CPU fire often without any user effect, training engineers to ignore alerts. Burn-rate alerts on an error budget also detect both fast outages and slow degradation.
It declares which package IDs may be restored from which source, so an internal package name can only come from the private feed and never from the public registry. An attacker publishing a same-named package with a higher version to nuget.org is ignored because that ID is mapped exclusively to the internal source.
Tags are movable references, so if an action's repository is compromised the attacker can repoint a tag to malicious code and every workflow using it runs that code with access to secrets. A full commit SHA is immutable, so the workflow keeps running exactly the code you reviewed until you deliberately update it.