Opened 4 years ago

Closed 3 years ago

#1043 closed defect (duplicate)

URL encoded change regex match result

Reported by: David Rousselie Owned by:
Priority: minor Milestone:
Component: other Version: 1.10.x
Keywords: Cc:
uname -a: Linux cache01-devfe 3.13.0-40-generic #69-Ubuntu SMP Thu Nov 13 17:53:56 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
nginx -V: nginx version: nginx/1.10.0
built by gcc 4.8.4 (Ubuntu 4.8.4-2ubuntu1~14.04)
built with OpenSSL 1.0.2h 3 May 2016
TLS SNI support enabled
configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib/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/nginx.pid --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-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_stub_status_module --with-http_auth_request_module --with-http_xslt_module=dynamic --with-http_image_filter_module=dynamic --with-http_geoip_module=dynamic --with-http_perl_module=dynamic --add-dynamic-module=debian/extra/njs-1c50334fbea6/nginx --with-threads --with-stream --with-stream_ssl_module --with-http_slice_module --with-mail --with-mail_ssl_module --with-file-aio --with-ipv6 --add-module=/tmp/ngx_http_enhanced_memcached_module --add-module=/tmp/headers-more-nginx-module --with-openssl=/openssl-1.0.2h --add-module=/tmp/lua-nginx-module --add-module=/tmp/ngx_devel_kit --add-module=/tmp/lua-upstream-nginx-module --with-http_v2_module --with-cc-opt='-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security' --with-ld-opt='-Wl,-Bsymbolic-functions -Wl,-z,relro'

Description

I am trying to ignore some URL parameters to compute a cache key with this kind of code:

set $cache_args $args;

if ($cache_args ~ (.*)(?:&|^)utm_source=[^&]*(.*)) {
  set $cache_args $1$2;
}

if ($cache_args ~ (.*)(?:&|^)utm_content=[^&]*(.*)) {
  set $cache_args $1$2;
}
...

It works until Nginx receive a request with URL encoded chars in its path.
For example, /%EE?utm_content=1&utm_source=2&arg1=3:

  • The first regex (.*)(?:&|^)utm_source=[^&]*(.*) will match but $2 will be %26arg1=3 whereas it is &arg1=3 when there is no chars URL encoded in the path. $cache_args is then set to utm_content=1%26arg1=3
  • Following regex (.*)(?:&|^)utm_content=[^&]*(.*) will then match utm_content=[^&]* as the whole value utm_content=1%26arg1=3 instead of just utm_content=1. Thus the new value set to $cache_args will be empty instead of &arg1=3.

Change History (1)

comment:1 by Maxim Dounin, 3 years ago

Resolution: duplicate
Status: newclosed

Duplicate of #348.

Note: See TracTickets for help on using tickets.