@@ -450,6 +450,70 @@ async def test_http_proxy(bbot_scanner, bbot_httpserver, proxy_server):
450450 await scan ._cleanup ()
451451
452452
453+ @pytest .mark .asyncio
454+ async def test_http_proxy_exclude (bbot_scanner , bbot_httpserver , proxy_server ):
455+ """Verify that requests to excluded hosts bypass the proxy."""
456+ endpoint = "/test_http_proxy_exclude"
457+ url = bbot_httpserver .url_for (endpoint )
458+ bbot_httpserver .expect_request (uri = endpoint ).respond_with_data ("proxy_exclude_works" )
459+
460+ proxy_address = f"http://127.0.0.1:{ proxy_server .server_address [1 ]} "
461+ # Exclude 127.0.0.1 from proxy
462+ scan = bbot_scanner (
463+ "127.0.0.1" ,
464+ config = {
465+ "web" : {
466+ "http_proxy" : proxy_address ,
467+ "http_proxy_exclude" : ["127.0.0.1" ],
468+ }
469+ },
470+ )
471+
472+ await scan ._prep ()
473+
474+ proxy_server .RequestHandlerClass .urls .clear ()
475+ r = await scan .helpers .request (url )
476+
477+ # Request should NOT go through proxy
478+ assert len (proxy_server .RequestHandlerClass .urls ) == 0 , "Request should have bypassed proxy but went through it"
479+ assert r .status_code == 200 and r .text == "proxy_exclude_works"
480+
481+ await scan ._cleanup ()
482+
483+
484+ @pytest .mark .asyncio
485+ async def test_http_proxy_exclude_passthrough (bbot_scanner , bbot_httpserver , proxy_server ):
486+ """Verify that non-excluded hosts still go through the proxy."""
487+ endpoint = "/test_proxy_passthrough"
488+ url = bbot_httpserver .url_for (endpoint )
489+ bbot_httpserver .expect_request (uri = endpoint ).respond_with_data ("passthrough_works" )
490+
491+ proxy_address = f"http://127.0.0.1:{ proxy_server .server_address [1 ]} "
492+ # Exclude a different host, not the one we're requesting
493+ scan = bbot_scanner (
494+ "127.0.0.1" ,
495+ config = {
496+ "web" : {
497+ "http_proxy" : proxy_address ,
498+ "http_proxy_exclude" : ["10.0.0.0/8" ],
499+ }
500+ },
501+ )
502+
503+ await scan ._prep ()
504+
505+ proxy_server .RequestHandlerClass .urls .clear ()
506+ r = await scan .helpers .request (url )
507+
508+ # Request SHOULD go through proxy (127.0.0.1 not in exclusion list)
509+ assert len (proxy_server .RequestHandlerClass .urls ) == 1 , (
510+ f"Request to { url } should have gone through proxy but didn't"
511+ )
512+ assert r .status_code == 200 and r .text == "passthrough_works"
513+
514+ await scan ._cleanup ()
515+
516+
453517@pytest .mark .asyncio
454518async def test_http_ssl (bbot_scanner , bbot_httpserver_ssl ):
455519 endpoint = "/test_http_ssl"
0 commit comments