summaryrefslogtreecommitdiffhomepage
path: root/src/http/modules (follow)
AgeCommit message (Collapse)AuthorFilesLines
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.
2017-06-07SSI: return NGX_ERROR when timefmt memory allocation failed.Sergey Kandaurov1-1/+1
Previously, when using NGX_HTTP_SSI_ERROR, error was ignored in ssi processing, thus timefmt could be accessed later in ngx_http_ssi_date_gmt_local_variable() as part of "set" handler, or NULL format pointer could be passed to strftime().
2017-05-31Headers filter: style.Piotr Sikora1-2/+2
Signed-off-by: Piotr Sikora <piotrsikora@google.com>
2017-05-18Upstream: fixed u->headers_in.headers allocation error handling.Sergey Kandaurov4-0/+6
Previously, an allocation error resulted in uninitialized memory access when evaluating $upstream_http_ variables. On a related note, see r->headers_out.headers cleanup work in 0cdee26605f3.
2017-05-15Realip: allow hostnames in set_real_ip_from (ticket #1180).Ruslan Ermilov1-15/+68
2017-05-15Access: simplified rule parser code.Ruslan Ermilov1-13/+7
2017-04-20Gzip static: use an appropriate error on memory allocation failure.Sergey Kandaurov1-1/+1
2017-04-20Cleaned up r->headers_out.headers allocation error handling.Sergey Kandaurov6-10/+21
If initialization of a header failed for some reason after ngx_list_push(), leaving the header as is can result in uninitialized memory access by the header filter or the log module. The fix is to clear partially initialized headers in case of errors. For the Cache-Control header, the fix is to postpone pushing r->headers_out.cache_control until its value is completed.
2017-04-18Sub filter: restored ngx_http_set_ctx() at the proper place.Sergey Kandaurov1-2/+2
Previously, ngx_http_sub_header_filter() could fail with a partially initialized context, later accessed in ngx_http_sub_body_filter() if called from the perl content handler. The issue had appeared in 2c045e5b8291 (1.9.4). A better fix would be to handle ngx_http_send_header() errors in the perl module, though this doesn't seem to be easy enough.
2017-04-18SSL: added support for TLSv1.3 in ssl_protocols directive.Sergey Kandaurov3-0/+3
Support for the TLSv1.3 protocol will be introduced in OpenSSL 1.1.1.
2017-04-11Added support for the "308 Permanent Redirect" (ticket #877).Simon Leblanc2-0/+3
2017-04-12Use ngx_calloc_buf() where appropriate.Ruslan Ermilov7-10/+10
2017-03-24Upstream: allow recovery from "429 Too Many Requests" response.Piotr Sikora4-0/+4
This change adds "http_429" parameter to "proxy_next_upstream" for retrying rate-limited requests, and to "proxy_cache_use_stale" for serving stale cached responses after being rate-limited. Signed-off-by: Piotr Sikora <piotrsikora@google.com>
2017-03-31Slice filter: prevented slice redirection (ticket #1219).Roman Arutyunyan1-1/+11
When a slice subrequest was redirected to a new location, its context was lost. After its completion, a new slice subrequest for the same slice was created. This could lead to infinite loop. Now the slice module makes sure each slice subrequest starts output with the slice context available.
2017-03-28Slice filter: allowed at most one subrequest at a time.Roman Arutyunyan1-12/+16
Previously, if slice main request write handler was called while a slice subrequest was running, a new subrequest for the same slice was started.
2017-04-02Moved handling of wev->delayed to the connection event handler.Maxim Dounin2-8/+2
With post_action or subrequests, it is possible that the timer set for wev->delayed will expire while the active subrequest write event handler is not ready to handle this. This results in request hangs as observed with limit_rate / sendfile_max_chunk and post_action (ticket #776) or subrequests (ticket #1228). Moving the handling to the connection event handler fixes the hangs observed, and also slightly simplifies the code.
2017-04-02Perl: fixed delaying subrequests.Maxim Dounin2-6/+11
Much like in limit_req, use the wev->delayed flag to ensure proper handling and interoperability with limit_rate.
2017-04-02Limit req: fixed delaying subrequests.Maxim Dounin1-1/+4
Since limit_req uses connection's write event to delay request processing, it can conflict with timers in other subrequests. In particular, even if applied to an active subrequest, it can break things if wev->delayed is already set (due to limit_rate or sendfile_max_chunk), since after limit_req finishes the wev->delayed flag will be set and no timer will be active. Fix is to use the wev->delayed flag in limit_req as well. This ensures that wev->delayed won't be set after limit_req finishes, and also ensures that limit_req's timers will be properly handled by other subrequests if the one delayed by limit_req is not active.
2017-03-28Fixed ngx_open_cached_file() error handling.Sergey Kandaurov2-3/+8
If of.err is 0, it means that there was a memory allocation error and no further logging and/or processing is needed. The of.failed string can be only accessed if of.err is not 0.
2017-03-07Access log: removed dead ev->timedout check in flush timer handler.Maxim Dounin1-14/+1
The ev->timedout flag is set on first timer expiration, and never reset after it. Due to this the code to stop the timer when the timer was canceled never worked (except in a very specific time frame immediately after start), and the timer was always armed again. This essentially resulted in a buffer flush at the end of an event loop iteration. This behaviour actually seems to be better than just stopping the flush timer for the whole shutdown, so it is preserved as is instead of fixing the code to actually remove the timer. It will be further improved by upcoming changes to preserve cancelable timers if there are other timers blocking shutdown.
2017-03-02Added missing static specifiers.Eran Kornblau4-4/+4
2017-02-13Gzip: free chain links on the hot path (ticket #1046).Maxim Dounin1-6/+16
2017-02-10Slice filter: fetch slices in cloned subrequests.Roman Arutyunyan1-1/+4
Previously, slice subrequest location was selected based on request URI. If request is then redirected to a new location, its context array is cleared, making the slice module loose current slice range information. This lead to broken output. Now subrequests with the NGX_HTTP_SUBREQUEST_CLONE flag are created for slices. Such subrequests stay in the same location as the parent request and keep the right slice context.
2017-02-10Upstream: proxy_cache_background_update and friends.Roman Arutyunyan4-0/+44
The directives enable cache updates in subrequests.
2017-01-31Variables: generic prefix variables.Dmitry Volyntsev1-10/+3
2016-12-24Win32: fixed some warnings reported by Borland C.Maxim Dounin1-2/+2
Most notably, warning W8012 (comparing signed and unsigned values) reported in multiple places where an unsigned value of small type (e.g., u_short) is promoted to an int and compared to an unsigned value. Warning W8072 (suspicious pointer arithmetic) disabled, it is reported when we increment base pointer in ngx_shm_alloc().
2016-12-22Fixed missing "Location" field with some relative redirects.Ruslan Ermilov2-12/+6
Relative redirects did not work with directory redirects and auto redirects issued by nginx.
2016-12-15Access log: support for json escaping.Valentin Bartenev1-6/+77
2016-12-08Map: the "volatile" parameter.Ruslan Ermilov1-1/+14
By default, "map" creates cacheable variables [1]. With this parameter it creates a non-cacheable variable. An original idea was to deduce the cacheability of the "map" variable by checking the cacheability of variables specified in source and resulting values, but it turned to be too hard. For example, a cacheable variable can be overridden with the "set" directive or with the SSI "set" command. Also, keeping "map" variables cacheable by default is good for performance reasons. This required adding a new parameter. [1] Before db699978a33f (1.11.0), the cacheability of the "map" variable could vary depending on the cacheability of variables specified in resulting values (ticket #1090). This is believed to be a bug rather than a feature.
2016-12-08Map: simplified "map" block parser.Ruslan Ermilov1-1/+2
No functional changes.
2016-12-07Perl: added PERL_SET_INTERP().Maxim Dounin1-0/+8
For Perl compiled with threads, without PERL_SET_INTERP() the PL_curinterp remains set to the first interpreter created (that is, one created at original start). As a result after a reload Perl thinks that operations are done withing a thread, and, most notably, denies to change environment. For example, the following code properly works on original start, but fails after a reload: perl 'sub { my $r = shift; $r->send_http_header("text/plain"); $ENV{TZ} = "UTC"; $r->print("tz: " . $ENV{TZ} . " (localtime " . (localtime()) . ")\n"); $ENV{TZ} = "Europe/Moscow"; $r->print("tz: " . $ENV{TZ} . " (localtime " . (localtime()) . ")\n"); return OK; }'; To fix this, PERL_SET_INTERP() added anywhere where PERL_SET_CONTEXT() was previously used. Note that PERL_SET_INTERP() doesn't seem to be documented anywhere. Yet it is used in some other software, and also seems to be the only solution possible.
2016-11-22Mp4: fixed setting wrong mdat atom size in very rare cases.hucongcong1-1/+3
Atom size is the sum of atom header size and atom data size. The specification says that the first 4 bytes are set to one when the atom size is greater than the maximum unsigned 32-bit value. Which means atom header size should be considered when the comparison takes place between atom data size and 0xffffffff.
2016-12-05SSL: $ssl_curves (ticket #1088).Maxim Dounin1-0/+3
The variable contains a list of curves as supported by the client. Known curves are listed by their names, unknown ones are shown in hex, e.g., "0x001d:prime256v1:secp521r1:secp384r1". Note that OpenSSL uses session data for SSL_get1_curves(), and it doesn't store full list of curves supported by the client when serializing a session. As a result $ssl_curves is only available for new sessions (and will be empty for reused ones). The variable is only meaningful when using OpenSSL 1.0.2 and above. With older versions the variable is empty.
2016-12-05SSL: $ssl_ciphers (ticket #870).Maxim Dounin1-0/+3
The variable contains list of ciphers as supported by the client. Known ciphers are listed by their names, unknown ones are shown in hex, e.g., ""AES128-SHA:AES256-SHA:0x00ff". The variable is fully supported only when using OpenSSL 1.0.2 and above. With older version there is an attempt to provide some information using SSL_get_shared_ciphers(). It only lists known ciphers though. Moreover, as OpenSSL uses session data for SSL_get_shared_ciphers(), and it doesn't store relevant data when serializing a session. As a result $ssl_ciphers is only available for new sessions (and not available for reused ones) when using OpenSSL older than 1.0.2.
2016-12-05SSL: $ssl_client_v_start, $ssl_client_v_end, $ssl_client_v_remain.Maxim Dounin1-0/+9
2016-11-10Range filter: only initialize ctx->ranges in main request.hucongcong1-6/+6
It is not necessary to initialize ctx->ranges in all request, because ctx->ranges in subrequest will be reassigned to ctx->ranges of main request.
2016-11-02Cache: proxy_cache_max_range_offset and friends.Dmitry Volyntsev4-0/+48
It configures a threshold in bytes, above which client range requests are not cached. In such a case the client's Range header is passed directly to a proxied server.
2016-11-01Perl: fixed optimization in SSI command handler.Maxim Dounin1-1/+1
As the pointer to the first argument was tested instead of the argument itself, array of arguments was always created, even if there were no arguments. Fix is to test args[0] instead of args. Found by Coverity (CID 1356862).
2016-10-31Upstream: added the ngx_http_upstream_resolved_t.name field.Ruslan Ermilov4-16/+8
This fixes inconsistency in what is stored in the "host" field. Normally it would contain the "host" part of the parsed URL (e.g., proxy_pass with variables), but for the case of an implicit upstream specified with literal address it contained the text representation of the socket address (that is, host including port for IP). Now the "host" field always contains the "host" part of the URL, while the text representation of the socket address is stored in the newly added "name" field. The ngx_http_upstream_create_round_robin_peer() function was modified accordingly in a way to be compatible with the code that does not know about the new "name" field. The "stream" code was similarly modified except for not adding compatibility in ngx_stream_upstream_create_round_robin_peer(). This change is also a prerequisite for the next change.
2016-10-31Upstream: removed unnecessary condition in proxy_eval() and friends.Ruslan Ermilov4-4/+4
The first condition added in d3454e719bbb should have just replaced the second one.
2016-10-27Mp4: introduced custom version of ngx_atofp().Maxim Dounin1-14/+60
This allows to correctly parse "start" and "end" arguments without null-termination (ticket #475), and also fixes rounding errors observed with strtod() when using i387 instructions.
2016-10-16Proxy: support variables for proxy_method directive.Dmitry Lazurkin1-6/+10
2016-10-21SSL: RFC2253 compliant $ssl_client_s_dn and $ssl_client_i_dn.Dmitry Volyntsev1-0/+6
Originally, the variables kept a result of X509_NAME_oneline(), which is, according to the official documentation, a legacy function. It produces a non standard output form and has various quirks and inconsistencies. The RFC2253 compliant behavior is introduced for these variables. The original variables are available through $ssl_client_s_dn_legacy and $ssl_client_i_dn_legacy.