diff --git a/scripts/compose-smoke.sh b/scripts/compose-smoke.sh index df6c52b..87339c0 100755 --- a/scripts/compose-smoke.sh +++ b/scripts/compose-smoke.sh @@ -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/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")"