Contactroutes: rate limiting per client met de ClientPartitionKey van de host
ContactRateLimitPartition.KeyFor gebruikt nu ClientPartitionKey.For(context) in plaats van een vaste sleutel; de test controleert dat verschillende clientadressen verschillende buckets krijgen. ForwardedHeaders:KnownProxies moet op elke host staan die de contactroutes inschakelt. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using SlpModularCms.Core.Hosting.Proxy;
|
||||
using SlpModularCms.Modules.Contact.Data.Entities;
|
||||
|
||||
namespace SlpModularCms.Modules.Contact.Services;
|
||||
@@ -46,16 +47,14 @@ public sealed class NoOpContactMailSender : IContactMailSender
|
||||
/// The single place that decides which rate-limit bucket a request belongs to.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// On the base branch the rate limiter has no per-client partitioning (no forwarded-header
|
||||
/// handling, no client key): every visitor is the same caller. This returns a constant, so the
|
||||
/// contact policies behave as ONE shared bucket per policy, which is why the contact routes are
|
||||
/// disabled (<c>Contact:Enabled=false</c>) until the per-client partitioning from the ASF branch
|
||||
/// has been merged. Switching to per-client is the one-line change documented in the rebase
|
||||
/// checklist: replace the body with <c>ClientPartitionKey.For(context)</c>.
|
||||
/// Every contact policy is partitioned per client, with the same key as the other policies of the
|
||||
/// host (<see cref="ClientPartitionKey"/>: the remote address as seen by the pipeline, the real
|
||||
/// visitor once <c>ForwardedHeaders:KnownProxies</c> is configured). That setting is required on
|
||||
/// every host that enables the contact routes: without it all visitors share the proxy's address,
|
||||
/// i.e. one bucket for the whole site. The routes stay disabled by default
|
||||
/// (<c>Contact:Enabled=false</c>) until that has been checked on the host.
|
||||
/// </remarks>
|
||||
public static class ContactRateLimitPartition
|
||||
{
|
||||
public const string GlobalKey = "global";
|
||||
|
||||
public static string KeyFor(HttpContext context) => GlobalKey;
|
||||
public static string KeyFor(HttpContext context) => ClientPartitionKey.For(context);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user