A scanner rotating through a rented /29 used to cost one row and one write per address: POST /admin-api/blocks answered "not an IP address" for a CIDR while the allowlist control beside it accepted one, and the config export could not carry the operator's answer either. A CIDR now has its own table and is enforced by containment. The rulings: - One list, two shapes. GET /admin-api/blocks merges address rows and range rows and says which is which with `kind`; DELETE ?key= takes the CIDR as it was typed; ?source=engine still cannot reach an operator's range, while ?source=operator clears both operator shapes. - Containment is checked on the raw peer address, the same field the allowlist is matched on, after the exact operator block and before the engine's own ban. The verdict stays block_operator, so nothing downstream had to learn a new reason; the decision trace names the range that answered, and an allow entry still outranks a range. - What is written is normalised before it is stored: 203.0.113.37/28 is stored as 203.0.113.32/28, a /32 or /128 is stored as the bare address it already was, and the full-width prefix is refused on meaning rather than on form — "0.0.0.0/0" covers every address there is, including the one this was written from; that is a shutdown, not a ban on a source. - A request pays for the number of distinct prefix lengths, not for the number of ranges: the index buckets by prefix and asks a set for the request address masked to it, most specific first, and an expired row does not stop the search for a broader live one. - Export carries ranges in the blocks section and import lands them idempotently, so an edge's decisions survive the move. /state counts them apart from address blocks, and the console prints the shape beside the row. What the run caught: - BlockRow read Range?.Field ?? Entry!.Field. The two rows are mutually exclusive, so a range with no expiry, reason or redirect — the common case — dereferenced the row that is not there and GET /admin-api/blocks answered 500. - NetworkBanIndex filed a row under "a.b.c.d/24" while the lookup compared a masked address with no prefix, so no range ever matched: ten unit tests red before the bucket key was fixed to the network address alone. - smoke and compose both wrote their JSON bodies with escaped quotes straight inside a command substitution, which truncates the body and answers 400 — the hazard this file's own header warns about. The payloads are variables now. - Scene ordering in smoke: the range scene clears the engine's list wholesale, which took the expired scanner row a later scene asserts on. It runs after those scenes now, and says why in the file. - Test-side, worth keeping: 203.0.113.37/28 is not the network 203.0.113.16/28 names, so an assertion that writes one and expects the other is testing the mask, not the match. build 0 warnings / 0 errors, unit 334/334, integration 312/312 in 31 s, console 105 assertions 0 failed, smoke passed 137 failed 0, compose 285 passed 0 failed against the built image at 262 MB. Refs OPEN-66.
28 lines
1.3 KiB
C#
28 lines
1.3 KiB
C#
namespace OpenWaf.Domain.Engine;
|
|
|
|
/// <summary>The decision plus everything the response writer and the log need
|
|
/// to explain it. An engine block always carries its reason and expiry: a ban
|
|
/// nobody can explain is a ban nobody can defend.</summary>
|
|
public sealed record EdgeDecision(
|
|
EdgeVerdict Verdict,
|
|
int StatusCode = 0,
|
|
string? Location = null,
|
|
string? Reason = null,
|
|
string? SourceKey = null,
|
|
DateTimeOffset? ExpiresAt = null,
|
|
/// <summary>The pattern that matched, for a rule verdict. The rule id is in
|
|
/// Reason; the pattern is what an operator reads in the log and the alert,
|
|
/// because an id means nothing without the page in front of them.</summary>
|
|
string? RulePattern = null,
|
|
/// <summary>The range that covered this address, for an operator block that
|
|
/// came from a range rather than from the address itself (OPEN-66). The
|
|
/// verdict is the same claim — the operator's list refused this source — and
|
|
/// this is what makes the row that refused it findable.</summary>
|
|
string? Range = null)
|
|
{
|
|
public bool IsBlocked => Verdict is EdgeVerdict.BlockOperator or EdgeVerdict.BlockEngine
|
|
or EdgeVerdict.GeoReject or EdgeVerdict.BlockRule;
|
|
|
|
public static readonly EdgeDecision Pass = new(EdgeVerdict.Pass);
|
|
}
|