summaryrefslogtreecommitdiffhomepage
path: root/src/http/modules (follow)
AgeCommit message (Collapse)AuthorFilesLines
2018-03-22gRPC: fixed possible sign extension of error and setting_value.Maxim Dounin1-3/+3
All cases are harmless and should not happen on valid values, though can result in bad values being shown incorrectly in logs. Found by Coverity (CID 1430311, 1430312, 1430313).
2018-03-20gRPC: fixed missing state save in frame header parsing.Sergey Kandaurov1-0/+1
Previously, frame state wasn't saved if HEADERS frame payload that begins with header fragment was not received at once.
2018-03-19gRPC: fixed parsing response headers split on CONTINUATION frames.Sergey Kandaurov1-2/+2
2018-03-19Upstream: fixed comments after 13f8dec720b5.Ruslan Ermilov3-6/+2
The fields "uri", "location", and "url" from ngx_http_upstream_conf_t moved to ngx_http_proxy_loc_conf_t and ngx_http_proxy_vars_t, reflect this change in create_loc_conf comments.
2018-03-17gRPC: special handling of "trailer only" responses.Maxim Dounin1-7/+10
The gRPC protocol makes a distinction between HEADERS frame with the END_STREAM flag set, and a HEADERS frame followed by an empty DATA frame with the END_STREAM flag. The latter is not permitted, and results in errors not being propagated through nginx. Instead, gRPC clients complain that "server closed the stream without sending trailers" (seen in grpc-go) or "13: Received RST_STREAM with error code 2" (seen in grpc-c). To fix this, nginx now returns HEADERS with the END_STREAM flag if the response length is known to be 0, and we are not expecting any trailer headers to be added. And the response length is explicitly set to 0 in the gRPC proxy if we see initial HEADERS frame with the END_STREAM flag set.
2018-03-17gRPC: special handling of the TE request header.Maxim Dounin1-2/+67
According to the gRPC protocol specification, the "TE" header is used to detect incompatible proxies, and at least grpc-c server rejects requests without "TE: trailers". To preserve the logic, we have to pass "TE: trailers" to the backend if and only if the original request contains "trailers" in the "TE" header. Note that no other TE values are allowed in HTTP/2, so we have to remove anything else.
2018-03-17The gRPC proxy module.Maxim Dounin1-0/+4571
The module allows passing requests to upstream gRPC servers. The module is built by default as long as HTTP/2 support is compiled in. Example configuration: grpc_pass 127.0.0.1:9000; Alternatively, the "grpc://" scheme can be used: grpc_pass grpc://127.0.0.1:9000; Keepalive support is available via the upstream keepalive module. Note that keepalive connections won't currently work with grpc-go as it fails to handle SETTINGS_HEADER_TABLE_SIZE. To use with SSL: grpc_pass grpcs://127.0.0.1:9000; SSL connections use ALPN "h2" when available. At least grpc-go works fine without ALPN, so if ALPN is not available we just establish a connection without it. Tested with grpc-c++ and grpc-go.
2018-03-01Access log: support for disabling escaping (ticket #1450).Vladimir Homutov1-8/+60
Based on patches by Johannes Baiter <johannes.baiter@bsb-muenchen.de> and Calin Don.
2018-02-28Generic subrequests in memory.Roman Arutyunyan3-63/+5
Previously, only the upstream response body could be accessed with the NGX_HTTP_SUBREQUEST_IN_MEMORY feature. Now any response body from a subrequest can be saved in a memory buffer. It is available as a single buffer in r->out and the buffer size is configured by the subrequest_output_buffer_size directive. Upstream, proxy and fastcgi code used to handle the old-style feature is removed.
2018-02-26Auth basic: prevent null character in error log (ticket #1494).Vadim Filimonov1-2/+2
2018-02-21Geo: optimized configuration parser.Ruslan Ermilov1-1/+5
If the geo block parser has failed, doing more things is pointless.
2018-02-21Geo: fixed memory allocation error handling (closes #1482).Ruslan Ermilov1-11/+16
If during configuration parsing of the geo directive the memory allocation has failed, pool used to parse configuration inside the block, and sometimes the temporary pool were not destroyed.
2018-02-08Basic support of the Link response header.Ruslan Ermilov1-19/+23
2018-02-07Dav: added error logging.Roman Arutyunyan1-1/+10
Previously, when request body was not available or was previously read in memory rather than a file, client received HTTP 500 error, but no explanation was logged in error log. This could happen, for example, if request body was read or discarded prior to error_page redirect, or if mirroring was enabled along with dav.
2017-11-20Proxy: escape explicit space in URI in default cache key.Roman Arutyunyan1-1/+1
If the flag space_in_uri is set, the URI in HTTP upstream request is escaped to convert space to %20. However this flag is not checked while creating the default cache key. This leads to different cache keys for requests '/foo bar' and '/foo%20bar', while the upstream requests are identical. Additionally, the change fixes background cache updates when the client URI contains unescaped space. Default cache key in a subrequest is always based on escaped URI, while the main request may not escape it. As a result, background cache update subrequest may update a different cache entry.
2017-11-20Proxy: simplified conditions of using unparsed uri.Roman Arutyunyan1-4/+2
Previously, the unparsed uri was explicitly allowed to be used only by the main request. However the valid_unparsed_uri flag is nonzero only in the main request, which makes the main request check pointless.
2017-11-28Upstream keepalive: clean read delayed flag in stored connections.Roman Arutyunyan1-0/+1
If a connection with the read delayed flag set was stored in the keepalive cache, and after picking it from the cache a read timer was set on that connection, this timer was considered a delay timer rather than a socket read event timer as expected. The latter timeout is usually much longer than the former, which caused a significant delay in request processing. The issue manifested itself with proxy_limit_rate and upstream keepalive enabled and exists since 973ee2276300 (1.7.7) when proxy_limit_rate was introduced.
2017-12-04Autoindex: discard request body (ticket #1439).Maxim Dounin1-0/+6
2017-11-18Gzip: support for a zlib variant from Intel.Maxim Dounin1-5/+33
A zlib variant from Intel as available from https://github.com/jtkukunas/zlib uses 64K hash instead of scaling it from the specified memory level, and also uses 16-byte padding in one of the window-sized memory buffers, and can force window bits to 13 if compression level is set to 1 and appropriate compile options are used. As a result, nginx complained with "gzip filter failed to use preallocated memory" alerts. This change improves deflate_state allocation detection by testing that items is 1 (deflate_state is the only allocation where items is 1). Additionally, on first failure to use preallocated memory we now assume that we are working with the Intel's modified zlib, and switch to using appropriate preallocations. If this does not help, we complain with the usual alerts. Previous version of this patch was published at http://mailman.nginx.org/pipermail/nginx/2014-July/044568.html. The zlib variant in question is used by default in ClearLinux from Intel, see http://mailman.nginx.org/pipermail/nginx-ru/2017-October/060421.html, http://mailman.nginx.org/pipermail/nginx-ru/2017-November/060544.html.
2017-11-16Xslt: fixed parameters parsing (ticket #1416).Ruslan Ermilov1-2/+13
If parameters were specified in xslt_stylesheet without variables, any request except the first would cause an internal server error.
2017-10-27SSI: fixed type.hucongcong1-8/+7
2017-11-09FastCGI: adjust buffer position when parsing incomplete records.Maxim Dounin1-0/+1
Previously, nginx failed to move buffer position when parsing an incomplete record header, and due to this wasn't be able to continue parsing once remaining bytes of the record header were received. This can affect response header parsing, potentially generating spurious errors like "upstream sent unexpected FastCGI request id high byte: 1 while reading response header from upstream". While this is very unlikely, since usually record headers are written in a single buffer, this still can happen in real life, for example, if a record header will be split across two TCP packets and the second packet will be delayed. This does not affect non-buffered response body proxying, due to "buf->pos = buf->last;" at the start of the ngx_http_fastcgi_non_buffered_filter() function. Also this does not affect buffered response body proxying, as each input buffer is only passed to the filter once.
2017-10-05Upstream hash: reordered peer checks.Maxim Dounin1-7/+7
This slightly reduces cost of selecting a peer if all or almost all peers failed, see ticket #1030. There should be no measureable difference with other workloads.
2017-10-05Upstream hash: limited number of tries in consistent case.Maxim Dounin1-3/+7
While this may result in non-ideal distribution of requests if nginx won't be able to select a server in a reasonable number of attempts, this still looks better than severe performance degradation observed if there is no limit and there are many points configured (ticket #1030). This is also in line with what we do for other hash balancing methods.
2017-09-22Do not use the obsolete NGX_SOCKADDRLEN macro.Ruslan Ermilov1-1/+1
The change in ac120e797d28 re-used the macro which was made obsolete in adf25b8d0431.
2017-09-18Removed more remnants of the old pthread implementation.Ruslan Ermilov1-55/+15
After e284f3ff6831, ngx_crypt() can no longer return NGX_AGAIN.
2017-08-22Secure link: fixed stack buffer overflow.Roman Arutyunyan1-2/+1
When secure link checksum has length of 23 or 24 bytes, decoded base64 value could occupy 17 or 18 bytes which is more than 16 bytes previously allocated for it on stack. The buffer overflow does not have any security implications since only one local variable was corrupted and this variable was not used in this case. The fix is to increase buffer size up to 18 bytes. Useless buffer size initialization is removed as well.
2017-08-22SSL: the $ssl_client_escaped_cert variable (ticket #857).Maxim Dounin1-0/+4
This variable contains URL-encoded client SSL certificate. In contrast to $ssl_client_cert, it doesn't depend on deprecated header continuation. The NGX_ESCAPE_URI_COMPONENT variant of encoding is used, so the resulting variable can be safely used not only in headers, but also as a request argument. The $ssl_client_cert variable should be considered deprecated now. The $ssl_client_raw_cert variable will be eventually renambed back to $ssl_client_cert.
2017-08-10Range filter: changed type for total length to off_t.Maxim Dounin1-8/+9
Total length of a response with multiple ranges can be larger than a size_t variable can hold, so type changed to off_t. Previously, an incorrect Content-Length was returned when requesting more than 4G of ranges from a large enough file on a 32-bit system. An additional size_t variable introduced to calculate size of the boundary header buffer, as off_t is not needed here and will require type casts on win32. Reported by Shuxin Yang, http://mailman.nginx.org/pipermail/nginx/2017-July/054384.html.
2017-08-10Style.Maxim Dounin2-5/+5
2017-08-09Fixed calls to ngx_open_file() in certain places.Sergey Kandaurov1-1/+1
Pass NGX_FILE_OPEN to ngx_open_file() to fix "The parameter is incorrect" error on win32 when using the ssl_session_ticket_key directive or loading a binary geo base. On UNIX, this change is a no-op.
2017-08-09Style.Sergey Kandaurov1-0/+1
2017-08-04Upstream: copy peer data in shared memory.Ruslan Ermilov1-8/+69
This, in addition to 1eb753aa8e5e, fixes "upstream zone" on Windows.
2017-08-04Referer: fixed $invalid_referer.Ruslan Ermilov1-14/+25
The variable was considered non-existent in the absence of any valid_referers directives. Given the following config snippet, location / { return 200 $invalid_referer; } location /referer { valid_referers server_names; } "location /" should work identically and independently on other "location /referer". The fix is to always add the $invalid_referer variable as long as the module is compiled in, as is done by other modules.
2017-08-01Upstream zone: store peers->name and its data in shared memory.Ruslan Ermilov1-0/+18
The shared objects should generally be allocated from shared memory. While peers->name and the data it points to allocated from cf->pool happened to work on UNIX, it broke on Windows. On UNIX this worked only because the shared memory zone for upstreams is re-created for every new configuration. But on Windows, a worker process does not inherit the address space of the master process, so the peers->name pointed to data allocated from cf->pool by the master process, and was invalid.
2017-08-01Variables: macros for null variables.Ruslan Ermilov8-8/+8
No functional changes.
2017-08-01Browser: style.Ruslan Ermilov1-24/+21
Removed custom variable type and renamed function that adds variables.
2017-07-21Mirror: "off" paramater of the "mirror" directive.Roman Arutyunyan1-2/+43
2017-07-20Mirror module.Roman Arutyunyan1-0/+223
2017-07-20Precontent phase.Roman Arutyunyan1-0/+404
The phase is added instead of the try_files phase. Unlike the old phase, the new one supports registering multiple handlers. The try_files implementation is moved to a separate ngx_http_try_files_module, which now registers a precontent phase handler.
2017-07-19Upstream: keep request body file from removal if requested.Roman Arutyunyan3-0/+6
The new request flag "preserve_body" indicates that the request body file should not be removed by the upstream module because it may be used later by a subrequest. The flag is set by the SSI (ticket #585), addition and slice modules. Additionally, it is also set by the upstream module when a background cache update subrequest is started to prevent the request body file removal after an internal redirect. Only the main request is now allowed to remove the file.
2017-07-17Parenthesized ASCII-related calculations.Valentin Bartenev2-6/+6
This also fixes potential undefined behaviour in the range and slice filter modules, caused by local overflows of signed integers in expressions.
2017-07-11Range filter: avoid negative range start.Maxim Dounin1-1/+1
Suffix ranges no longer allowed to set negative start values, to prevent ranges with negative start from appearing even if total size protection will be removed.
2017-07-11Range filter: protect from total size overflows.Maxim Dounin1-0/+4
The overflow can be used to circumvent the restriction on total size of ranges introduced in c2a91088b0c0 (1.1.2). Additionally, overflow allows producing ranges with negative start (such ranges can be created by using a suffix, "bytes=-100"; normally this results in 200 due to the total size check). These can result in the following errors in logs: [crit] ... pread() ... failed (22: Invalid argument) [alert] ... sendfile() failed (22: Invalid argument) When using cache, it can be also used to reveal cache file header. It is believed that there are no other negative effects, at least with standard nginx modules. In theory, this can also result in memory disclosure and/or segmentation faults if multiple ranges are allowed, and the response is returned in a single in-memory buffer. This never happens with standard nginx modules though, as well as known 3rd party modules. Fix is to properly protect from possible overflow when incrementing size.
2017-03-15Proxy: split configured header names and values.Piotr Sikora1-106/+59
Previously, each configured header was represented in one of two ways, depending on whether or not its value included any variables. If the value didn't include any variables, then it would be represented as as a single script that contained complete header line with HTTP/1.1 delimiters, i.e.: "Header: value\r\n" But if the value included any variables, then it would be represented as a series of three scripts: first contained header name and the ": " delimiter, second evaluated to header value, and third contained only "\r\n", i.e.: "Header: " "$value" "\r\n" This commit changes that, so that each configured header is represented as a series of two scripts: first contains only header name, and second contains (or evaluates to) only header value, i.e.: "Header" "$value" or "Header" "value" This not only makes things more consistent, but also allows header name and value to be accessed separately. Signed-off-by: Piotr Sikora <piotrsikora@google.com>
2017-06-27Range filter: allowed ranges on empty files (ticket #1031).Maxim Dounin1-0/+3
As per RFC 2616 / RFC 7233, any range request to an empty file is expected to result in 416 Range Not Satisfiable response, as there cannot be a "byte-range-spec whose first-byte-pos is less than the current length of the entity-body". On the other hand, this makes use of byte-range requests inconvenient in some cases, as reported for the slice module here: http://mailman.nginx.org/pipermail/nginx-devel/2017-June/010177.html This commit changes range filter to instead return 200 if the file is empty and the range requested starts at 0.
2017-03-24Headers filter: added "add_trailer" directive.Piotr Sikora1-22/+142
Trailers added using this directive are evaluated after response body is processed by output filters (but before it's written to the wire), so it's possible to use variables calculated from the response body as the trailer value. Signed-off-by: Piotr Sikora <piotrsikora@google.com>
2017-03-24Added support for trailers in HTTP responses.Piotr Sikora1-27/+125
Example: ngx_table_elt_t *h; h = ngx_list_push(&r->headers_out.trailers); if (h == NULL) { return NGX_ERROR; } ngx_str_set(&h->key, "Fun"); ngx_str_set(&h->value, "with trailers"); h->hash = ngx_hash_key_lc(h->key.data, h->key.len); The code above adds "Fun: with trailers" trailer to the response. Modules that want to emit trailers must set r->expect_trailers = 1 in header filter, otherwise they might not be emitted for HTTP/1.1 responses that aren't already chunked. This change also adds $sent_trailer_* variables. Signed-off-by: Piotr Sikora <piotrsikora@google.com>
2017-06-14Gzip: fixed style in $gzip_ratio variable handler.Ruslan Ermilov1-4/+4
The current style in variable handlers returning NGX_OK is to either set v->not_found to 1, or to initialize the entire ngx_http_variable_value_t structure. In theory, always setting v->valid = 1 for NGX_OK would be useful, which would mean that the value was computed and is thus valid, including the special case of v->not_found = 1. But currently that's not the case and causes the (v->valid || v->not_found) check to access an uninitialized v->valid value, which is safe only because its value doesn't matter when v->not_found is set.
2017-06-07Userid: ngx_http_get_indexed_variable() error handling.Sergey Kandaurov1-0/+4
When evaluating a mapped $reset_uid variable in the userid filter, if get_handler set to ngx_http_map_variable() returned an error, this previously resulted in a NULL pointer dereference.