Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Netflix Zuul query string encoding

Tags:

netflix-zuul

When sending a request via Zuul to a client, Zuul seems to change the query String. More specifically, if the client should receive an url-encoded query String, Zuul decodes the query String once. Here is a concrete example:

If "http://localhost:8080/demo/demo?a=http%3A%2F%2Fsomething/" is sent to the client, the client receives as a query String "a=http://something/".

Looking into Zuul`s code, the function "buildZuulRequestQueryParams" uses "HTTPRequestUtils.getInstance().getQueryParams();" which decodes the query String.

Is this a desired feature or a bug?

like image 950
albert noll Avatar asked Apr 07 '16 12:04

albert noll


People also ask

What language is ZUUL written in?

Zuul's rule engine lets rules and filters be written in essentially any JVM language, with built-in support for Java and Groovy.

How does Netflix ZUUL work?

Zuul is built to enable dynamic routing, monitoring, resiliency, and security. It can also route the requests to multiple Amazon Auto Scaling Groups. For Example, /api/products are mapped to the product service and /api/user is mapped to the user service.

In what order are ZUUL filters executed?

There are four types of standard filters in Zuul: pre for pre-routing filtering, route for routing to an origin, post for post-routing filters, and error for error handling.

Is ZUUL a reverse proxy?

Zuul is the library used to provide the reverse proxy, based on the route it will forward to configure URL or service-id by passing the necessary information.


1 Answers

Zuul actually offers a flag to disable this behavior.

8.9 Query String Encoding When processing the incoming request, query params are decoded so that they can be available for possible modifications in Zuul filters. They are then re-encoded the backend request is rebuilt in the route filters. The result can be different than the original input if (for example) it was encoded with Javascript’s encodeURIComponent() method. While this causes no issues in most cases, some web servers can be picky with the encoding of complex query string.

To force the original encoding of the query string, it is possible to pass a special flag to ZuulProperties so that the query string is taken as is with the HttpServletRequest::getQueryString method, as shown in the following example:

application.yml.

 zuul:
  forceOriginalQueryStringEncoding: true

[Note] This special flag works only with SimpleHostRoutingFilter. Also, you loose the ability to easily override query parameters with RequestContext.getCurrentContext().setRequestQueryParams(someOverriddenParameters), because the query string is now fetched directly on the original HttpServletRequest.

8. Router and Filter: Zuul

like image 173
Always Learning Avatar answered Oct 14 '22 14:10

Always Learning