Beschikbaarheidspoort laat publieke site-endpoints door en 429 geeft Retry-After met ProblemDetails

Nieuwe marker [PublicSiteEndpoint] (deny-by-default): alleen GET /offerings blijft bereikbaar als het CMS uit staat of in onderhoud is; alle andere acties, adminroutes inbegrepen, blijven 503. OnRejected zet Retry-After en schrijft application/problem+json met alleen type, title en status. Op master zijn de limiet-policies nog globale buckets: de contactroutes mogen pas live na de per-client-partitionering van de ASF-branch.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-10 13:07:18 +01:00
co-authored by Claude Sonnet 5.5
parent c3c8bcfd5e
commit a58374abeb
12 changed files with 510 additions and 10 deletions
@@ -171,7 +171,7 @@ public static class ServiceCollectionExtensions
// Without this callback a brute-force attempt against /api/v1/Auth/login returns 429
// and leaves NO trace anywhere — the one rate limiter this application has would be
// entirely unobservable, and the alert rule for it could never fire.
options.OnRejected = (context, _) =>
options.OnRejected = async (context, cancellationToken) =>
{
var logger = context.HttpContext.RequestServices
.GetRequiredService<ILoggerFactory>()
@@ -202,11 +202,24 @@ public static class ServiceCollectionExtensions
var window = configuration.GetValue<int>($"RateLimiting:{section}:WindowSeconds", 60);
waitSeconds = policyName == "refresh" ? window / 4.0 : window;
}
// Every 429 carries a retry hint, also for policies that report no wait (the contact and offerings policies).
waitSeconds ??= 60;
if (waitSeconds is not null)
context.HttpContext.Response.Headers.RetryAfter =
Math.Max(1, (int)Math.Ceiling(waitSeconds.Value)).ToString(System.Globalization.CultureInfo.InvariantCulture);
return ValueTask.CompletedTask;
// Machine-readable body with only the standard type/title/status: nothing about the limiter, the policy or the caller.
await context.HttpContext.Response.WriteAsJsonAsync(
new Microsoft.AspNetCore.Mvc.ProblemDetails
{
Type = "https://www.rfc-editor.org/rfc/rfc6585#section-4",
Title = "Too many requests",
Status = StatusCodes.Status429TooManyRequests,
},
options: null,
contentType: "application/problem+json",
cancellationToken: cancellationToken);
};
// Every named policy is partitioned per client address (ClientPartitionKey). Behind a