55 lines
2.3 KiB
C#
55 lines
2.3 KiB
C#
namespace OpenWaf.Domain.Security;
|
|
|
|
/// <summary>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.</summary>
|
|
public enum RequestRuleAction
|
|
{
|
|
/// <summary>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.</summary>
|
|
Observe = 0,
|
|
|
|
/// <summary>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.</summary>
|
|
Block = 1
|
|
}
|
|
|
|
/// <summary>
|
|
/// 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.
|
|
/// </summary>
|
|
public sealed class RequestRule
|
|
{
|
|
public long Id { get; init; }
|
|
|
|
/// <summary>Glob over the request path — see <see cref="PathPattern"/>.
|
|
/// Anchored, case-insensitive, <c>*</c> and <c>?</c> only.</summary>
|
|
public string Pattern { get; set; } = string.Empty;
|
|
|
|
public RequestRuleAction Action { get; set; }
|
|
|
|
public string? Note { get; set; }
|
|
|
|
public DateTimeOffset CreatedAt { get; set; } = DateTimeOffset.UtcNow;
|
|
|
|
/// <summary>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.</summary>
|
|
public DateTimeOffset? ExpiresAt { get; set; }
|
|
|
|
public bool IsLive(DateTimeOffset now) => ExpiresAt is null || ExpiresAt > now;
|
|
}
|