ParseSource mapped any unrecognised string to BlockSource.Operator. Measured on
the shipped image (openwaf:ci), with two operator blocks and three engine bans
live:
GET /admin-api/blocks?source=enigne -> 200, the operator list, engine bans hidden
DELETE /admin-api/blocks?source=enigne -> 200 {"deleted":1}, then operator=0 engine=3
The caller who mistyped "engine" while clearing automatic bans erased the
operator's hand-maintained list instead — the exact failure the comment above
that endpoint says the provenance parameter exists to prevent. A missing source
was already refused with 400; a misspelled one was not.
After the fix, same image, same script:
GET ?source=enigne -> 400 source must be operator|engine|all; got "enigne"
DELETE ?source=enigne -> 400, counts unchanged (operator=2 engine=3)
DELETE ?source=engine -> 200 {"deleted":3}, then operator=2 engine=0
Two more of the same family, both measured on the image:
expiresInMinutes: 0 and -5 -> 204 with expiresAt: null. Not "no expiry given",
but a permanent allow entry — the one control that outranks every ban — from
a field left at zero. Absent is now the only way to say never; present must
be 1..5256000 or it is a 400. The console page refuses 0 in the field before
the round trip, and the gate asserts both halves: 0 is refused, empty still
means never.
a 1 MB reason and a 1 MB note -> 204, and the listings then returned
~1,000,287 and ~1,000,722 bytes for a handful of rows. Operator notes are
bounded at 512 characters, the budget the attacker-written path field
already gets, so the two columns in the same table are the same size.
unit 126/126 (unchanged), integration 62 -> 73 (+11), console 37 -> 39
Teeth, each measured by putting the old line back: old ParseSource -> exactly 5
integration tests fail; expiry guard off -> exactly 3; length guards off ->
exactly 1.
36 lines
1.8 KiB
C#
36 lines
1.8 KiB
C#
namespace OpenWaf.Domain.Security;
|
|
|
|
/// <summary>
|
|
/// 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.
|
|
/// </summary>
|
|
public static class EntryLimits
|
|
{
|
|
/// <summary>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.</summary>
|
|
public const int NoteMaxLength = 512;
|
|
|
|
/// <summary>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.</summary>
|
|
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;
|
|
}
|