namespace OpenWaf.Domain.Security; /// What a matched request rule does. Said as two values because the /// difference is the whole reason an operator can add a rule at all. public enum RequestRuleAction { /// Record the match as an alert and let the request through. This /// is what makes a rule safe to write: an operator can see what it would /// have blocked before it blocks anything. Observe = 0, /// Refuse the request. Fires in Observe mode too — the mode /// switches off what the edge decides by itself, not what a human wrote /// down, which is the same ruling that keeps an operator block live in /// Observe mode. Block = 1 } /// /// A rule about the request itself: a path pattern the edge refuses (or /// records) before the request reaches the application. /// /// (OPEN-54.) Until this existed the edge only ever reacted to what the upstream /// answered — a streak of 4xx/5xx from one source, a country, an operator's /// list. It never looked at the request. That leaves the part of a WAF's job /// nobody else in this design does: refusing a known-bad request before it /// costs the origin anything, and refusing it without first waiting for the /// origin to answer 404 three times. /// /// It is an operator-authored list, not a signature feed: the patterns are /// written by a human who can read the access log, and every one of them is /// visible, editable and removable on the same page that shows the bans. /// public sealed class RequestRule { public long Id { get; init; } /// Glob over the request path — see . /// Anchored, case-insensitive, * and ? only. public string Pattern { get; set; } = string.Empty; public RequestRuleAction Action { get; set; } public string? Note { get; set; } public DateTimeOffset CreatedAt { get; set; } = DateTimeOffset.UtcNow; /// A rule that expires. A path rule written during an active scan /// is usually wrong six weeks later, and nothing in the system will say /// so; the expiry is the part that stops being true on its own. public DateTimeOffset? ExpiresAt { get; set; } public bool IsLive(DateTimeOffset now) => ExpiresAt is null || ExpiresAt > now; }