spring-cloud / spring-cloud-netflix

Integration with Netflix OSS components
http://cloud.spring.io/spring-cloud-netflix/
Apache License 2.0
4.87k stars 2.44k forks source link

Sidecar double-encodes URL instead of passing it to backend #1378

Closed bogdatov closed 8 years ago

bogdatov commented 8 years ago

This is similar issue to this one: https://github.com/spring-cloud/spring-cloud-netflix/issues/366#issuecomment-106363315

I'm using Spring Cloud Brixton.M5 When I call my service like this: https://order-detail-uat.cfappstpanpz2.ebiz.verizon.com/trail/name/I10415%252FOM96%252FCYVLMDCK%252FTWSNMDTW/orders Everything works fine and I'm able to get data back.

But using SideCar: https://service-sidecar-server-uat.cfappstpanpz2.ebiz.verizon.com/order-detail/trail/name/I10415%252FOM96%252FCYVLMDCK%252FTWSNMDTW/orders

I'm not getting data back. When request comes to order-detail service I see this: 2016-10-04T20:05:44.85-0400 [RTR/0] OUT order-detail-test.cfappstpanpz2.ebiz.verizon.com:443 - [05/10/2016:00:05:44.846 +0000] "GET /trail/name/I10415%25252FOM96%25252FCYVLMDCK%25252FTWSNMDTW/orders HTTP/1.1" 401 0 344 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:49.0) Gecko/20100101 Firefox/49.0" 10.73.217.10:37146 x_forwarded_for:"139.49.4.204" x_forwarded_proto:"http" vcap_request_id:c5f8a4fb-4874-45ad-595d-840e3a416811 response_time:0.012254151 app_id:62d11480-216b-4710-9d29-283a6ffbce90

So I see kind of double encoding. That one %25252

I tried to have "pre" filter as described on link above - OriginalRequestUriFilter - same issue.

