Opened 4 months ago
Last modified 3 months ago
#2666 new defect
"Content-Length: 1\t\r\n" is not treated as a valid Content-Length
Reported by: | LI Daobing | Owned by: | |
---|---|---|---|
Priority: | minor | Milestone: | |
Component: | documentation | Version: | 1.18.x |
Keywords: | Cc: | ||
uname -a: | Linux ub122 6.5.0-41-generic #41~22.04.2-Ubuntu SMP PREEMPT_DYNAMIC Mon Jun 3 11:32:55 UTC 2 x86_64 x86_64 x86_64 GNU/Linux | ||
nginx -V: |
nginx version: nginx/1.18.0 (Ubuntu)
built with OpenSSL 3.0.2 15 Mar 2022 TLS SNI support enabled configure arguments: --with-cc-opt='-g -O2 -ffile-prefix-map=/build/nginx-zctdR4/nginx-1.18.0=. -flto=auto -ffat-lto-objects -flto=auto -ffat-lto-objects -fstack-protector-strong -Wformat -Werror=format-security -fPIC -Wdate-time -D_FORTIFY_SOURCE=2' --with-ld-opt='-Wl,-Bsymbolic-functions -flto=auto -ffat-lto-objects -flto=auto -Wl,-z,relro -Wl,-z,now -fPIC' --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 --modules-path=/usr/lib/nginx/modules --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-compat --with-debug --with-pcre-jit --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-http_auth_request_module --with-http_v2_module --with-http_dav_module --with-http_slice_module --with-threads --add-dynamic-module=/build/nginx-zctdR4/nginx-1.18.0/debian/modules/http-geoip2 --with-http_addition_module --with-http_flv_module --with-http_geoip_module=dynamic --with-http_gunzip_module --with-http_gzip_static_module --with-http_image_filter_module=dynamic --with-http_mp4_module --with-http_perl_module=dynamic --with-http_random_index_module --with-http_secure_link_module --with-http_sub_module --with-http_xslt_module=dynamic --with-mail=dynamic --with-mail_ssl_module --with-stream=dynamic --with-stream_geoip_module=dynamic --with-stream_ssl_module --with-stream_ssl_preread_module --add-dynamic-module=/build/nginx-zctdR4/nginx-1.18.0/debian/modules/http-headers-more-filter --add-dynamic-module=/build/nginx-zctdR4/nginx-1.18.0/debian/modules/http-auth-pam --add-dynamic-module=/build/nginx-zctdR4/nginx-1.18.0/debian/modules/http-cache-purge --add-dynamic-module=/build/nginx-zctdR4/nginx-1.18.0/debian/modules/http-dav-ext --add-dynamic-module=/build/nginx-zctdR4/nginx-1.18.0/debian/modules/http-ndk --add-dynamic-module=/build/nginx-zctdR4/nginx-1.18.0/debian/modules/http-echo --add-dynamic-module=/build/nginx-zctdR4/nginx-1.18.0/debian/modules/http-fancyindex --add-dynamic-module=/build/nginx-zctdR4/nginx-1.18.0/debian/modules/nchan --add-dynamic-module=/build/nginx-zctdR4/nginx-1.18.0/debian/modules/rtmp --add-dynamic-module=/build/nginx-zctdR4/nginx-1.18.0/debian/modules/http-uploadprogress --add-dynamic-module=/build/nginx-zctdR4/nginx-1.18.0/debian/modules/http-upstream-fair --add-dynamic-module=/build/nginx-zctdR4/nginx-1.18.0/debian/modules/http-subs-filter |
Description (last modified by )
when visiting nginx with "Content-Length: 2\t\r\n", it will return 400[1] with error log:
2024/07/10 10:08:36 [info] 91882#91882: *111 client sent invalid "Content-Length" header while reading client request headers, client: 127.0.0.1, server: ub122.lidaobing.com, request: "POST / HTTP/1.1", host: "127.0.0.1"
when visit nginx with "Content-Length: 2 \r\n", it will work as expected[2]
the RFC 7230/9112 said SP or HTAB are both valid whitesapce[3]
$ echo -ne "POST / HTTP/1.1\r\nHost: 127.0.0.1\r\nContent-Length: 2\t\r\n\r\n{}" | nc 127.0.0.1 80 HTTP/1.1 400 Bad Request Server: nginx/1.18.0 (Ubuntu) Date: Wed, 10 Jul 2024 17:20:27 GMT Content-Type: text/html Content-Length: 166 Connection: close <html> <head><title>400 Bad Request</title></head> <body> <center><h1>400 Bad Request</h1></center> <hr><center>nginx/1.18.0 (Ubuntu)</center> </body> </html>
$ echo -ne "POST / HTTP/1.1\r\nHost: 127.0.0.1\r\nContent-Length: 2 \r\n\r\n{}" | nc 127.0.0.1 80 HTTP/1.1 200 OK Server: nginx/1.18.0 (Ubuntu) Date: Wed, 10 Jul 2024 17:13:02 GMT Content-Type: text/html Transfer-Encoding: chunked Connection: keep-alive 6 'None' 0
[3]
https://www. rfc-editor.org/rfc/rfc7230#appendix-B
OWS = *( SP / HTAB )
header-field = field-name ":" OWS field-value OWS
https://www. rfc-editor.org/rfc/rfc9112#name-field-syntax
field-line = field-name ":" OWS field-value OWS
OWS = <OWS, see [HTTP], Section 5.6.3>
(in RFC 9110, Section 5.6.3)
OWS = *( SP / HTAB )
; optional whitespace