setting arguments from get_uri_args() does not preserve original URI value
We are having an issue with preserving state of our incoming request URI arguments. The goal is to be able to take in the URI args, add some values and then set the request URI args before passing to the backend server.
Example: Incoming request:
GET /?path=my/key HTTP/1.1
Request processing:
local updatedArgs = ngx.req.get_uri_args()
... add to updatedArgs...
ngx.req.set_uri_args(updatedArgs)
Backend sees:
GET /?path=my%2Fkey HTTP/1.1
The get_uri_args() call does not appear to preserve the original URI values so when re-setting it, we end up storing the escaped value and not the original unescaped value to the request uri. Any thoughts on the best way to address this issue?
@davidaah You know that / is required to be properly escaped according to the HTTP standard?
@agentzh thanks! In my original reading of the spec, I think i may have misread the circumstances in which / must be encoded (eg. specifically whether or not it has to be encoded when it is a query parameter as opposed to a part of the request path). to confirm, is this the section you are referring to? (https://www.ietf.org/rfc/rfc2396.txt)
Many URI include components consisting of or delimited by, certain
special characters. These characters are called "reserved", since
their usage within the URI component is limited to their reserved
purpose. If the data for a URI component would conflict with the
reserved purpose, then the conflicting data must be escaped before
forming the URI.
reserved = ";" | "/" | "?" | ":" | "@" | "&" | "=" | "+" |
"$" | ","
The "reserved" syntax class above refers to those characters that are
allowed within a URI, but which may not be allowed within a
particular component of the generic URI syntax; they are used as
delimiters of the components described in Section 3.
Specifically the confusion was around whether Characters other than those in the "reserved" and "unsafe" sets (see RFC 2396 [42]) are equivalent to their ""%" HEX HEX" encoding. (https://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.2.1) implies that / in say a query parameter is not the same as the same request with %2F since / is in the "reserved" set
@davidaah Reserved characters in the URI components should be escaped.
@davidaah If you really want complete control over your querystrings, then you should feed a Lua string value instead of a Lua table to ngx.req.set_uri_args() directly.
awesome! really appreciate the support and feedback. i'm working with my upstream and downstream users to ensure that they properly handle the URL encoding/decoding within their application which will allow me to remain HTTP spec compliant in our implementation