namespace OpenWaf.Domain.Security;
///
/// How long an operator-authored note may be, and how long an exemption may
/// last. Said once, next to the reason.
///
/// The fields the attacker writes are already bounded — the path an observation
/// keeps is truncated to 512 and the User-Agent to 256 — while the fields the
/// operator writes were not bounded at all: a 1 MB reason and a 1 MB note were
/// both accepted with 204, and the listings then returned ~1,000,287 and
/// ~1,000,722 bytes for a handful of rows. The console renders every reason into
/// a table cell, so "unbounded" there means a page that cannot be read.
///
/// The expiry bound is the same class of mistake with sharper edges. The old
/// shape — `is > 0 ? UtcNow.AddMinutes(n) : null` — made `expiresInMinutes: 0`
/// and `expiresInMinutes: -5` mean "never expires", silently, on the one control
/// that outranks every ban in the system. A form that sends 0 for an empty field
/// does not create a short exemption; it creates a permanent one.
///
public static class EntryLimits
{
/// An operator's note about why a source is blocked or allowlisted.
/// 512 is the budget the attacker-controlled path field already gets, so the
/// two columns in the same table are the same size.
public const int NoteMaxLength = 512;
/// 10 years. Long enough that "until this contract ends" is
/// expressible; short enough that a permanent exemption is a thing you have
/// to say on purpose by leaving the field out.
public const int ExpiresInMinutesMin = 1, ExpiresInMinutesMax = 5_256_000;
public static bool NoteOk(string? value) => value is null || value.Length <= NoteMaxLength;
public static bool ExpiresInMinutesOk(int value) =>
value >= ExpiresInMinutesMin && value <= ExpiresInMinutesMax;
}