browserup / browserup-proxy

BrowserUp Proxy is a free utility to watch, test, and manipulate web application network traffic and performance.
https://browserup.com
Apache License 2.0
164 stars 41 forks source link

Non Proxy Host still being forwarded to Proxy #364

Open ns-pdimarco opened 3 years ago

ns-pdimarco commented 3 years ago

Describe the bug In version 2.1.1 (2.1.2 missing execution files) The Non Proxy Host specified to the proxy causes an error in browserup-proxy followed by the traffic being forwarded to the specified proxyHost. I tested this with creating a sauce connect proxy (https://wiki.saucelabs.com/display/DOCS/Sauce+Connect+Proxy) that points to a created browserup-proxy proxy.

To Reproduce Steps to reproduce the behavior:

  1. Add Proxy with these settings: {httpNonProxyHosts=[saucelabs.com], trustAllServers=[true], httpProxy=[localhost:8080]}
    [INFO  2021-02-23T10:21:29,548 com.browserup.bup.proxy.bricks.ProxyResource] (qtp1566099239-36) POST /
    [INFO  2021-02-23T10:21:29,549 com.browserup.bup.proxy.bricks.ProxyResource] (qtp1566099239-36) {httpNonProxyHosts=[saucelabs.com], trustAllServers=[true], httpProxy=[localhost:8080]}
    [INFO  2021-02-23T10:35:53,325 org.littleshoot.proxy.impl.DefaultHttpProxyServer] (qtp1566099239-36) Starting proxy at address: 0.0.0.0/0.0.0.0:9091
  2. Start up sauce connect tunnel pointing --proxy to the newly created browserup-proxy proxy. Eg: sc -u $SAUCE_USERNAME -k $SAUCE_ACCESS_KEY --proxy localhost:9091
  3. See error in runtime logs:
    [ERROR 2021-02-23T10:21:30,248 com.browserup.bup.BrowserUpProxyServer] (LittleProxy-0-ClientToProxyWorker-0) The requested URL is not valid. java.net.MalformedURLException: unknown protocol: saucelabs.com
        at java.net.URL.<init>(URL.java:679) ~[?:?]
        at java.net.URL.<init>(URL.java:568) ~[?:?]
        at java.net.URL.<init>(URL.java:515) ~[?:?]
        at com.browserup.bup.BrowserUpProxyServer$2.lookupChainedProxies(BrowserUpProxyServer.java:412) [browserup-proxy-core-2.1.1-SNAPSHOT.jar:?]
        at org.littleshoot.proxy.impl.ProxyToServerConnection.create(ProxyToServerConnection.java:178) [littleproxy-2.0.0-beta-5.jar:?]
        at org.littleshoot.proxy.impl.ClientToProxyConnection.doReadHTTPInitial(ClientToProxyConnection.java:281) [littleproxy-2.0.0-beta-5.jar:?]
        at org.littleshoot.proxy.impl.ClientToProxyConnection.readHTTPInitial(ClientToProxyConnection.java:187) [littleproxy-2.0.0-beta-5.jar:?]
        at org.littleshoot.proxy.impl.ClientToProxyConnection.readHTTPInitial(ClientToProxyConnection.java:55) [littleproxy-2.0.0-beta-5.jar:?]
        at org.littleshoot.proxy.impl.ProxyConnection.readHTTP(ProxyConnection.java:144) [littleproxy-2.0.0-beta-5.jar:?]
        at org.littleshoot.proxy.impl.ProxyConnection.read(ProxyConnection.java:122) [littleproxy-2.0.0-beta-5.jar:?]
        at org.littleshoot.proxy.impl.ProxyConnection.channelRead0(ProxyConnection.java:582) [littleproxy-2.0.0-beta-5.jar:?]
        at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:99) [netty-all-4.1.50.Final.jar:4.1.50.Final]
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379) [netty-all-4.1.50.Final.jar:4.1.50.Final]
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365) [netty-all-4.1.50.Final.jar:4.1.50.Final]
        at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357) [netty-all-4.1.50.Final.jar:4.1.50.Final]
        at io.netty.handler.timeout.IdleStateHandler.channelRead(IdleStateHandler.java:286) [netty-all-4.1.50.Final.jar:4.1.50.Final]
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379) [netty-all-4.1.50.Final.jar:4.1.50.Final]
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365) [netty-all-4.1.50.Final.jar:4.1.50.Final]
        at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357) [netty-all-4.1.50.Final.jar:4.1.50.Final]
        at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:93) [netty-all-4.1.50.Final.jar:4.1.50.Final]
        at org.littleshoot.proxy.impl.ProxyConnection$RequestReadMonitor.channelRead(ProxyConnection.java:709) [littleproxy-2.0.0-beta-5.jar:?]
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379) [netty-all-4.1.50.Final.jar:4.1.50.Final]
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365) [netty-all-4.1.50.Final.jar:4.1.50.Final]
        at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357) [netty-all-4.1.50.Final.jar:4.1.50.Final]
        at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:324) [netty-all-4.1.50.Final.jar:4.1.50.Final]
        at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:296) [netty-all-4.1.50.Final.jar:4.1.50.Final]
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379) [netty-all-4.1.50.Final.jar:4.1.50.Final]
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365) [netty-all-4.1.50.Final.jar:4.1.50.Final]
        at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357) [netty-all-4.1.50.Final.jar:4.1.50.Final]
        at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:93) [netty-all-4.1.50.Final.jar:4.1.50.Final]
        at org.littleshoot.proxy.impl.ProxyConnection$BytesReadMonitor.channelRead(ProxyConnection.java:686) [littleproxy-2.0.0-beta-5.jar:?]
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379) [netty-all-4.1.50.Final.jar:4.1.50.Final]
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365) [netty-all-4.1.50.Final.jar:4.1.50.Final]
        at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357) [netty-all-4.1.50.Final.jar:4.1.50.Final]
        at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410) [netty-all-4.1.50.Final.jar:4.1.50.Final]
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379) [netty-all-4.1.50.Final.jar:4.1.50.Final]
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365) [netty-all-4.1.50.Final.jar:4.1.50.Final]
        at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919) [netty-all-4.1.50.Final.jar:4.1.50.Final]
        at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:163) [netty-all-4.1.50.Final.jar:4.1.50.Final]
        at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:714) [netty-all-4.1.50.Final.jar:4.1.50.Final]
        at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:650) [netty-all-4.1.50.Final.jar:4.1.50.Final]
        at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:576) [netty-all-4.1.50.Final.jar:4.1.50.Final]
        at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:493) [netty-all-4.1.50.Final.jar:4.1.50.Final]
        at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989) [netty-all-4.1.50.Final.jar:4.1.50.Final]
        at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) [netty-all-4.1.50.Final.jar:4.1.50.Final]
        at java.lang.Thread.run(Thread.java:832) [?:?]

Expected behavior Would expect the nonProxyHosts config to not generate errors and not forward traffic to proxy host.

Please complete the following information:

Additional Context May be related to https://github.com/browserup/browserup-proxy/issues/258

mauromol commented 10 months ago

The exception you see is most probably that of #258. Anyway, when a chained proxy is configured and there's a connection error, the logging code prints a log entry saying that an error occurred while trying to connect to the target URL using a chained proxy, even if the target URL is in the no-proxy host configuration. However this log entry is misleading, because I verified that the no-proxy host mechanism does indeed work, it's just the logging code that does a dumb check like "if a chained proxy is configured, than say that the error occurred while connecting through it", disregarding whether it was actually used to make the connection or not.