The redirect target an edge cannot send is now refused by the shipped image, not only by the test host

OPEN-21's validator had never been driven from the image: the compose
gate wrote a valid redirectTo and asserted the 301, and never once sent
a CRLF, a javascript: or a relative target. Six assertions close that —
400 for each shape, the refusal naming the field, zero rows written for
either address, and both addresses still reaching the upstream
afterwards, which is what "no half-blocked visitor" means when the
block list is read by the next request rather than this one.

Two harness traps found on the way and written into the script: under
set -o pipefail, curl | grep -q reports failure because grep exits on
the first match and curl dies of SIGPIPE — the assertion went red about
a body that said exactly the right sentence; and a case pattern ending
in *) closes an enclosing command substitution, so the first rewrite
printed the rest of the line as the value under test.
This commit is contained in:
Pavlo Ratushnyi
2026-10-02 18:37:34 +02:00
parent e5f4ff041d
commit d871d5791b
+45
View File
@@ -204,6 +204,51 @@ admin -X DELETE "$EDGE/admin-api/blocks?source=engine" >/dev/null
check 'the scanner passes again once its ban is cleared' '404' "$(code -H "$(xff "$SCANNER")" "$EDGE/xmlrpc.php")"
check 'operator block survives the clear' '301' "$(code -H "$(xff "$OFFICE")" "$EDGE/any/path")"
echo '- a redirect target the edge cannot send is refused before it is written'
# OPEN-21 measured this on the shipped image: POST with redirectTo
# "http://x.invalid/<CRLF>X-Injected: 1" answered 204, and the next request from
# that address answered 500 with no Location at all — Kestrel refused to write the
# header, so the block became an outage for that visitor. "javascript:alert(1)"
# answered 204 and then 301 with Location: javascript:alert(1). The integration
# suite proves the guard; what is proven here is that the image an operator
# deploys refuses it too, and that a refused write leaves no half-blocked address
# behind — which is the part that matters, because the block list is read by the
# next request, not by this one.
CRLF_SRC=203.0.113.246
JS_SRC=203.0.113.247
check 'a target with a CRLF in it is refused, not stored' '400' \
"$(code -H "X-Admin-Token: $OPENWAF_ADMIN_TOKEN" -X POST -H 'Content-Type: application/json' \
-d "{\"ip\":\"$CRLF_SRC\",\"reason\":\"crlf target\",\"redirectTo\":\"http://x.invalid/\\r\\nX-Injected: 1\"}" \
"$EDGE/admin-api/blocks")"
# The body is captured first and matched without a pipe into grep -q. Under
# `set -o pipefail` — which this script runs with — `curl | grep -q` reports the
# pipeline as failed: grep exits on the first match, curl dies of SIGPIPE, and
# the assertion reads "no" about a body that says exactly what it says. Measured
# in this very scene: the same request answered the right sentence and the
# assertion still went red.
REFUSED_TARGET=$(admin -X POST -H 'Content-Type: application/json' \
-d "{\"ip\":\"$CRLF_SRC\",\"redirectTo\":\"http://x.invalid/\\r\\nX-Injected: 1\"}" \
"$EDGE/admin-api/blocks")
# Not inside $( ): a case pattern ending in `*)` closes an enclosing command
# substitution, so the first version of this printed the rest of the line as the
# value under test.
names_field=no
case "$REFUSED_TARGET" in
*'redirectTo must be an absolute http(s) URL'*) names_field=yes ;;
esac
check 'and the refusal names the field it refused' 'yes' "$names_field"
check 'a javascript: target is refused too' '400' \
"$(code -H "X-Admin-Token: $OPENWAF_ADMIN_TOKEN" -X POST -H 'Content-Type: application/json' \
-d "{\"ip\":\"$JS_SRC\",\"redirectTo\":\"javascript:alert(1)\"}" "$EDGE/admin-api/blocks")"
check 'a relative target is refused too' '400' \
"$(code -H "X-Admin-Token: $OPENWAF_ADMIN_TOKEN" -X POST -H 'Content-Type: application/json' \
-d "{\"ip\":\"$JS_SRC\",\"redirectTo\":\"not-a-url\"}" "$EDGE/admin-api/blocks")"
check 'neither address was written as a block at all' '0' \
"$(admin "$EDGE/admin-api/blocks?live=false" \
| jcount "b['sourceKey']=='$CRLF_SRC' or b['sourceKey']=='$JS_SRC'")"
check 'and both still reach the upstream, which is what no half-blocked visitor means' '404 404' \
"$(code -H "$(xff "$CRLF_SRC")" "$EDGE/any/path") $(code -H "$(xff "$JS_SRC")" "$EDGE/any/path")"
echo '- allowlist outranks the operator block'
admin -X POST -H 'Content-Type: application/json' -d "{\"match\":\"$OFFICE\",\"note\":\"smoke\"}" "$EDGE/admin-api/allow" >/dev/null
check 'allowlisted source gets through' '404' "$(code -H "$(xff "$OFFICE")" "$EDGE/any/path")"