summaryrefslogtreecommitdiffhomepage
path: root/src/http/ngx_http_parse.c (follow)
AgeCommit message (Collapse)AuthorFilesLines
2024-09-13Proxy: proxy_pass_trailers directive.Sergey Kandaurov1-1/+10
The directive allows to pass upstream response trailers to client.
2023-11-28HTTP: removed unused r->port_start and r->port_end.Vladimir Khomutov1-3/+0
Neither r->port_start nor r->port_end were ever used. The r->port_end is set by the parser, though it was never used by the following code (and was never usable, since not copied by the ngx_http_alloc_large_header_buffer() without r->port_start set).
2022-05-30Reworked multi headers to use linked lists.Maxim Dounin1-33/+27
Multi headers are now using linked lists instead of arrays. Notably, the following fields were changed: r->headers_in.cookies (renamed to r->headers_in.cookie), r->headers_in.x_forwarded_for, r->headers_out.cache_control, r->headers_out.link, u->headers_in.cache_control u->headers_in.cookies (renamed to u->headers_in.set_cookie). The r->headers_in.cookies and u->headers_in.cookies fields were renamed to r->headers_in.cookie and u->headers_in.set_cookie to match header names. The ngx_http_parse_multi_header_lines() and ngx_http_parse_set_cookie_lines() functions were changed accordingly. With this change, multi headers are now essentially equivalent to normal headers, and following changes will further make them equivalent.
2021-06-28Improved logging of invalid headers.Maxim Dounin1-0/+5
In 71edd9192f24 logging of invalid headers which were rejected with the NGX_HTTP_PARSE_INVALID_HEADER error was restricted to just the "client sent invalid header line" message, without any attempts to log the header itself. This patch returns logging of the header up to the invalid character and the character itself. The r->header_end pointer is now properly set in all cases to make logging possible. The same logging is also introduced when parsing headers from upstream servers.
2021-06-28Disabled control characters and space in header names.Maxim Dounin1-2/+2
Control characters (0x00-0x1f, 0x7f), space, and colon were never allowed in header names. The only somewhat valid use is header continuation which nginx never supported and which is explicitly obsolete by RFC 7230. Previously, such headers were considered invalid and were ignored by default (as per ignore_invalid_headers directive). With this change, such headers are unconditionally rejected. It is expected to make nginx more resilient to various attacks, in particular, with ignore_invalid_headers switched off (which is inherently unsecure, though nevertheless sometimes used in the wild).
2021-06-28Disabled control characters in URIs.Maxim Dounin1-14/+28
Control characters (0x00-0x1f, 0x7f) were never allowed in URIs, and must be percent-encoded by clients. Further, these are not believed to appear in practice. On the other hand, passing such characters might make various attacks possible or easier, despite the fact that currently allowed control characters are not significant for HTTP request parsing.
2021-06-28Disabled spaces in URIs (ticket #196).Maxim Dounin1-64/+8
From now on, requests with spaces in URIs are immediately rejected rather than allowed. Spaces were allowed in 31e9677b15a1 (0.8.41) to handle bad clients. It is believed that now this behaviour causes more harm than good.
2021-06-28Added CONNECT method rejection.Maxim Dounin1-0/+5
No valid CONNECT requests are expected to appear within nginx, since it is not a forward proxy. Further, request line parsing will reject proper CONNECT requests anyway, since we don't allow authority-form of request-target. On the other hand, RFC 7230 specifies separate message length rules for CONNECT which we don't support, so make sure to always reject CONNECTs to avoid potential abuse.
2020-12-10Fixed parsing of absolute URIs with empty path (ticket #2079).Maxim Dounin1-0/+17
When the request line contains request-target in the absolute-URI form, it can contain path-empty instead of a single slash (see RFC 7230, RFC 3986). Previously, the ngx_http_parse_request_line() function only accepted empty path when there was no query string. With this change, non-empty query is also correctly handled. That is, request line "GET http://example.com?foo HTTP/1.1" is accepted and results in $uri "/" and $args "foo". Note that $request_uri remains "?foo", similarly to how spaces in URIs are handled. Providing "/?foo", similarly to how "/" is provided for "GET http://example.com HTTP/1.1", requires allocation.
2019-10-15Fixed header parsing with ignore_invalid_headers switched off.Ruslan Ermilov1-0/+4
The parsing was broken when the first character of the header name was invalid. Based on a patch by Alan Kemp.
2019-10-08Fixed URI normalization with merge_slashes switched off.Maxim Dounin1-2/+2
Previously, "/foo///../bar" was normalized into "/foo/bar" instead of "/foo//bar".
2019-10-08The "/." and "/.." at the end of URI should be normalized.Ruslan Ermilov1-6/+32
2019-10-08Improved detection of broken percent encoding in URI.Ruslan Ermilov1-0/+4
2019-09-03Detect runaway chunks in ngx_http_parse_chunked().Sergey Kandaurov1-0/+3
As defined in HTTP/1.1, body chunks have the following ABNF: chunk = chunk-size [ chunk-ext ] CRLF chunk-data CRLF where chunk-data is a sequence of chunk-size octets. With this change, chunk-data that doesn't end up with CRLF at chunk-size offset will be treated as invalid, such as in the example provided below: 4 SEE-THIS-AND- 4 THAT 0
2018-05-24Allowed digits, '+', '-', and '.' in scheme names as per RFC 3986.Ruslan Ermilov1-0/+5
2017-07-17Parenthesized ASCII-related calculations.Valentin Bartenev1-7/+7
This also fixes potential undefined behaviour in the range and slice filter modules, caused by local overflows of signed integers in expressions.
2017-04-27Added missing "fall through" comments (ticket #1259).Maxim Dounin1-0/+3
Found by gcc7 (-Wimplicit-fallthrough).
2017-04-25Don't pretend we support HTTP major versions >1 as HTTP/1.1.Ruslan Ermilov1-3/+9
2016-10-10Allowed '-' in method names.Maxim Dounin1-2/+2
It is used at least by SOAP (M-POST method, defined by RFC 2774) and by WebDAV versioning (VERSION-CONTROL and BASELINE-CONTROL methods, defined by RFC 3253).
2016-07-07Avoid left-shifting integers into the sign bit, which is undefined.Sergey Kandaurov1-11/+11
Found with UndefinedBehaviorSanitizer.
2016-05-18Added overflow checks for version numbers (ticket #762).Maxim Dounin1-0/+16
Both minor and major versions are now limited to 999 maximum. In case of r->http_minor, this limit is already implied by the code. Major version, r->http_major, in theory can be up to 65535 with current code, but such values are very unlikely to become real (and, additionally, such values are not allowed by RFC 7230), so the same test was used for r->http_major.
2015-03-17Overflow detection in ngx_http_parse_chunked().Ruslan Ermilov1-4/+8
2014-07-08Style: add whitespace between control statement and parentheses.Piotr Sikora1-4/+4
Signed-off-by: Piotr Sikora <piotr@cloudflare.com>
2014-04-29Upstream: added the "$upstream_cookie_<name>" variables.Vladimir Homutov1-0/+51
2014-03-24Apply underscores_in_headers also to the first character.Piotr Sikora1-0/+13
Signed-off-by: Piotr Sikora <piotr@cloudflare.com>
2013-12-23Teach ngx_http_parse_unsafe_uri() how to unescape URIs.Ruslan Ermilov1-3/+60
This fixes handling of escaped URIs in X-Accel-Redirect (ticket #316), SSI (ticket #240), and DAV.
2013-12-23Detect more unsafe URIs in ngx_http_parse_unsafe_uri().Ruslan Ermilov1-3/+7
The following URIs were considered safe: "..", "../foo", and "/foo/..".
2013-11-19Proper backtracking after space in a request line.Ruslan Ermilov1-0/+2
2013-08-21Minor ngx_http_parse_request_line() optimization.Maxim Dounin1-0/+3
Noted by Nils Kuhnhenn.
2013-06-28Fixed ngx_http_parse_chunked() minimal length calculation.Maxim Dounin1-2/+3
Minimal data length we expect for further calls was calculated incorrectly if parsing stopped right after parsing chunk size. This might in theory affect clients and/or backends using LF instead of CRLF. Patch by Dmitry Popov.
2013-06-05Fixed debug logging in ngx_http_parse_complex_uri().Maxim Dounin1-2/+2
The *u previously logged isn't yet initialized at this point, and Valgrind complains.
2013-05-06Fixed chunk size parsing.Maxim Dounin1-0/+4
2013-03-20Preliminary experimental support for SPDY draft 2.Valentin Bartenev1-0/+148
2012-11-21Request body: adjust b->pos when chunked parsing done.Maxim Dounin1-0/+3
This is a nop for the current code, though will allow to correctly parse pipelined requests.
2012-11-21Request body: chunked parsing moved to ngx_http_parse.c from proxy.Maxim Dounin1-0/+253
No functional changes.
2012-06-05Win32: normalization of trailing dot inside uri.Maxim Dounin1-0/+20
Windows treats "/directory./" identical to "/directory/". Do the same when working on Windows. Note that the behaviour is different from one with last path component (where multiple spaces and dots are ignored by Windows).
2012-04-03Fixed spelling in multiline C comments.Ruslan Ermilov1-1/+1
2012-03-19For the sake of case/switch code readability, 'fall through'Maxim Konovalov1-0/+1
comments added.
2012-03-15Headers with null character are now rejected.Maxim Dounin1-0/+14
Headers with NUL character aren't allowed by HTTP standard and may cause various security problems. They are now unconditionally rejected.
2012-01-18Copyright updated.Maxim Konovalov1-0/+1
2011-11-28Added support for IP-literal in the Host header and request line (ticket #1).Valentin Bartenev1-2/+62
Additional parsing logic added to correctly handle RFC 3986 compliant IPv6 and IPvFuture characters enclosed in square brackets. The host validation was completely rewritten. The behavior for non IP literals was changed in a more proper and safer way: - Host part is now delimited either by the first colon or by the end of string if there's no colon. Previously the last colon was used as delimiter which allowed substitution of a port number in the $host variable. (e.g. Host: 127.0.0.1:9000:80) - Fixed stripping of the ending dot in the Host header when the host was also followed by a port number. (e.g. Host: nginx.com.:80) - Fixed upper case characters detection. Previously it was broken which led to wasting memory and CPU.
2011-09-15Protocol version parsing in ngx_http_parse_status_line().Maxim Dounin1-0/+5
Once we know protocol version, set u->headers_in.connection_close to indicate implicitly assumed connection close with HTTP before 1.1.
2010-06-23style fixIgor Sysoev1-1/+1
2010-06-15ngx_http_parse_status_line()Igor Sysoev1-0/+205
2010-06-15allow spaces in URIIgor Sysoev1-5/+55
2010-06-10PATCH methodIgor Sysoev1-0/+4
2010-06-04fix "/dir/%3F../" and "/dir/%23../" casesIgor Sysoev1-6/+3
2010-05-24remove r->zero_in_uriIgor Sysoev1-34/+15
2009-09-25check unsafe DestinationIgor Sysoev1-2/+4
2009-09-14handle "/../" case more reliablyIgor Sysoev1-5/+9