Files
openwaf/scripts
Pavlo Ratushnyi 00f6dd9513 A block's redirect target went into a header unchecked, and one of them turned the block into a 500
Measured on the shipped image (openwaf:ci). POST /admin-api/blocks answered 204
for every one of these, and the next request from that source paid for it:

  "https://example.com/ok"               301 Location: https://example.com/ok
  "http://bad target"                    301 Location: http://bad target
  "http://x.invalid/<CRLF>X-Injected: 1" 500 Internal Server Error, Content-Length: 0
  "javascript:alert(1)"                  301 Location: javascript:alert(1)
  "not-a-url"                            301 Location: not-a-url

The CRLF row is the defect rather than the wart: Kestrel refuses to write the
header, so the operator's own block — written with a 204 — became a server error
for that visitor. Nothing was injected; the server validated the header, which
is the only part of the old behaviour that was safe. javascript: and data: are
absolute URIs too, and a redirect is a navigation, so those are an execution
request made on the operator's behalf by a string somebody typed into a form.

RedirectTarget.IsSendable is now the one judge: absolute, http(s), no control
characters or surrounding whitespace. The API answers 400 naming the field, and
DecisionEngine ignores a target it cannot send and answers the block's own
default instead — for a row that arrived by a restored backup or a hand edit,
where the API guard never ran.

The console gate also asserts the other half of the same boundary: every value
that came from the API is rendered through esc(), and two of those values are
not authored by the person reading the page — the path in an observation row is
whatever an anonymous visitor asked for, and a block reason is a form field. The
seed now sends a percent-encoded path carrying <img onerror=...> and an operator
block whose reason carries <svg onload=...>, and the page must show both as text
and create no elements from them.

  unit 105 -> 126 (+21: the target table, and the decision point's fallback)
  integration 55 -> 62 (+7: 400 by name for five targets, a valid target
    reaching the wire as 301, and a hand-written row with CRLF answering 301 to
    the default target instead of the 500 it used to answer)
  console 33 -> 37 assertions

Teeth, each measured by removing the thing: esc() reduced to identity in the
shipped page makes the console gate go red with 6 failures, and the page title
becomes "XSS" — the anonymous visitor's path executed script in the operator's
browser. Dropping the API guard fails exactly 5 integration tests; dropping the
decision-point guard fails exactly 6 unit tests and the 1 hand-written-row test.
2026-10-02 00:34:35 +02:00
..