Skip to content

proxy test: Cover hcexpr, 100-continue, XSS escaping, wstunnel, AJP TE and CRLF smuggling - #1152

Merged
PaulLodge merged 3 commits into
apache:trunkfrom
PaulLodge:port2-proxy
Dec 3, 2026
Merged

PaulLodge merged 3 commits into
apache:trunkfrom
PaulLodge:port2-proxy

Conversation

@PaulLodge

@PaulLodge PaulLodge commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Adding various tests ProxyHCExpri condition test in test_09, an Expect: 100-continue test in test_06, balancer-manager and (moved to the generators module) server-info

Host-header escaping, an AJP Transfer-Encoding smuggling test in test_04, and encoded-CRLF no-smuggling through RewriteRule [P], ProxyPassMatch nocanon and LocationMatch in test_11.


  • This PR does not report or address a security vulnerability
    (see SECURITY.md and
    https://www.apache.org/security/#reporting-a-vulnerability).
  • Code follows the httpd style guide.
  • New log messages (level debug or higher) use an empty APLOGNO() tag;
    numbers are assigned by a committer at merge time (see docs/log-message-tags/README).
  • If the change is user-visible, a changes-entries/*.txt file is included,
    following the template in README.CHANGES (not needed otherwise).
  • Test cases based on pyhttpd are included where appropriate, in the
    test/modules/xxx directory matching the modules/xxx module source,
    or test/modules/core for core server changes. On Unix, verify these
    pass locally with e.g. make check-pytest PYTEST_DIRS=test/modules/xxx.

…E and CRLF smuggling

Adding various tests ProxyHCExpri condition test in test_09,
an Expect: 100-continue test in test_06, balancer-manager
and (moved to the generators module) server-info

Host-header escaping, an AJP Transfer-Encoding smuggling test in
test_04, and encoded-CRLF no-smuggling through RewriteRule [P],
ProxyPassMatch nocanon and LocationMatch in test_11.

Co-Authored-By: Claude Code <noreply@anthropic.com>
@PaulLodge PaulLodge changed the title proxy test: Cover hcexpr, 100-continue, XSS escaping, wstunnel, AJP T… proxy test: Cover hcexpr, 100-continue, XSS escaping, wstunnel, AJP TE and CRLF smuggling Dec 2, 2026
@arturobernalg

arturobernalg commented Dec 2, 2026 •

Copy link
Copy Markdown
Member

Thanks, good coverage overall. Two don't quite hold up though: test_proxy_011_04 (RewriteRule [P], no nocanon) never reaches the backend -- 403 before that, so the assert passes on an empty list. And test_proxy_13_01 only survives because the fake backend hangs up right after answering; a real websocket backend would very likely swallow the pipelined second request into the tunnel instead.

test_proxy_011_04 asserted no-smuggling on an empty backend capture:
RewriteRule [P] matches the decoded URI, so the rewritten query string
holds decoded control characters, which mod_rewrite rejects with 403
(AH10410) before the request is forwarded. Assertng the 403 and that
nothing reaches the backend, and made the 011_05/011_06 asserts more
meaningful by asserting the backend received exactly one request
with the CRLFs still percent-encoded.

test_proxy_13_01 never reached mod_proxy_wstunnel: with proxy_http
loaded, ProxyWebsocketFallbackToProxyHttp defaults to On so
mod_proxy_wstunnel declines, and mod_proxy_http only tunnels after a
101 response, which the fake backend never sends. Test rewritten to
test what it actually exercised -- both pipelined requests answer
when the backend does not upgrade, with the Upgrade headers forwarded.

Add a new test: test_proxy_13_02 with the fallback Off to pin
mod_proxy_wstunnel behavior: with  a verbatim relay, no response for a
pipelined request behind the tunnel, and the client connection closed
once the backend hangs up.

Co-Authored-By: Claude Code <noreply@anthropic.com>
@PaulLodge

PaulLodge commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor Author

Hi @arturobernalg
Thank you for catching these issues, both points are correct.

test_proxy_011_04 now checks what really happens: the request is rejected with 403 before it reaches the backend.
The reason: is_absolute_uri() does not know the proxy: prefix, so will_escape is false for [P] rules, and AH10410 is logged. The test now asserts the 403 and that the backend list is empty. For tests 05 and 06 I have new asserts: the backend must receive exactly one request, with the CRLFs still percent-encoded. So that none of the three tests can now pass on an empty list.

test_proxy_13_01 had a bigger problem: it never used mod_proxy_wstunnel at all.
Because proxy_http is loaded, ProxyWebsocketFallbackToProxyHttp (default On) makes mod_proxy_wstunnel decline the request. mod_proxy_http only creates a tunnel after a 101 response, and the fake backend answers 200, so no tunnel was created. The connection stayed normal HTTP, and that is why the second request was processed.

I changed the test to test this directly: both pipelined requests must be answered, and the Upgrade headers must be forwarded to the backend. After a real 101 the connection is a tunnel, so a pipelined request behind it is tunnel data this behavior is correct and I did not test against it.

Instead I added a new test with ProxyWebsocketFallbackToProxyHttp Off, which uses mod_proxy_wstunnel for real.
It checks that the backend response is forwarded unchanged (no new headers added), that a pipelined request behind the tunnel gets no answer, and that the client connection is closed after the backend closes.

@arturobernalg

Copy link
Copy Markdown
Member

Ran these two against trunk to double check. Good progress, but not quite there yet:

test_proxy_011_05 / 011_06: these are red right now, not flaky. The %0d%0a check is case-sensitive, but curl sends %0D%0A (uppercase), so the assert never matches. Easiest fix is to lowercase before comparing, or build the raw request over a socket like test_13 does instead of going through curl.

test_proxy_13_02: good that it now forces the real tunnel, but the backend only does one recv(), so whether the pipelined bytes show up in that read is a coin flip. Across a few runs I sometimes saw GET /ws2 land in the captured data and sometimes not, and the test passes either way since it only checks the negative side. To actually prove the pipelined request gets swallowed into the tunnel, have the backend keep reading until it sees it (or EOF) and then assert on that. Also, closing the socket with those bytes still unread sends a RST instead of a clean FIN, which risks the response getting dropped before httpd relays it on Windows.

Small one: 011_04 ignores AH10410 in the log but doesn't actually check it's the reason for the 403.

011_05/011_06: the percent-encoded CRLF check is now
case-insensitive; curl re-encodes the URI with upper-case hex on some
platforms, so the lower-case assert never matched there.

011_04: assert the AH10410 rejection is actually logged, so the 403
is pinned to the query-string check and not just to any 403.

13_02: the tunnel backend now keeps reading after answering, until
the pipelined request arrives (or the connection ends), and asserts
it was forwarded into the tunnel to the same backend -- proving the
swallow instead of only checking the client saw no second response.
Draining before the close also keeps the FIN clean; closing with
unread data can surface as a reset and lose the response in flight.
TCPFaker grows an overridable _handle_connection() hook for this.

Co-Authored-By: Claude Code <noreply@anthropic.com>
@PaulLodge

PaulLodge commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor Author

Thank you pointing out the continuing issues with the tests, it's very appreciated

011_05 / 011_06: case-sensitive %0d%0a (the red tests): The assert now compares against faker.all_requests[0].lower().
Verified by simulating CI's behavior, I uppercased the URL encodings to %0D%0A and the tests pass where the old assert failed, then restored.

13_02: coin-flip capture + RST risk: The tunnel backend now overrides a new TCPFaker._handle_connection() hook (minimal scaffolding extension in env.py) to keep reading after answering until the pipelined GET /ws2 arrives, then drains with a short grace timeout before closing.

The test now asserts positively that the pipelined request was forwarded into the tunnel to the same
backend not just that the client saw no second response.

The drain-then-close also fixes the RST concern: the socket is empty when it shuts down, so the FIN is clean on Windows too. Instrumented runs confirmed the keep-reading path is genuinely exercised (first recv = request 1 only,
the pipelined request arrives as a later tunneled chunk, all 3 runs).

011_04: AH10410 not actually checked: Now does the wait_for on the AH10410 "Rewritten query string" line and asserts it's found, so the 403 is pinned to that check rather than any 403.

@arturobernalg arturobernalg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. thank you

@PaulLodge
PaulLodge merged commit 01aaa16 into apache:trunk Dec 3, 2026
46 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants