Welcome! Log In Create A New Profile

Advanced

Re: partial urlEncoding when using if and $request_uri

Maxim Dounin
November 11, 2013 11:04AM
Hello!

On Mon, Nov 11, 2013 at 09:51:01AM -0500, mte03 wrote:

> Hi,
>
> I have observed strange behavior with nginx rewrites. What happens: I get
> request going to myserver.com/appID/path1/path2/uglyID and I need to proxy
> this to appID.backend.internal/path1/path2/uglyID. The uglyID is URL encoded
> because it contains characters like commas and forward slashes. When I do
> location matching in nginx, nginx will url decode $uri parameter on which it
> does matches. That's not a problem, when the location matches, I can extract
> the appID and then extract the rest from $request_uri. And here the issue
> happens. If I use:
>
> if ($request_uri ~ ^/[^\/]+(/.*)$ ) { set $path $1; }, the uglyID (but only
> uglyID) gets URL encoded again. The $path simply is
> /path1/path2/urlEncoded(uglyID). However, when I do
>
> if ($uri ~ ^/[^\/]+(/.*)$ ) { set $path $1; }, then $path will be the
> urlDecoded(/path1/path2/uglyID) - as expected.
>
> I have tested this on ubuntu 12.04 (Linux ip-10-50-20-57 3.2.0-36-virtual
> #57-Ubuntu SMP Tue Jan 8 22:04:49 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux)
> and nginx versions nginx/1.1.19 and nginx/1.5.6 - and the behavior is
> consistently same in both versions. The nginx config is identical in all
> cases, only difference is the name of the variable in the if statement,
> where using $request_uri simply implies uglyID (but only uglyID - not the
> whole matched string) will be url encoded again. Meanwhile I have found
> possible workaround using maps, where matching on $request_uri works
> correctly and doesn't modify matched data anyhow.
>
> So I wonder, has anyone else experienced this? Is this expected? Why is the
> uglyID (but only uglyID) url encoded again? I would expect either
> urlEncoding of the whole match, or none at all - as it doesn't happen when I
> try to match e.g. $uri... Could this indicate a possible bug?

Yes, this looks like a bug. Here is a ticket we already have for
this:

http://trac.nginx.org/nginx/ticket/348

--
Maxim Dounin
http://nginx.org/en/donation.html

_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

partial urlEncoding when using if and $request_uri

mte03 November 11, 2013 09:51AM

Re: partial urlEncoding when using if and $request_uri

mte03 November 11, 2013 11:01AM

Re: partial urlEncoding when using if and $request_uri

Maxim Dounin November 11, 2013 11:04AM

Re: partial urlEncoding when using if and $request_uri

mte03 November 11, 2013 11:35AM

Re: partial urlEncoding when using if and $request_uri

Maxim Dounin November 11, 2013 12:34PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 306
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready