Contactmodule: token- en inzendroute met spamafhandeling, idempotentie en retentietaak

Nieuwe module SlpModularCms.Modules.Contact met eigen DbContext en migratie InitialCreate. GET contact-messages/token en POST contact-messages zijn publiek ([PublicSiteEndpoint]), geven bij echte inzendingen, spam en herhalingen hetzelfde 202 en slaan spam apart op (30 dagen, dagplafond). Standaard staat de module uit (Contact:Enabled=false, 404 met lege body, geen databasetoegang) totdat de rate limiting per client op de basisbranch staat; de rate-limit-sleutel zit in een enkele functie zodat dat later een regel wijzigen is. Mail zit achter een seam (nog een no-op).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-10 13:07:27 +01:00
co-authored by Claude Sonnet 5.5
parent 0f6f5475a1
commit 7748bbe9c9
37 changed files with 3266 additions and 9 deletions
@@ -0,0 +1,61 @@
using Microsoft.AspNetCore.Http;
using SlpModularCms.Modules.Contact.Data.Entities;
namespace SlpModularCms.Modules.Contact.Services;
/// <summary>
/// Verifies a captcha token server-side. Implementations must fail open: when the provider
/// itself is unreachable they return <c>true</c> (and log without personal data), so real
/// visitors are never locked out by a provider outage.
/// </summary>
public interface ICaptchaVerifier
{
Task<bool> VerifyAsync(string? captchaToken, CancellationToken cancellationToken);
}
/// <summary>Used while no captcha is configured: everything passes.</summary>
public sealed class NullCaptchaVerifier : ICaptchaVerifier
{
public Task<bool> VerifyAsync(string? captchaToken, CancellationToken cancellationToken) => Task.FromResult(true);
}
public enum ContactMailOutcome
{
/// <summary>No mail was attempted (no sender available yet); the message stays pending.</summary>
Skipped,
Sent,
Failed,
}
/// <summary>
/// Sends the notification mail for a genuine message. Called after the message is stored; a
/// failure must never fail the request. The real implementation arrives with the mail unit.
/// </summary>
public interface IContactMailSender
{
Task<ContactMailOutcome> SendAsync(ContactMessage message, CancellationToken cancellationToken);
}
public sealed class NoOpContactMailSender : IContactMailSender
{
public Task<ContactMailOutcome> SendAsync(ContactMessage message, CancellationToken cancellationToken)
=> Task.FromResult(ContactMailOutcome.Skipped);
}
/// <summary>
/// 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>.
/// </remarks>
public static class ContactRateLimitPartition
{
public const string GlobalKey = "global";
public static string KeyFor(HttpContext context) => GlobalKey;
}