duendesoftware/duende-skills/identity-security-hardening

Claude Code and agent skill by duendesoftware/duende-skills

Trust tier 3
  • community
Source check pending

Checking that the SKILL.md file is still in the repository.

Security hardening for Duende IdentityServer deployments including signing key rotation, HTTPS enforcement, CORS configuration, CSP headers, rate limiting, token lifetime tuning, and security audit patterns.

Install

npx vskill@latest install duendesoftware/duende-skills/identity-security-hardening

SKILL.md

The same SKILL.md was published earlier as duendesoftware/duende-skills/identity-security-hardening.

Identity Security Hardening

When to Use This Skill

Use this skill when:

  • Hardening a Duende IdentityServer deployment before promoting to production
  • Configuring HTTPS, HSTS, and TLS requirements for the identity server host
  • Evaluating or enforcing client secret policies (shared secrets vs. certificates vs. private_key_jwt)
  • Setting PKCE requirements, restricting grant types, or locking down redirect URI validation
  • Configuring Content Security Policy (CSP) and CORS for IdentityServer UI pages and endpoints
  • Applying rate limiting to the token endpoint to protect against brute-force and enumeration attacks
  • Tuning token lifetimes, enabling reference tokens, or implementing token replay detection
  • Rotating signing keys or choosing between RS256 and ES256 algorithms
  • Hardening session lifetimes, idle timeouts, and back-channel logout behavior
  • Auditing an existing IdentityServer setup against OAuth 2.0 Security Best Current Practice (RFC 9700)

Core Principles

  1. HTTPS Everywhere — IdentityServer must only be reachable over HTTPS in production. Any HTTP request should be permanently redirected. HSTS with includeSubDomains and preload is the minimum bar.
  2. Reduce Token Blast Radius — Short access token lifetimes, reference tokens for sensitive APIs, and audience validation ensure that a stolen token can do minimal damage.
  3. PKCE is Non-Negotiable — Every authorization code flow client must use PKCE, regardless of whether it is a public or confidential client. RequirePkce = true is the default; never disable it.
  4. Asymmetric Client Authentication — Prefer certificate-based or private_key_jwt client authentication over shared secrets. Secrets that are never transmitted cannot be stolen in transit.
  5. Strict Redirect URI Matching — Wildcards in redirect URIs are a critical attack surface. Every production URI must be fully qualified and must match exactly.
  6. Restrict Grant Types Per Client — Every client should only allow the grant types it actually uses. Disabling implicit flow and unused grants is one of the highest-impact, lowest-effort hardening steps.
  7. Defense in Depth — Combine transport security, token constraints, rate limiting, CSP, and CORS into a layered defense. No single control is sufficient.

Related Skills

  • identityserver-configuration — Server-side configuration of clients, resources, and signing keys that these hardening patterns build upon
  • oauth-oidc-protocols — Protocol-level context for PKCE, PAR, DPoP, and grant type trade-offs
  • aspnetcore-authentication — Applying OIDC authentication hardening in client applications
  • aspnetcore-authorization — Enforcing authorization policies that consume the hardened tokens produced here

Docs: https://docs.duendesoftware.com/general/security-best-practices/


Sub-Documents

DocumentDescriptionWhen to Load
docs/cors-csp.mdCORS ICorsPolicyService implementation and CSP middleware with header examplesCORS origins, Content-Security-Policy, X-Frame-Options, clickjacking, custom CORS policy
docs/rate-limiting.mdASP.NET Core AddRateLimiter configuration for token and authorization endpointsRate limiting, brute force, 429, sliding window, fixed window, token endpoint protection
docs/session-hardening.mdServer-side sessions, cookie lifetime configuration, back-channel logout client setupSession security, CookieSlidingExpiration, BackChannelLogoutUri, session fixation, inactivity

Pattern 1: Transport Security — HTTPS, HSTS, and TLS

IdentityServer handles credentials and tokens. Every byte must travel over TLS. ASP.NET Core provides the pipeline middleware to enforce this.