In SideCar logs I see this (pre filter is enabled) 2016-10-04 20:04:00,166 45336 DEBUG [http-nio-8080-exec-1] o.a.c.http11.InternalNioInputBuffer [DirectJDKLog.java:180] --- Received [GET /order-detail/trail/name/I10415%252FOM96%252FCYVLMDCK%252FTWSNMDTW/orders HTTP/1.1 ..... 2016-10-04 20:04:00,186 45336 DEBUG [http-nio-8080-exec-1] o.a.c.connector.CoyoteAdapter [DirectJDKLog.java:180] --- The variable [uriBC] has value [/order-detail/trail/name/I10415%252FOM96%252FCYVLMDCK%252FTWSNMDTW/orders] .... 2016-10-04 20:04:00,355 45336 DEBUG [http-nio-8080-exec-1] o.s.c.n.zuul.web.ZuulHandlerMapping [AbstractUrlHandlerMapping.java:220] --- URI Template variables for request [/order-detail/trail/name/I10415%2FOM96%2FCYVLMDCK%2FTWSNMDTW/orders] are {} 2016-10-04 20:04:00,356 45336 DEBUG [http-nio-8080-exec-1] o.s.c.n.zuul.web.ZuulHandlerMapping [AbstractUrlHandlerMapping.java:141] --- Mapping [/order-detail/trail/name/I10415%2FOM96%2FCYVLMDCK%2FTWSNMDTW/orders] to HandlerExecutionChain with handler [org.springframework.cloud.netflix.zuul.web.ZuulController@50aebbed] and 1 interceptor 2016-10-04 20:04:00,358 45336 DEBUG [http-nio-8080-exec-1] o.s.web.servlet.DispatcherServlet [DispatcherServlet.java:947] --- Last-Modified value for [/order-detail/trail/name/I10415%252FOM96%252FCYVLMDCK%252FTWSNMDTW/orders] is: -1 2016-10-04 20:04:00,408 45336 DEBUG [http-nio-8080-exec-1] c.v.u.s.s.s.f.OriginalRequestUriFilter [OriginalRequestUriFilter.java:34] --- requestURI:/order-detail/trail/name/I10415%252FOM96%252FCYVLMDCK%252FTWSNMDTW/orders 2016-10-04 20:04:00,411 45336 DEBUG [http-nio-8080-exec-1] o.s.c.n.z.f.SimpleRouteLocator [SimpleRouteLocator.java:86] --- Finding route for path: /order-detail/trail/name/I10415%2FOM96%2FCYVLMDCK%2FTWSNMDTW/orders 2016-10-04 20:04:00,413 45336 DEBUG [http-nio-8080-exec-1] o.s.c.n.z.f.SimpleRouteLocator .... [SimpleRouteLocator.java:188] --- adjustedPath=/order-detail/trail/name/I10415%2FOM96%2FCYVLMDCK%2FTWSNMDTW/orders ... 2016-10-04 19:44:31,454 46008 DEBUG [http-nio-8080-exec-1] c.n.l.LoadBalancerContext [LoadBalancerContext.java:477] --- order-detail using LB returned Server: order-detail-test.cfappstpanpz2.ebiz.verizon.com:order-detail:deb49ace-c000-49e6-5be4-4f53fb90cd51 for request /trail/name/I10415%252FOM96%252FCYVLMDCK%252FTWSNMDTW/orders ... 2016-10-04 19:44:31,653 46008 DEBUG [http-nio-8080-exec-1] o.a.h.i.c.DefaultHttpClientConnectionOperator [DefaultHttpClientConnectionOperator.java:138] --- Connection established 139.49.4.204:56049<->10.73.217.237:443 2016-10-04 19:44:31,653 46008 DEBUG [http-nio-8080-exec-1] o.a.h.impl.execchain.MainClientExec ..... AND now somehow %252 gets converted to %25252 !!!!

[MainClientExec.java:255] --- Executing request GET /trail/name/I10415%25252FOM96%25252FCYVLMDCK%25252FTWSNMDTW/orders HTTP/1.1 2016-10-04 19:44:31,654 46008 DEBUG [http-nio-8080-exec-1] o.a.h.impl.execchain.MainClientExec [MainClientExec.java:260] --- Target auth state: UNCHALLENGED 2016-10-04 19:44:31,654 46008 DEBUG [http-nio-8080-exec-1] o.a.h.impl.execchain.MainClientExec [MainClientExec.java:266] --- Proxy auth state: UNCHALLENGED 2016-10-04 19:44:31,655 46008 DEBUG [http-nio-8080-exec-1] org.apache.http.headers [LoggingManagedHttpClientConnection.java:135] --- http-outgoing-0 >> GET /trail/name/I10415%25252FOM96%25252FCYVLMDCK%25252FTWSNMDTW/orders HTTP/1.1 .... 2016-10-04 19:44:31,659 46008 DEBUG [http-nio-8080-exec-1] org.apache.http.headers [LoggingManagedHttpClientConnection.java:138] --- http-outgoing-0 >> Connection: Keep-Alive 2016-10-04 19:44:31,660 46008 DEBUG [http-nio-8080-exec-1] org.apache.http.wire [Wire.java:72] --- http-outgoing-0 >> "GET /trail/name/I10415%25252FOM96%25252FCYVLMDCK%25252FTWSNMDTW/orders HTTP/1.1[\r][\n]" 2016-10-04 19:44:31,661 46008 DEBUG [http-nio-8080-exec-1] org.apache.http.wire [Wire.java:72] --- http-outgoing-0 >> "user-agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:49.0) Gecko/20100101 Firefox/49.0[\r][\n]" 2016-10-04 19:44:31,661 46008 DEBUG [http-nio-8080-exec-1] org.apache.http.wire [Wire.java:72] --- http-outgoing-0 >> "accept: text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8[\r][\n]" 2016-10-04 19:44:31,662 46008 DEBUG [http-nio-8080-exec-1] org.apache.http.wire [Wire.java:72] --- http-outgoing-0 >> "accept-language: en-US,en;q=0.5[\r][\n]"

How do I fix this ?

bogdatov commented 8 years ago

This is "pre" filter I have

@Component
public class OriginalRequestUriFilter extends ZuulFilter {
    private static Logger LOGGER = LoggerFactory.getLogger(OriginalRequestUriFilter.class);

    @Override
    public String filterType() {
        return "pre";
    }

    @Override
    public int filterOrder() {
        return Integer.MIN_VALUE;
    }

    @Override
    public boolean shouldFilter() {
        return true;
    }

    @Override
    public Object run() {
        RequestContext context = RequestContext.getCurrentContext();
        LOGGER.debug("requestURI:{}", context.getRequest().getRequestURI());
        //context.put("requestURI", context.getRequest().getRequestURI());
        try
        {
            String uriDecoded1=URLDecoder.decode(context.getRequest().getRequestURI().toString(), "UTF-8"); 
            LOGGER.info("uriDecoded1: {}", uriDecoded1);    
            //String uriDecoded2=URLDecoder.decode(new URI(uriDecoded1).toString(), "UTF-8"); 
            //LOGGER.info("uriDecoded2: {}", uriDecoded2);    

            //context.put("requestURI", uriDecoded1);
            context.put("requestURI", context.getRequest().getRequestURI());
        }
        catch(Exception e) {
            LOGGER.error("exception:",e);
        }
        return null;
    }
}
spencergibb commented 8 years ago

Many things have changed since Spring Cloud Brixton.M5. We are now on Camden.RELEASE. Feel free to reopen if you find issues with the latest release.

Chinna-SHS commented 7 years ago

Used the Camden.SR3 and still seeing the same issue. Slash(/) is decoded while passing to my target service via zuul proxy.

Fix is to override the ProxyRequestHelper.buildZuulRequestURI method to exclude the encoding again in zuul and just pass the url from client as it is.