Opened 7 years ago

Closed 7 years ago

#1371 closed defect (duplicate)

some url contains space will be treated as invalid

Reported by: Alex Zhang Owned by:
Priority: minor Milestone:
Component: nginx-module Version: 1.13.x
Keywords: ngx_http_parse_request_line Cc:
uname -a: Linux Fedora26-64 4.12.5-300.fc26.x86_64 #1 SMP Mon Aug 7 15:27:25 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
nginx -V: nginx version: nginx/1.13.4
built by gcc 7.1.1 20170622 (Red Hat 7.1.1-3) (GCC)
configure arguments: --prefix=/home/alex/bin_install/nginx



So i have two url, both of them contain the space, one is "/foo/blah Hello", and the other is "/foo/blah Yeah", i found the former will be treated as invalid and got the 400 Bad Request while the latter doesn't.

You can reproduce this by the following configuration.

server {
    listen 8082;
    server_name _;

    location /foo/blah {
        return 200;
curl -I " Hello"
HTTP/1.1 400 Bad Request
Server: nginx/1.13.4
Date: Wed, 30 Aug 2017 02:31:33 GMT
Content-Type: text/html
Content-Length: 173
Connection: close
curl -I " Yeah"
HTTP/1.1 200 OK
Server: nginx/1.13.4
Date: Wed, 30 Aug 2017 02:31:53 GMT
Content-Type: application/octet-stream
Content-Length: 0
Connection: keep-alive

I found the reason is that when space in uri and the next character after the space is 'H', function ngx_http_parse_request_line will try to match the word HTTP, so 'T' is expected after 'H', otherwise NGX_HTTP_PARSE_INVALID_REQUEST will be returned so 400 Bad Request will be printed.

I'm wondering if this is a bug or just the expected behavior?

Change History (1)

comment:1 by Maxim Dounin, 7 years ago

Resolution: duplicate
Status: newclosed

Both URLs are invalid, you should encode space as %20. Duplicate of #196.

Note: See TracTickets for help on using tickets.