csharp
// ✅ Program.cs — production pipeline ordering
var app = builder.Build();
// 1. HTTPS redirection — permanent redirect (308) for any HTTP request
app.UseHttpsRedirection();
// 2. HSTS — tell browsers to always use HTTPS for this host
// includeSubDomains: all subdomains also require HTTPS
// preload: opt-in to browser preload lists (requires max-age >= 1 year)
app.UseHsts();
app.UseIdentityServer();
app.UseAuthorization();

Configure HSTS options in Program.cs before Build():

csharp
// ✅ Strong HSTS configuration
builder.Services.AddHsts(options =>
{
options.MaxAge = TimeSpan.FromDays(365);
options.IncludeSubDomains = true;
options.Preload = true;
// Optionally exclude development/staging hosts
// options.ExcludedHosts.Add("localhost");
});
// ✅ Force HTTPS redirect to use 443 explicitly
builder.Services.AddHttpsRedirection(options =>
{
options.RedirectStatusCode = StatusCodes.Status308PermanentRedirect;
options.HttpsPort = 443;
});
Behind a Reverse Proxy

When IdentityServer sits behind a load balancer or reverse proxy that terminates TLS, the inner request arrives as HTTP. Configure ForwardedHeaders so IdentityServer sees the correct scheme:

csharp
// ✅ Required when hosted behind a load balancer or ingress
builder.Services.Configure<ForwardedHeadersOptions>(options =>
{
options.ForwardedHeaders =
ForwardedHeaders.XForwardedFor |
ForwardedHeaders.XForwardedProto;
// Restrict to known proxy IPs — never accept from any source
options.KnownProxies.Add(IPAddress.Parse("10.0.0.1"));
options.ForwardLimit = 1;
});
// Must be the very first middleware in the pipeline
app.UseForwardedHeaders();
app.UseHttpsRedirection();
app.UseHsts();
app.UseIdentityServer();
Important: Without ForwardedHeaders, IdentityServer publishes an http:// issuer URI in the discovery document, causing token validation failures in every downstream API.
Kestrel TLS Configuration

For direct Kestrel hosting (no reverse proxy), configure TLS explicitly:

csharp
// ✅ Kestrel TLS — require TLS 1.2 minimum
builder.WebHost.ConfigureKestrel(options =>
{
options.ConfigureHttpsDefaults(https =>
{
https.SslProtocols = SslProtocols.Tls12 | SslProtocols.Tls13;
https.ClientCertificateMode = ClientCertificateMode.NoCertificate;
});
});

Pattern 2: Signing Key Security — Algorithm Selection and Rotation

