Opened 9 years ago

Closed 9 years ago

#876 closed defect (invalid)

POST error_page handling sends bad GET request with content-length

Reported by: valhallasw@… Owned by:
Priority: minor Milestone:
Component: nginx-core Version: 1.9.x
Keywords: Cc:
uname -a: Linux tools-proxy-01 4.2.0-0.bpo.1-amd64 #1 SMP Debian 4.2.6-3~bpo8+2 (2015-12-14) x86_64 GNU/Linux
nginx -V: nginx version: nginx/1.9.4
built with OpenSSL 1.0.2d 9 Jul 2015
TLS SNI support enabled
configure arguments: --with-cc-opt='-g -O2 -fPIE -fstack-protector-strong -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2' --with-ld-opt='-fPIE -pie -Wl,-z,relro -Wl,-z,now' --prefix=/usr/share/nginx --conf-path=/etc/nginx/nginx.conf --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --lock-path=/var/lock/nginx.lock --pid-path=/run/nginx.pid --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --with-debug --with-pcre-jit --with-ipv6 --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-http_auth_request_module --with-http_addition_module --with-http_dav_module --with-http_flv_module --with-http_geoip_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_image_filter_module --with-http_mp4_module --with-http_perl_module --with-http_random_index_module --with-http_secure_link_module --with-http_spdy_module --with-http_sub_module --with-http_xslt_module --with-mail --with-mail_ssl_module --with-stream --with-stream_ssl_module --with-threads --add-module=/tmp/buildd/nginx-1.9.4/debian/modules/headers-more-nginx-module --add-module=/tmp/buildd/nginx-1.9.4/debian/modules/nginx-auth-pam --add-module=/tmp/buildd/nginx-1.9.4/debian/modules/nginx-cache-purge --add-module=/tmp/buildd/nginx-1.9.4/debian/modules/nginx-dav-ext-module --add-module=/tmp/buildd/nginx-1.9.4/debian/modules/nginx-development-kit --add-module=/tmp/buildd/nginx-1.9.4/debian/modules/nginx-echo --add-module=/tmp/buildd/nginx-1.9.4/debian/modules/ngx-fancyindex --add-module=/tmp/buildd/nginx-1.9.4/debian/modules/nginx-http-push --add-module=/tmp/buildd/nginx-1.9.4/debian/modules/nginx-lua --add-module=/tmp/buildd/nginx-1.9.4/debian/modules/nginx-upload-progress --add-module=/tmp/buildd/nginx-1.9.4/debian/modules/nginx-upstream-fair --add-module=/tmp/buildd/nginx-1.9.4/debian/modules/ngx_http_substitutions_filter_module

Description

Downstream bug: https://phabricator.wikimedia.org/T123136

Basic setup:

        error_page 500 /admin/?500;
        proxy_pass $backend;
        proxy_intercept_errors on;

The full config, although as puppet template (so there's a few stray <%'s): https://github.com/wikimedia/operations-puppet/blob/production/modules/dynamicproxy/templates/urlproxy.conf

If a POST with content to a page causes an HTTP/500, the entire request, including content-length and data, is passed to /admin/?500, as GET request.

For example, the original request

POST /gerrit-reviewer-bot/trigger400.php HTTP/1.1
Host: tools.wmflabs.org
Content-Length: 18
(...)


boo=fdsfdsafdsafda

is proxied to the correct location, which then returns HTTP/500. Nginx then sends the following request:

GET /admin/?500 HTTP/1.1
Host: tools.wmflabs.org
(...all other headers that were present in the original...)

boo=fdsfdsafdsafda

which lighttpd (the backend server) rejects (HTTP/400 Bad Request), so the error cannot be handled.

Change History (1)

comment:1 by Maxim Dounin, 9 years ago

Resolution: invalid
Status: newclosed

This is expected behaviour. When a request is redirected to another URI using the error_page directive, its method is changed to GET (except for HEAD requests). No other changes are made though, including changes to the request body.

If you want to handle error_page using a backend, and the backend is unable to handle GET requests with body, consider the following options:

  • If you want nginx to drop request body, consider using proxy_set_body to do so (alternatively, use proxy_pass_request_body off; proxy_set_header Content-Length "";).
  • If you want nginx to preserve original request method, consider using error_page with a named location instead.
Note: See TracTickets for help on using tickets.