Dependency and secret hygiene
Dependency and secret hygiene
Secret hygiene keeps credentials out of code, logs, build artifacts and unnecessary process boundaries. Dependency hygiene keeps the software supply chain reviewable: know what packages you restore, from which sources, with what transitive dependencies and known advisories. Neither a lockfile nor a successful audit proves an application is secure.
Use development user secrets only for local convenience; their file is not an encrypted vault. Production secrets belong in an approved secret store with scoped access, rotation and audit. Environment variables can be visible to processes and diagnostics; do not dump configuration or exception contents indiscriminately. Log an allowlist of operational fields rather than trying to redact every possible credential pattern. A compromised secret needs revocation and replacement, not merely removal from the latest commit. ASP.NET Core Data Protection keys require separate lifecycle and storage protections; replicas must share a suitable key ring and application discriminator when sharing tickets. Do not disable TLS certificate validation to resolve connectivity issues. Review direct and transitive NuGet packages, lockfile changes, source mappings, signatures/provenance where applicable, maintenance and advisories. .NET 10 NuGet auditing defaults to all dependencies for net10.0 targets; dotnet package list --include-transitive --vulnerable lists known advisories from available sources, and may restore unless --no-restore is specified. Audit metadata and feeds may require network access; run only with approved sources and privacy policy. Do not disable auditing merely to make a build succeed. Use a risk-based upgrade, rerun tests and document exceptions with an owner and expiry. The examples are offline data exercises: no secret store, logging backend or package feed is contacted.
Baseline: .NET 10 / C# 14 with Microsoft.AspNetCore.App shared framework. All snippets are independent console fixtures, not ByteMind runner code. In an approved isolated environment with a reviewed installed SDK and targeting packs, use dotnet build and dotnet run --no-build in the fixture directory; restore only from approved sources if required. No external service, real user data, account or credential is needed. Expected results are reasoned, not executed; cryptographic random data is not printed.
Project a safe log event
Allowlist only operational fields; the fictional credential and request body are deliberately omitted.
using System.Text.Json;var request = new Dictionary<string, string> { ["requestId"] = "req-17", ["operation"] = "catalog-read", ["authorization"] = "SYNTHETIC-NOT-A-SECRET", ["body"] = "private fixture"};var safe = new { requestId = request["requestId"], operation = request["operation"] };var json = JsonSerializer.Serialize(safe);Console.WriteLine(json);Console.WriteLine(!json.Contains("SYNTHETIC", StringComparison.Ordinal));Expected output (not executed):
{"requestId":"req-17","operation":"catalog-read"}TrueOnly explicitly approved fields appear. A production sink and exception logging also need review; this snippet does not test a logging provider.
Validate configuration presence without revealing values
Use only an in-memory configuration dictionary. A blank credential is a startup configuration error, and the diagnostic never prints the value.
using Microsoft.Extensions.Configuration;foreach (var value in new[] { "fixture-value", "", " " }) { var config = new ConfigurationBuilder().AddInMemoryCollection(new Dictionary<string, string?> { ["Catalog:Credential"] = value }).Build(); Console.WriteLine(string.IsNullOrWhiteSpace(config["Catalog:Credential"]) ? "configuration missing" : "configuration present");}Expected output (not executed):
configuration presentconfiguration missingconfiguration missingThe presence check avoids printing the credential. Production startup validation must also check applicability and access; no actual secret is loaded.
Review a synthetic dependency change list
Compare two fictional resolved graphs. Flag additions, removals and changed versions without parsing semantic versions or contacting a registry.
var before = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase) { ["Example.Core"] = "1.0.0", ["Example.Legacy"] = "2.0.0"};var after = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase) { ["Example.Core"] = "1.1.0", ["Example.Transport"] = "3.0.0"};foreach (var id in before.Keys.Union(after.Keys, StringComparer.OrdinalIgnoreCase).OrderBy(x => x, StringComparer.Ordinal)) { before.TryGetValue(id, out var oldVersion); after.TryGetValue(id, out var newVersion); if (oldVersion != newVersion) Console.WriteLine($"{id}: {oldVersion ?? "absent"} -> {newVersion ?? "absent"}");}Expected output (not executed):
Example.Core: 1.0.0 -> 1.1.0Example.Legacy: 2.0.0 -> absentExample.Transport: absent -> 3.0.0The change list prompts review of additions, removals and version changes. It is not a NuGet resolver, advisory database or semantic-version comparator.
Apply the concept
A CI build reports a vulnerable transitive package and a developer discovers a committed API key. Write a response plan covering both issues, with no actual account changes.
Use the manual practice and knowledge check to reason about the boundary. Do not deploy these fixtures as production security controls.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Dependency and secret hygiene — knowledge check
Apply the lesson concepts to the following scenarios.
A secret is removed from the latest commit after exposure. What else is essential?
Is Secret Manager a production encrypted vault?
What is safer for routine request logs?
What does an unchanged NuGet lockfile establish?
What should follow a transitive dependency advisory?