Signing keys are the root of trust for every token IdentityServer issues. The default RS256 algorithm is broadly compatible. ES256 (ECDSA) offers smaller tokens and is appropriate for new deployments. Supported signing algorithm families are RS (RSA PKCS#1), PS (RSA-PSS), and ES (ECDSA).

Rotation overlap rule: Always publish a new public key before using it to sign tokens, and keep a retired public key available until all tokens signed with it have expired. Consumers must be able to fetch the key (via JWKS) both before it starts signing and after it stops. Automatic Key Management handles this overlap automatically; manual key managers must do phased rotation (below).
Automatic Key Management (Recommended)
csharp
// ✅ Production automatic key management
builder.Services.AddIdentityServer(options =>
{
// Rotate every 90 days (default); reduce for higher-security deployments
options.KeyManagement.RotationInterval = TimeSpan.FromDays(90);
// Announce 14 days before activation so JWKS caches refresh
options.KeyManagement.PropagationTime = TimeSpan.FromDays(14);
// Keep retired keys for 14 days to validate recently-issued tokens
options.KeyManagement.RetentionDuration = TimeSpan.FromDays(14);
// Delete keys when their retention period ends
options.KeyManagement.DeleteRetiredKeys = true;
// Encrypt keys at rest via ASP.NET Core Data Protection (default: true)
options.KeyManagement.DataProtectKeys = true;
// Store keys in a shared, durable location for load-balanced deployments
options.KeyManagement.KeyPath = "/var/identity/keys";
// ES256 first = default for new tokens; RS256 for legacy client compatibility
options.KeyManagement.SigningAlgorithms = new[]
{
new SigningAlgorithmOptions(SecurityAlgorithms.EcdsaSha256),
new SigningAlgorithmOptions(SecurityAlgorithms.RsaSha256)
{
UseX509Certificate = true
}
};
});
Key Storage — ASP.NET Data Protection

Automatic key management encrypts signing keys at rest using ASP.NET Data Protection. Configure Data Protection to use durable, shared storage. See ASP.NET Core Data Protection for complete configuration guidance.

v8 licensing note: On IdentityServer v8, Automatic Key Management, Server-Side Sessions, and SAML throw at startup when a license is present but lacks the entitlement (other licensed features only log a warning). Run lower environments with the production license key so entitlement gaps surface before production. Also note the v8 license key is a signed JWT with a kid header and fails on v7/BFF runtimes with IDX10503. See ASP.NET Core Data Protection for complete configuration guidance.
csharp
// ✅ Data Protection for load-balanced IdentityServer
builder.Services.AddDataProtection()
// Persist keys to a shared location accessible by all instances
.PersistKeysToFileSystem(new DirectoryInfo("/var/identity/dp-keys"))
// Or: .PersistKeysToDbContext<IdentityDbContext>()
// Or: .PersistKeysToAzureBlobStorage(...)
.ProtectKeysWithCertificate(LoadProtectionCertificate())
// Always set an explicit application name
.SetApplicationName("identity-server");
Warning: Never store Data Protection keys on ephemeral storage (e.g., container local disk). If keys are lost, all encrypted data (persisted grants, cookies, server-side sessions) becomes unreadable.
Manual Key Rotation (Three-Phase Process)

When using static keys, never swap them in a single deployment. Use a phased rotation to avoid breaking in-flight token validation:

csharp
// Phase 1: Announce new key — continue signing with old key
// Deploy and wait ≥ 24 h for JWKS caches to refresh
idsvrBuilder.AddSigningCredential(oldKey, SecurityAlgorithms.RsaSha256);
idsvrBuilder.AddValidationKey(newKey, SecurityAlgorithms.RsaSha256);
// Phase 2: Switch to new key — retain old key for validation
// Deploy and wait ≥ token lifetime (default 1 h) for old tokens to expire
idsvrBuilder.AddSigningCredential(newKey, SecurityAlgorithms.RsaSha256);
idsvrBuilder.AddValidationKey(oldKey, SecurityAlgorithms.RsaSha256);
// Phase 3: Drop old key — old tokens are all expired
idsvrBuilder.AddSigningCredential(newKey, SecurityAlgorithms.RsaSha256);

Pattern 3: Token Constraints — Lifetimes, Reference Tokens, and Audience Validation

Token constraints limit the damage from token compromise and ensure tokens are only usable at their intended audience.

Token Lifetime Tuning
csharp
// ✅ Production-tuned client — short-lived access tokens, rotating refresh tokens
new Client
{
ClientId = "web.app",
AllowedGrantTypes = GrantTypes.Code,
RequirePkce = true,
// Short access token — reduces replay window
AccessTokenLifetime = 300, // 5 minutes (default: 3600)
// Identity tokens are consumed immediately after login
IdentityTokenLifetime = 300, // 5 minutes (default: 300)
// Refresh tokens rotate on every use — each use issues a new token
AllowOfflineAccess = true,
RefreshTokenUsage = TokenUsage.OneTimeOnly,
RefreshTokenExpiration = TokenExpiration.Absolute,
AbsoluteRefreshTokenLifetime = 86400, // 24 hours (default: 2592000 = 30 days)
SlidingRefreshTokenLifetime = 3600, // 1 hour sliding window
// Revoke refresh tokens when the user's session ends
CoordinateLifetimeWithUserSession = true
}
Reference Tokens

This is the start of the file. Read the full SKILL.md on GitHub.

Security

  • Security scanPassed, 95 of 100Pattern checks on the skill's files.
  • Model reviewPassed

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

7-day trend score
0

Not refreshed yet.

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/duendesoftware/duende-skills/identity-security-hardening/badge)](https://verified-skill.com/skills/duendesoftware/duende-skills/identity-security-hardening)

Something wrong with this skill or its page? Tell us.