@@ -295,47 +295,51 @@ fn test_server_mode() {
295295fn test_host_header_security ( ) {
296296 use std:: process:: Command ;
297297
298- // Define the same curl command that attempts to set a mismatched Host header
298+ // Test with Cloudflare's trace endpoint that clearly shows the Host header
299299 let curl_args = vec ! [
300300 "-s" ,
301301 "-H" ,
302302 "Host: evil.com" ,
303303 "--max-time" ,
304304 "3" ,
305- "http://httpbin.org/headers " ,
305+ "http://www.cloudflare.com/cdn-cgi/trace " ,
306306 ] ;
307307
308- // Test 1: Direct curl execution (without httpjail) - shows the vulnerability
308+ // Test 1: Direct curl execution (without httpjail) - Cloudflare blocks mismatched Host
309309 let direct_result = Command :: new ( "curl" )
310310 . args ( & curl_args)
311311 . output ( )
312312 . expect ( "Failed to execute curl directly" ) ;
313313
314314 let direct_stdout = String :: from_utf8_lossy ( & direct_result. stdout ) ;
315+ // Cloudflare returns an error code (1034) for mismatched Host headers
315316 assert ! (
316- direct_stdout. contains( "\" Host\" : \" evil.com\" " ) ,
317- "Direct curl should pass through the evil.com Host header unchanged"
317+ direct_stdout. contains( "error code: 1034" ) ,
318+ "Direct curl with mismatched Host header should be blocked by Cloudflare with error 1034 (got: {})" ,
319+ direct_stdout
318320 ) ;
319321
320- // Test 2: Same curl command through httpjail - shows the fix
322+ // Test 2: Same curl command through httpjail - should correct the Host header
321323 let httpjail_result = HttpjailCommand :: new ( )
322324 . weak ( )
323325 . js ( "true" ) // Allow all requests
324- . command ( vec ! [ "curl" ] . into_iter ( ) . chain ( curl_args) . collect ( ) )
326+ . command ( vec ! [ "curl" ] . into_iter ( ) . chain ( curl_args. clone ( ) ) . collect ( ) )
325327 . execute ( ) ;
326328
327329 assert ! ( httpjail_result. is_ok( ) , "Httpjail request should complete" ) ;
328330 let ( exit_code, stdout, _) = httpjail_result. unwrap ( ) ;
329331 assert_eq ! ( exit_code, 0 , "Httpjail request should succeed" ) ;
330332
331- // Httpjail should have corrected the Host header to match the URI
333+ // Httpjail should have corrected the Host header, allowing the request to succeed
332334 assert ! (
333- stdout. contains( "\" Host\" : \" httpbin.org\" " ) ,
334- "Httpjail should correct the Host header to httpbin.org"
335+ stdout. contains( "h=www.cloudflare.com" ) ,
336+ "Httpjail should correct the Host header to www.cloudflare.com, allowing the request (got: {})" ,
337+ stdout
335338 ) ;
336339 assert ! (
337- !stdout. contains( "\" Host\" : \" evil.com\" " ) ,
338- "Httpjail should not pass through the evil.com Host header"
340+ !stdout. contains( "error code: 1034" ) ,
341+ "Httpjail-corrected request should not be blocked by Cloudflare (got: {})" ,
342+ stdout
339343 ) ;
340344
341345 // This demonstrates that httpjail prevents the Host header bypass attack
0 commit comments