Opened 4 weeks ago

Closed 4 weeks ago

#2003 closed defect (invalid)

regex generated variable loses character encoding when used in proxypass rule

Reported by: excudo@… Owned by:
Priority: minor Milestone:
Component: documentation Version: 1.19.x
Keywords: Cc:
uname -a: Linux [[removed the host]] 2.6.32-696.1.1.el6.x86_64 #1 SMP Tue Apr 11 17:13:24 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
nginx -V: nginx version: nginx/1.12.0
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-17) (GCC)
built with OpenSSL 1.0.1e-fips 11 Feb 2013
TLS SNI support enabled
configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/ --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie'


I had exactly the same problem as is described in this stackoverflow post:

The proxypass was towards tomcat and in those logs I could see that everything after the (originally encoded) space went missing. Even the HTTP/1.1 part, which caused it to throw a 505.

I can confirm the workaround mentioned in the answers (to assign it to a new variable) works. But this should be fixed structurally, without the need for a workaround.

Change History (1)

comment:1 by Maxim Dounin, 4 weeks ago

Resolution: invalid
Status: newclosed

The stackoveflow post uses a part of the unencoded URI as used in location matching. Quoting docs:

The matching is performed against a normalized URI, after decoding the text encoded in the “%XX” form, resolving references to relative path components “.” and “..”, and possible compression of two or more adjacent slashes into a single slash.

That is, a configuration like:

location ~ /api/search(/.*) {

is expected to produce incorrect requests to proxied server. One is expected to use properly encoded variables when using variables in proxy_pass, and this might not be trivial to do. In this particular case, a better solution might be to use a much simpler configuration without variables:

location ~ /api/search/ {

In more complex cases using rewrite ... break; followed by a proxy_pass without an URI component is usually the simplest solution.

Note well that the "workaround" with using set mentioned on the stackoverflow is actually a misuse of a bug (#348). Avoid using it.

Note: See TracTickets for help on using tickets.