]> git.kaiwu.me - nginx.git/log
nginx.git
7 years agoUpstream: revised upstream response time variables.
Vladimir Homutov [Wed, 21 Nov 2018 10:40:40 +0000 (13:40 +0300)]
Upstream: revised upstream response time variables.

Variables now do not depend on presence of the HTTP status code in response.
If the corresponding event occurred, variables contain time between request
creation and the event, and "-" otherwise.

Previously, intermediate value of the $upstream_response_time variable held
unix timestamp.

7 years agoUpstream: removed unused ngx_http_upstream_t.timeout field.
Vladimir Homutov [Wed, 21 Nov 2018 10:40:36 +0000 (13:40 +0300)]
Upstream: removed unused ngx_http_upstream_t.timeout field.

7 years agoCore: ngx_explicit_memzero().
Maxim Dounin [Thu, 15 Nov 2018 18:28:02 +0000 (21:28 +0300)]
Core: ngx_explicit_memzero().

7 years agoCore: free shared memory on cycle initialization failure.
Ruslan Ermilov [Thu, 15 Nov 2018 12:28:54 +0000 (15:28 +0300)]
Core: free shared memory on cycle initialization failure.

7 years agoStream: proxy_requests directive.
Vladimir Homutov [Mon, 12 Nov 2018 13:29:30 +0000 (16:29 +0300)]
Stream: proxy_requests directive.

The directive allows to drop binding between a client and existing UDP stream
session after receiving a specified number of packets.  First packet from the
same client address and port will start a new session.  Old session continues
to exist and will terminate at moment defined by configuration: either after
receiving the expected number of responses, or after timeout, as specified by
the "proxy_responses" and/or "proxy_timeout" directives.

By default, proxy_requests is zero (disabled).

7 years agoStream: session completion check code moved to a separate function.
Vladimir Homutov [Mon, 12 Nov 2018 09:05:03 +0000 (12:05 +0300)]
Stream: session completion check code moved to a separate function.

The code refactored to simplify the ngx_stream_proxy_process() function
and facilitate adding new session termination conditions.

7 years agoStream: fixed possible use of a freed connection.
Vladimir Homutov [Wed, 7 Nov 2018 10:22:14 +0000 (13:22 +0300)]
Stream: fixed possible use of a freed connection.

The session handler may result in session termination, thus a connection
pool (from which c->udp was allocated) may be destroyed.

7 years agoVersion bump.
Vladimir Homutov [Tue, 13 Nov 2018 11:42:47 +0000 (14:42 +0300)]
Version bump.

7 years agorelease-1.15.6 tag
Maxim Dounin [Tue, 6 Nov 2018 13:32:09 +0000 (16:32 +0300)]
release-1.15.6 tag

7 years agonginx-1.15.6-RELEASE release-1.15.6
Maxim Dounin [Tue, 6 Nov 2018 13:32:08 +0000 (16:32 +0300)]
nginx-1.15.6-RELEASE

7 years agogRPC: limited allocations due to ping and settings frames.
Maxim Dounin [Tue, 6 Nov 2018 13:29:59 +0000 (16:29 +0300)]
gRPC: limited allocations due to ping and settings frames.

7 years agoHTTP/2: limit the number of idle state switches.
Ruslan Ermilov [Tue, 6 Nov 2018 13:29:49 +0000 (16:29 +0300)]
HTTP/2: limit the number of idle state switches.

An attack that continuously switches HTTP/2 connection between
idle and active states can result in excessive CPU usage.
This is because when a connection switches to the idle state,
all of its memory pool caches are freed.

This change limits the maximum allowed number of idle state
switches to 10 * http2_max_requests (i.e., 10000 by default).
This limits possible CPU usage in one connection, and also
imposes a limit on the maximum lifetime of a connection.

Initially reported by Gal Goldshtein from F5 Networks.

7 years agoHTTP/2: flood detection.
Ruslan Ermilov [Tue, 6 Nov 2018 13:29:35 +0000 (16:29 +0300)]
HTTP/2: flood detection.

Fixed uncontrolled memory growth in case peer is flooding us with
some frames (e.g., SETTINGS and PING) and doesn't read data.  Fix
is to limit the number of allocated control frames.

7 years agoMp4: fixed reading 64-bit atoms.
Roman Arutyunyan [Tue, 6 Nov 2018 13:29:18 +0000 (16:29 +0300)]
Mp4: fixed reading 64-bit atoms.

Previously there was no validation for the size of a 64-bit atom
in an mp4 file.  This could lead to a CPU hog when the size is 0,
or various other problems due to integer underflow when calculating
atom data size, including segmentation fault or worker process
memory disclosure.

7 years agoCache: improved keys zone size error reporting.
Maxim Dounin [Wed, 31 Oct 2018 13:49:40 +0000 (16:49 +0300)]
Cache: improved keys zone size error reporting.

After this change, too small keys zones are explicitly reported as such,
much like in the other modules which use shared memory.

7 years agoCache: fixed minimum cache keys zone size limit.
Maxim Dounin [Wed, 31 Oct 2018 13:49:39 +0000 (16:49 +0300)]
Cache: fixed minimum cache keys zone size limit.

Size of a shared memory zones must be at least two pages - one page
for slab allocator internal data, and another page for actual allocations.
Using 8192 instead is wrong, as there are systems with page sizes other
than 4096.

Note well that two pages is usually too low as well.  In particular, cache
is likely to use two allocations of different sizes for global structures,
and at least four pages will be needed to properly allocate cache nodes.
Except in a few very special cases, with keys zone of just two pages nginx
won't be able to start.  Other uses of shared memory impose a limit
of 8 pages, which provides some room for global allocations.  This patch
doesn't try to address this though.

Inspired by ticket #1665.

7 years agoA minor code clean for macro ngx_event_get_conf in ngx_event.h.
chronolaw [Fri, 19 Oct 2018 05:50:36 +0000 (13:50 +0800)]
A minor code clean for macro ngx_event_get_conf in ngx_event.h.

7 years agoSSL: explicitly set maximum version (ticket #1654).
Maxim Dounin [Tue, 23 Oct 2018 19:11:48 +0000 (22:11 +0300)]
SSL: explicitly set maximum version (ticket #1654).

With maximum version explicitly set, TLSv1.3 will not be unexpectedly
enabled if nginx compiled with OpenSSL 1.1.0 (without TLSv1.3 support)
will be run with OpenSSL 1.1.1 (with TLSv1.3 support).

7 years agoUpstream: proxy_socket_keepalive and friends.
Vladimir Homutov [Wed, 3 Oct 2018 11:08:51 +0000 (14:08 +0300)]
Upstream: proxy_socket_keepalive and friends.

The directives enable the use of the SO_KEEPALIVE option on
upstream connections.  By default, the value is left unchanged.

7 years agoVersion bump.
Vladimir Homutov [Wed, 3 Oct 2018 14:02:44 +0000 (17:02 +0300)]
Version bump.

7 years agorelease-1.15.5 tag
Maxim Dounin [Tue, 2 Oct 2018 15:13:52 +0000 (18:13 +0300)]
release-1.15.5 tag

7 years agonginx-1.15.5-RELEASE release-1.15.5
Maxim Dounin [Tue, 2 Oct 2018 15:13:51 +0000 (18:13 +0300)]
nginx-1.15.5-RELEASE

7 years agoSSL: fixed segfault on renegotiation (ticket #1646).
Maxim Dounin [Tue, 2 Oct 2018 14:46:18 +0000 (17:46 +0300)]
SSL: fixed segfault on renegotiation (ticket #1646).

In e3ba4026c02d (1.15.4) nginx own renegotiation checks were disabled
if SSL_OP_NO_RENEGOTIATION is available.  But since SSL_OP_NO_RENEGOTIATION
is only set on a connection, not in an SSL context, SSL_clear_option()
removed it as long as a matching virtual server was found.  This resulted
in a segmentation fault similar to the one fixed in a6902a941279 (1.9.8),
affecting nginx built with OpenSSL 1.1.0h or higher.

To fix this, SSL_OP_NO_RENEGOTIATION is now explicitly set in
ngx_http_ssl_servername() after adjusting options.  Additionally, instead
of c->ssl->renegotiation we now check c->ssl->handshaked, which seems
to be a more correct flag to test, and will prevent the segmentation fault
from happening even if SSL_OP_NO_RENEGOTIATION is not working.

7 years agoFixed off-by-one error in shared zone initialization.
Ruslan Ermilov [Tue, 2 Oct 2018 10:32:52 +0000 (13:32 +0300)]
Fixed off-by-one error in shared zone initialization.

On systems without atomic ops, not enough space was allocated
for mutex's file name during shared zone initialization.

7 years agoSSL: fixed unlocked access to sess_id->len.
Ruslan Ermilov [Tue, 25 Sep 2018 11:07:59 +0000 (14:07 +0300)]
SSL: fixed unlocked access to sess_id->len.

7 years agoVersion bump.
Ruslan Ermilov [Thu, 27 Sep 2018 10:05:39 +0000 (13:05 +0300)]
Version bump.

7 years agorelease-1.15.4 tag
Maxim Dounin [Tue, 25 Sep 2018 15:11:39 +0000 (18:11 +0300)]
release-1.15.4 tag

7 years agonginx-1.15.4-RELEASE release-1.15.4
Maxim Dounin [Tue, 25 Sep 2018 15:11:39 +0000 (18:11 +0300)]
nginx-1.15.4-RELEASE

7 years agoSSL: logging level of "no suitable signature algorithm".
Maxim Dounin [Tue, 25 Sep 2018 11:00:04 +0000 (14:00 +0300)]
SSL: logging level of "no suitable signature algorithm".

The "no suitable signature algorithm" errors are reported by OpenSSL 1.1.1
when using TLSv1.3 if there are no shared signature algorithms.  In
particular, this can happen if the client limits available signature
algorithms to something we don't have a certificate for, or to an empty
list.  For example, the following command:

    openssl s_client -connect 127.0.0.1:8443 -sigalgs rsa_pkcs1_sha1

will always result in the "no suitable signature algorithm" error
as the "rsa_pkcs1_sha1" algorithm refers solely to signatures which
appear in certificates and not defined for use in TLS 1.3 handshake
messages.

The SSL_R_NO_COMMON_SIGNATURE_ALGORITHMS error is what BoringSSL returns
in the same situation.

7 years agoSSL: logging level of "no suitable key share".
Maxim Dounin [Tue, 25 Sep 2018 10:59:53 +0000 (13:59 +0300)]
SSL: logging level of "no suitable key share".

The "no suitable key share" errors are reported by OpenSSL 1.1.1 when
using TLSv1.3 if there are no shared groups (that is, elliptic curves).
In particular, it is easy enough to trigger by using only a single
curve in ssl_ecdh_curve:

    ssl_ecdh_curve secp384r1;

and using a different curve in the client:

    openssl s_client -connect 127.0.0.1:443 -curves prime256v1

On the client side it is seen as "sslv3 alert handshake failure",
"SSL alert number 40":

0:error:14094410:SSL routines:ssl3_read_bytes:sslv3 alert handshake failure:ssl/record/rec_layer_s3.c:1528:SSL alert number 40

It can be also triggered with default ssl_ecdh_curve by using a curve
which is not in the default list (X25519, prime256v1, X448, secp521r1,
secp384r1):

    openssl s_client -connect 127.0.0.1:8443 -curves brainpoolP512r1

Given that many clients hardcode prime256v1, these errors might become
a common problem with TLSv1.3 if ssl_ecdh_curve is redefined.  Previously
this resulted in not using ECDH with such clients, but with TLSv1.3 it
is no longer possible and will result in a handshake failure.

The SSL_R_NO_SHARED_GROUP error is what BoringSSL returns in the same
situation.

Seen at:

https://serverfault.com/questions/932102/nginx-ssl-handshake-error-no-suitable-key-share

7 years agoCache: status must be less then 599 in *_cache_valid directives.
Gena Makhomed [Mon, 24 Sep 2018 17:26:46 +0000 (20:26 +0300)]
Cache: status must be less then 599 in *_cache_valid directives.

Previously, configurations with typo, for example

    fastcgi_cache_valid 200301 302 5m;

successfully pass configuration test. Adding check for status
codes > 599, and such configurations are now properly rejected.

7 years agoRemoved bgcolor attribute on body in error pages and autoindex.
Nova DasSarma [Wed, 19 Sep 2018 14:26:47 +0000 (09:26 -0500)]
Removed bgcolor attribute on body in error pages and autoindex.

The bgcolor attribute overrides compatibility settings in browsers
and leads to undesirable behavior when the default font color is set
to white in the browser, since font-color is not also overridden.

7 years agoSSL: support for TLSv1.3 early data with OpenSSL.
Sergey Kandaurov [Fri, 21 Sep 2018 17:49:12 +0000 (20:49 +0300)]
SSL: support for TLSv1.3 early data with OpenSSL.

In collaboration with Maxim Dounin.

7 years agoSSL: disabled renegotiation checks with SSL_OP_NO_RENEGOTIATION.
Maxim Dounin [Fri, 21 Sep 2018 17:31:32 +0000 (20:31 +0300)]
SSL: disabled renegotiation checks with SSL_OP_NO_RENEGOTIATION.

Following 7319:dcab86115261, as long as SSL_OP_NO_RENEGOTIATION is
defined, it is OpenSSL library responsibility to prevent renegotiation,
so the checks are meaningless.

Additionally, with TLSv1.3 OpenSSL tends to report SSL_CB_HANDSHAKE_START
at various unexpected moments - notably, on KeyUpdate messages and
when sending tickets.  This change prevents unexpected connection
close on KeyUpdate messages and when finishing handshake with upcoming
early data changes.

7 years agoRewrite: removed r->err_status special handling (ticket #1634).
Maxim Dounin [Fri, 21 Sep 2018 12:59:33 +0000 (15:59 +0300)]
Rewrite: removed r->err_status special handling (ticket #1634).

Trying to look into r->err_status in the "return" directive
makes it behave differently than real errors generated in other
parts of the code, and is an endless source of various problems.
This behaviour was introduced in 726:7b71936d5299 (0.4.4) with
the comment "fix: "return" always overrode "error_page" response code".
It is not clear if there were any real cases this was expected to fix,
but there are several cases which are broken due to this change, some
previously fixed (4147:7f64de1cc2c0).

In ticket #1634, the problem is that when r->err_status is set to
a non-special status code, it is not possible to return a response
by simply returning r->err_status.  If this is the case, the only
option is to return script's e->status instead.  An example
configuration:

    location / {
        error_page 404 =200 /err502;
        return 404;
    }

    location = /err502 {
        return 502;
    }

After the change, such a configuration will properly return
standard 502 error, much like it happens when a 502 error is
generated by proxy_pass.

This also fixes the following configuration to properly close
connection as clearly requested by "return 444":

    location / {
        error_page 404 /close;
        return 404;
    }

    location = /close {
        return 444;
    }

Previously, this required "error_page 404 = /close;" to work
as intended.

7 years agoFixed socket leak with "return 444" in error_page (ticket #274).
Maxim Dounin [Fri, 21 Sep 2018 12:59:30 +0000 (15:59 +0300)]
Fixed socket leak with "return 444" in error_page (ticket #274).

Socket leak was observed in the following configuration:

    error_page 400 = /close;

    location = /close {
        return 444;
    }

The problem is that "return 444" triggers termination of the request,
and due to error_page termination thinks that it needs to use a posted
request to clear stack.  But at the early request processing where 400
errors are generated there are no ngx_http_run_posted_requests() calls,
so the request is only terminated after an external event.

Variants of the problem include "error_page 497" instead (ticket #695)
and various other errors generated during early request processing
(405, 414, 421, 494, 495, 496, 501, 505).

The same problem can be also triggered with "return 499" and "return 408"
as both codes trigger ngx_http_terminate_request(), much like "return 444".

To fix this, the patch adds ngx_http_run_posted_requests() calls to
ngx_http_process_request_line() and ngx_http_process_request_headers()
functions, and to ngx_http_v2_run_request() and ngx_http_v2_push_stream()
functions in HTTP/2.

Since the ngx_http_process_request() function is now only called via
other functions which call ngx_http_run_posted_requests(), the call
there is no longer needed and was removed.

7 years agoSSL: restore handlers after blocking.
Maxim Dounin [Mon, 10 Sep 2018 15:57:39 +0000 (18:57 +0300)]
SSL: restore handlers after blocking.

It is possible that after SSL_read() will return SSL_ERROR_WANT_WRITE,
further calls will return SSL_ERROR_WANT_READ without reading any
application data.  We have to call ngx_handle_write_event() and
switch back to normal write handling much like we do if there are some
application data, or the write there will be reported again and again.

Similarly, we have to switch back to normal read handling if there
is saved read handler and SSL_write() returns SSL_ERROR_WANT_WRITE.

7 years agoSSL: corrected SSL_ERROR_WANT_WRITE / SSL_ERROR_WANT_READ logging.
Maxim Dounin [Mon, 10 Sep 2018 15:57:19 +0000 (18:57 +0300)]
SSL: corrected SSL_ERROR_WANT_WRITE / SSL_ERROR_WANT_READ logging.

While SSL_read() most likely to return SSL_ERROR_WANT_WRITE (and SSL_write()
accordingly SSL_ERROR_WANT_READ) during an SSL renegotiation, it is
not necessary mean that a renegotiation was started.  In particular,
it can never happen during a renegotiation or can happen multiple times
during a renegotiation.

Because of the above, misleading "peer started SSL renegotiation" info
messages were replaced with "SSL_read: want write" and "SSL_write: want read"
debug ones.

Additionally, "SSL write handler" and "SSL read handler" are now logged
by the SSL write and read handlers, to make it easier to understand that
temporary SSL handlers are called instead of normal handlers.

7 years agoLingering close changed to handle NGX_AGAIN.
Maxim Dounin [Mon, 10 Sep 2018 15:57:13 +0000 (18:57 +0300)]
Lingering close changed to handle NGX_AGAIN.

The "do { c->recv() } while (c->read->ready)" form used in the
ngx_http_lingering_close_handler() is not really correct, as for
example with SSL c->read->ready may be still set when returning NGX_AGAIN
due to SSL_ERROR_WANT_WRITE.  Therefore the above might be an infinite loop.

This doesn't really matter in lingering close, as we shutdown write side
of the socket anyway and also disable renegotiation (and even without shutdown
and with renegotiation it requires using very large certificate chain and
tuning socket buffers to trigger SSL_ERROR_WANT_WRITE).  But for the sake of
correctness added an NGX_AGAIN check.

7 years agogRPC: disabled keepalive when sending control frames was blocked.
Maxim Dounin [Mon, 3 Sep 2018 16:34:02 +0000 (19:34 +0300)]
gRPC: disabled keepalive when sending control frames was blocked.

If sending request body was not completed (u->request_body_sent is not set),
the upstream keepalive module won't save such a connection.  However, it
is theoretically possible (though highly unlikely) that sending of some
control frames can be blocked after the request body was sent.  The
ctx->output_blocked flag introduced to disable keepalive in such cases.

7 years agogRPC: improved keepalive handling.
Maxim Dounin [Mon, 3 Sep 2018 16:34:01 +0000 (19:34 +0300)]
gRPC: improved keepalive handling.

The code is now able to parse additional control frames after
the response is received, and can send control frames as well.
This fixes keepalive problems as observed with grpc-c, which can
send window update and ping frames after the response, see
http://mailman.nginx.org/pipermail/nginx/2018-August/056620.html.

7 years agoUwsgi: added a check on maximum uwsgi request size.
Maxim Dounin [Mon, 3 Sep 2018 16:17:06 +0000 (19:17 +0300)]
Uwsgi: added a check on maximum uwsgi request size.

Requested by Chris Caputo.

7 years agoUwsgi: style.
Maxim Dounin [Mon, 3 Sep 2018 16:17:01 +0000 (19:17 +0300)]
Uwsgi: style.

7 years agoVersion bump.
Roman Arutyunyan [Thu, 30 Aug 2018 11:42:15 +0000 (14:42 +0300)]
Version bump.

7 years agoStream: avoid potential infinite loop at preread phase.
Roman Arutyunyan [Wed, 29 Aug 2018 12:56:42 +0000 (15:56 +0300)]
Stream: avoid potential infinite loop at preread phase.

Previously the preread phase code ignored NGX_AGAIN value returned from
c->recv() and relied only on c->read->ready.  But this flag is not reliable and
should only be checked for optimization purposes.  For example, when using
SSL, c->read->ready may be set when no input is available.  This can lead to
calling preread handler infinitely in a loop.

7 years agorelease-1.15.3 tag
Maxim Dounin [Tue, 28 Aug 2018 15:36:00 +0000 (18:36 +0300)]
release-1.15.3 tag

7 years agonginx-1.15.3-RELEASE release-1.15.3
Maxim Dounin [Tue, 28 Aug 2018 15:36:00 +0000 (18:36 +0300)]
nginx-1.15.3-RELEASE

7 years agoUpdated OpenSSL used for win32 builds.
Maxim Dounin [Tue, 28 Aug 2018 12:05:41 +0000 (15:05 +0300)]
Updated OpenSSL used for win32 builds.

7 years agoUpstream: fixed request chain traversal (ticket #1618).
Vladimir Homutov [Fri, 24 Aug 2018 09:19:37 +0000 (12:19 +0300)]
Upstream: fixed request chain traversal (ticket #1618).

The problem does not manifest itself currently, because in case of
non-buffered reading, chain link created by u->create_request method
consists of a single element.

Found by PVS-Studio.

7 years agoUpstream keepalive: keepalive_requests directive.
Maxim Dounin [Fri, 10 Aug 2018 18:54:46 +0000 (21:54 +0300)]
Upstream keepalive: keepalive_requests directive.

The directive configures maximum number of requests allowed on
a connection kept in the cache.  Once a connection reaches the number
of requests configured, it is no longer saved to the cache.
The default is 100.

Much like keepalive_requests for client connections, this is mostly
a safeguard to make sure connections are closed periodically and the
memory allocated from the connection pool is freed.

7 years agoUpstream keepalive: keepalive_timeout directive.
Maxim Dounin [Fri, 10 Aug 2018 18:54:23 +0000 (21:54 +0300)]
Upstream keepalive: keepalive_timeout directive.

The directive configures maximum time a connection can be kept in the
cache.  By configuring a time which is smaller than the corresponding
timeout on the backend side one can avoid the race between closing
a connection by the backend and nginx trying to use the same connection
to send a request at the same time.

7 years agoUpstream keepalive: comment added.
Maxim Dounin [Fri, 10 Aug 2018 18:54:17 +0000 (21:54 +0300)]
Upstream keepalive: comment added.

7 years agoSSL: fixed build with LibreSSL 2.8.0 (ticket #1605).
Maxim Dounin [Fri, 10 Aug 2018 17:49:06 +0000 (20:49 +0300)]
SSL: fixed build with LibreSSL 2.8.0 (ticket #1605).

LibreSSL 2.8.0 "added const annotations to many existing APIs from OpenSSL,
making interoperability easier for downstream applications".  This includes
the const change in the SSL_CTX_sess_set_get_cb() callback function (see
9dd43f4ef67e), which breaks compilation.

To fix this, added a condition on how we redefine OPENSSL_VERSION_NUMBER
when working with LibreSSL (see 382fc7069e3a).  With LibreSSL 2.8.0,
we now set OPENSSL_VERSION_NUMBER to 0x1010000fL (OpenSSL 1.1.0), so the
appropriate conditions in the code will use "const" as it happens with
OpenSSL 1.1.0 and later versions.

7 years agoA link to the error_log directive on nginx.org removed.
Maxim Konovalov [Fri, 10 Aug 2018 11:15:05 +0000 (14:15 +0300)]
A link to the error_log directive on nginx.org removed.

It makes more harm than good for users and nginx.org
infrastructure.

7 years agoHTTP/2: workaround for clients which fail on table size updates.
Maxim Dounin [Thu, 9 Aug 2018 17:12:17 +0000 (20:12 +0300)]
HTTP/2: workaround for clients which fail on table size updates.

There are clients which cannot handle HPACK's dynamic table size updates
as added in 12cadc4669a7 (1.13.6).  Notably, old versions of OkHttp library
are known to fail on it (ticket #1397).

This change makes it possible to work with such clients by only sending
dynamic table size updates in response to SETTINGS_HEADER_TABLE_SIZE.  As
a downside, clients which do not use SETTINGS_HEADER_TABLE_SIZE will
continue to maintain default 4k table.

7 years agoSkipping spaces in configuration files (ticket #1557).
Maxim Dounin [Thu, 9 Aug 2018 09:15:42 +0000 (12:15 +0300)]
Skipping spaces in configuration files (ticket #1557).

Previously, a chunk of spaces larger than NGX_CONF_BUFFER (4096 bytes)
resulted in the "too long parameter" error during parsing such a
configuration.  This was because the code only set start and start_line
on non-whitespace characters, and hence adjacent whitespace characters
were preserved when reading additional data from the configuration file.
Fix is to always move start and start_line if the last character was
a space.

7 years agoSSL: support for TLSv1.3 early data with BoringSSL.
Maxim Dounin [Mon, 6 Aug 2018 23:16:07 +0000 (02:16 +0300)]
SSL: support for TLSv1.3 early data with BoringSSL.

Early data AKA 0-RTT mode is enabled as long as "ssl_early_data on" is
specified in the configuration (default is off).

The $ssl_early_data variable evaluates to "1" if the SSL handshake
isn't yet completed, and can be used to set the Early-Data header as
per draft-ietf-httpbis-replay-04.

7 years agoSSL: enabled TLSv1.3 with BoringSSL.
Maxim Dounin [Mon, 6 Aug 2018 23:15:28 +0000 (02:15 +0300)]
SSL: enabled TLSv1.3 with BoringSSL.

BoringSSL currently requires SSL_CTX_set_max_proto_version(TLS1_3_VERSION)
to be able to enable TLS 1.3.  This is because by default max protocol
version is set to TLS 1.2, and the SSL_OP_NO_* options are merely used
as a blacklist within the version range specified using the
SSL_CTX_set_min_proto_version() and SSL_CTX_set_max_proto_version()
functions.

With this change, we now call SSL_CTX_set_max_proto_version() with an
explicit maximum version set.  This enables TLS 1.3 with BoringSSL.
As a side effect, this change also limits maximum protocol version to
the newest protocol we know about, TLS 1.3.  This seems to be a good
change, as enabling unknown protocols might have unexpected results.

Additionally, we now explicitly call SSL_CTX_set_min_proto_version()
with 0.  This is expected to help with Debian system-wide default
of MinProtocol set to TLSv1.2, see
http://mailman.nginx.org/pipermail/nginx-ru/2017-October/060411.html.

Note that there is no SSL_CTX_set_min_proto_version macro in BoringSSL,
so we call SSL_CTX_set_min_proto_version() and SSL_CTX_set_max_proto_version()
as long as the TLS1_3_VERSION macro is defined.

7 years agoDav: removed dead store after 8e7a5de61664.
Sergey Kandaurov [Thu, 2 Aug 2018 10:19:48 +0000 (13:19 +0300)]
Dav: removed dead store after 8e7a5de61664.

Found by Clang Static Analyzer.

7 years agoDav: changed COPY of a file to preserve access mask.
Maxim Dounin [Tue, 31 Jul 2018 23:12:21 +0000 (02:12 +0300)]
Dav: changed COPY of a file to preserve access mask.

The behaviour is now in line with COPY of a directory with contents,
which preserves access masks on individual files, as well as the "cp"
command.

Requested by Roman Arutyunyan.

7 years agoDav: changed ngx_copy_file() to preserve access and mtime.
Maxim Dounin [Tue, 31 Jul 2018 23:12:11 +0000 (02:12 +0300)]
Dav: changed ngx_copy_file() to preserve access and mtime.

This fixes wrong permissions and file time after cross-device MOVE
in the DAV module (ticket #1577).  Broken in 8101d9101ed8 (0.8.9) when
cross-device copying was introduced in ngx_ext_rename_file().

With this change, ngx_copy_file() always calls ngx_set_file_time(),
either with the time provided, or with the time from the original file.
This is considered acceptable given that copying the file is costly anyway,
and optimizing cases when we do not need to preserve time will require
interface changes.

7 years agoDav: fixed ngx_copy_file() to truncate destination file.
Maxim Dounin [Tue, 31 Jul 2018 23:11:58 +0000 (02:11 +0300)]
Dav: fixed ngx_copy_file() to truncate destination file.

Previously, ngx_open_file(NGX_FILE_CREATE_OR_OPEN) was used, resulting
in destination file being partially rewritten if exists.  Notably,
this affected WebDAV COPY command (ticket #1576).

7 years agoConfigure: fixed compiler warnings with "-Wall -Wextra".
Sergey Kandaurov [Tue, 24 Jul 2018 15:46:54 +0000 (18:46 +0300)]
Configure: fixed compiler warnings with "-Wall -Wextra".

7 years agoVersion bump.
Sergey Kandaurov [Tue, 24 Jul 2018 15:46:18 +0000 (18:46 +0300)]
Version bump.

7 years agorelease-1.15.2 tag
Maxim Dounin [Tue, 24 Jul 2018 13:11:00 +0000 (16:11 +0300)]
release-1.15.2 tag

7 years agonginx-1.15.2-RELEASE release-1.15.2
Maxim Dounin [Tue, 24 Jul 2018 13:10:59 +0000 (16:10 +0300)]
nginx-1.15.2-RELEASE

7 years agoFixed NGX_TID_T_FMT format specification for uint64_t.
Maxim Dounin [Sun, 22 Jul 2018 01:03:40 +0000 (04:03 +0300)]
Fixed NGX_TID_T_FMT format specification for uint64_t.

Previously, "%uA" was used, which corresponds to ngx_atomic_uint_t.
Size of ngx_atomic_uint_t can be easily different from uint64_t,
leading to undefined results.

7 years agoStream ssl_preread: added SSLv2 Client Hello support.
Sergey Kandaurov [Wed, 18 Jul 2018 15:51:25 +0000 (18:51 +0300)]
Stream ssl_preread: added SSLv2 Client Hello support.

In particular, it was not possible to obtain SSLv2 protocol version.

7 years agoFixed invalid access to location defined as an empty string.
Ruslan Ermilov [Tue, 17 Jul 2018 12:30:43 +0000 (15:30 +0300)]
Fixed invalid access to location defined as an empty string.

7 years agoSSL: save sessions for upstream peers using a callback function.
Sergey Kandaurov [Tue, 17 Jul 2018 09:53:23 +0000 (12:53 +0300)]
SSL: save sessions for upstream peers using a callback function.

In TLSv1.3, NewSessionTicket messages arrive after the handshake and
can come at any time.  Therefore we use a callback to save the session
when we know about it.  This approach works for < TLSv1.3 as well.
The callback function is set once per location on merge phase.

Since SSL_get_session() in BoringSSL returns an unresumable session for
TLSv1.3, peer save_session() methods have been updated as well to use a
session supplied within the callback.  To preserve API, the session is
cached in c->ssl->session.  It is preferably accessed in save_session()
methods by ngx_ssl_get_session() and ngx_ssl_get0_session() wrappers.

7 years agoSSL: use of the SSL_OP_NO_RENEGOTIATION option (ticket #1376).
Maxim Dounin [Mon, 16 Jul 2018 14:47:48 +0000 (17:47 +0300)]
SSL: use of the SSL_OP_NO_RENEGOTIATION option (ticket #1376).

The SSL_OP_NO_RENEGOTIATION option is available in OpenSSL 1.1.0h+ and can
save some CPU cycles on renegotiation attempts.

7 years agoSSL: fixed SSL_clear_options() usage with OpenSSL 1.1.0+.
Maxim Dounin [Mon, 16 Jul 2018 14:47:20 +0000 (17:47 +0300)]
SSL: fixed SSL_clear_options() usage with OpenSSL 1.1.0+.

In OpenSSL 1.1.0 the SSL_CTRL_CLEAR_OPTIONS macro was removed, so
conditional compilation test on it results in SSL_clear_options()
and SSL_CTX_clear_options() not being used.  Notably, this caused
"ssl_prefer_server_ciphers off" to not work in SNI-based virtual
servers if server preference was switched on in the default server.

It looks like the only possible fix is to test OPENSSL_VERSION_NUMBER
explicitly.

7 years agoSSL: logging levels of "unsupported protocol", "version too low".
Maxim Dounin [Mon, 16 Jul 2018 14:47:18 +0000 (17:47 +0300)]
SSL: logging levels of "unsupported protocol", "version too low".

Starting with OpenSSL 1.1.0, SSL_R_UNSUPPORTED_PROTOCOL instead of
SSL_R_UNKNOWN_PROTOCOL is reported when a protocol is disabled via
an SSL_OP_NO_* option.

Additionally, SSL_R_VERSION_TOO_LOW is reported when using MinProtocol
or when seclevel checks (as set by @SECLEVEL=n in the cipher string)
rejects a protocol, and this is what happens with SSLv3 and @SECLEVEL=1,
which is the default.

There is also the SSL_R_VERSION_TOO_HIGH error code, but it looks like
it is not possible to trigger it.

7 years agoEvents: added configuration check on the number of connections.
Maxim Dounin [Thu, 12 Jul 2018 16:50:07 +0000 (19:50 +0300)]
Events: added configuration check on the number of connections.

There should be at least one worker connection for each listening socket,
plus an additional connection for channel between worker and master,
or starting worker processes will fail.

7 years agoEvents: moved sockets cloning to ngx_event_init_conf().
Maxim Dounin [Thu, 12 Jul 2018 16:50:02 +0000 (19:50 +0300)]
Events: moved sockets cloning to ngx_event_init_conf().

Previously, listenings sockets were not cloned if the worker_processes
directive was specified after "listen ... reuseport".

This also simplifies upcoming configuration check on the number
of worker connections, as it needs to know the number of listening
sockets before cloning.

7 years agoStream ssl_preread: $ssl_preread_protocol variable.
Roman Arutyunyan [Wed, 11 Jul 2018 14:56:51 +0000 (17:56 +0300)]
Stream ssl_preread: $ssl_preread_protocol variable.

The variable keeps the latest SSL protocol version supported by the client.
The variable has the same format as $ssl_protocol.

The version is read from the client_version field of ClientHello.  If the
supported_versions extension is present in the ClientHello, then the version
is set to TLSv1.3.

7 years agoAllow resetting connections closed by "return 444" (ticket #905).
Ruslan Ermilov [Thu, 12 Jul 2018 09:50:20 +0000 (12:50 +0300)]
Allow resetting connections closed by "return 444" (ticket #905).

If reset_timedout_connection is on, TCP connections closed by
"return 444" will be reset instead of a normal close.

7 years agoResolver: retry sending queries on errors (ticket #1511).
Maxim Dounin [Thu, 5 Jul 2018 19:21:14 +0000 (22:21 +0300)]
Resolver: retry sending queries on errors (ticket #1511).

Errors when sending UDP datagrams can happen, e.g., when local IP address
changes (see fa0e093b64d7), or an unavailable DNS server on the LAN can cause
send() to fail with EHOSTDOWN on BSD systems.  If this happens during
initial query, retry sending immediately, to a different DNS server when
possible.  If this is not enough, allow normal resend to happen by ignoring
the return code of the second ngx_resolver_send_query() call, much like we
do in ngx_resolver_resend().

7 years agoSSL: logging level of "https proxy request" errors.
Maxim Dounin [Thu, 5 Jul 2018 17:45:29 +0000 (20:45 +0300)]
SSL: logging level of "https proxy request" errors.

The "http request" and "https proxy request" errors cannot happen
with HTTP due to pre-handshake checks in ngx_http_ssl_handshake(),
but can happen when SSL is used in stream and mail modules.

7 years agoVersion bump.
Maxim Dounin [Thu, 5 Jul 2018 17:44:58 +0000 (20:44 +0300)]
Version bump.

7 years agorelease-1.15.1 tag
Maxim Dounin [Tue, 3 Jul 2018 15:07:44 +0000 (18:07 +0300)]
release-1.15.1 tag

7 years agonginx-1.15.1-RELEASE release-1.15.1
Maxim Dounin [Tue, 3 Jul 2018 15:07:43 +0000 (18:07 +0300)]
nginx-1.15.1-RELEASE

7 years agoUpstream: fixed tcp_nopush with gRPC.
Maxim Dounin [Mon, 2 Jul 2018 16:03:04 +0000 (19:03 +0300)]
Upstream: fixed tcp_nopush with gRPC.

With gRPC it is possible that a request sending is blocked due to flow
control.  Moreover, further sending might be only allowed once the
backend sees all the data we've already sent.  With such a backend
it is required to clear the TCP_NOPUSH socket option to make sure all
the data we've sent are actually delivered to the backend.

As such, we now clear TCP_NOPUSH in ngx_http_upstream_send_request()
also on NGX_AGAIN if c->write->ready is set.  This fixes a test (which
waits for all the 64k bytes as per initial window before allowing more
bytes) with sendfile enabled when the body was written to a file
in a different context.

7 years agoUpstream: fixed unexpected tcp_nopush usage on peer connections.
Maxim Dounin [Mon, 2 Jul 2018 16:02:31 +0000 (19:02 +0300)]
Upstream: fixed unexpected tcp_nopush usage on peer connections.

Now tcp_nopush on peer connections is disabled if it is disabled on
the client connection, similar to how we handle c->sendfile.  Previously,
tcp_nopush was always used on upstream connections, regardless of
the "tcp_nopush" directive.

7 years agogRPC: clearing buffers in ngx_http_grpc_get_buf().
Maxim Dounin [Mon, 2 Jul 2018 16:02:08 +0000 (19:02 +0300)]
gRPC: clearing buffers in ngx_http_grpc_get_buf().

We copy input buffers to our buffers, so various flags might be
unexpectedly set in buffers returned by ngx_chain_get_free_buf().

In particular, the b->in_file flag might be set when the body was
written to a file in a different context.  With sendfile enabled this
in turn might result in protocol corruption if such a buffer was reused
for a control frame.

Make sure to clear buffers and set only fields we really need to be set.

7 years agoAdded FreeBSD support for "listen ... reuseport".
Ruslan Ermilov [Mon, 2 Jul 2018 10:54:33 +0000 (13:54 +0300)]
Added FreeBSD support for "listen ... reuseport".

7 years agoMIME: added font/woff2 type (ticket #1243).
Valentin Bartenev [Fri, 15 Jun 2018 14:29:55 +0000 (17:29 +0300)]
MIME: added font/woff2 type (ticket #1243).

7 years agoMIME: changed type for woff to font/woff (ticket #1243).
Valentin Bartenev [Fri, 15 Jun 2018 14:29:55 +0000 (17:29 +0300)]
MIME: changed type for woff to font/woff (ticket #1243).

According to RFC 8081 the previously used application/font-woff
type is deprecated.

7 years agoUpstream: ngx_http_upstream_random module.
Vladimir Homutov [Fri, 15 Jun 2018 08:46:14 +0000 (11:46 +0300)]
Upstream: ngx_http_upstream_random module.

The module implements random load-balancing algorithm with optional second
choice.  In the latter case, the best of two servers is chosen, accounting
number of connections and server weight.

Example:

upstream u {
    random [two [least_conn]];

    server 127.0.0.1:8080;
    server 127.0.0.1:8081;
    server 127.0.0.1:8082;
    server 127.0.0.1:8083;
}

7 years agoUpstream: improved peer selection concurrency for hash and ip_hash.
Ruslan Ermilov [Thu, 14 Jun 2018 04:03:50 +0000 (07:03 +0300)]
Upstream: improved peer selection concurrency for hash and ip_hash.

7 years agoResolver: require name servers.
Ruslan Ermilov [Wed, 13 Jun 2018 19:37:49 +0000 (22:37 +0300)]
Resolver: require name servers.

7 years agoResolver: allocate resolver from configuration pool.
Ruslan Ermilov [Wed, 13 Jun 2018 19:37:42 +0000 (22:37 +0300)]
Resolver: allocate resolver from configuration pool.

Before 4a8c9139e579, ngx_resolver_create() didn't use configuration
pool, and allocations were done using malloc().

In 016352c19049, when resolver gained support of several servers,
new allocations were done from the pool.

7 years agoUpstream: disable body cleanup with preserve_output (ticket #1565).
Maxim Dounin [Wed, 13 Jun 2018 12:28:11 +0000 (15:28 +0300)]
Upstream: disable body cleanup with preserve_output (ticket #1565).

With u->conf->preserve_output set the request body file might be used
after the response header is sent, so avoid cleaning it.  (Normally
this is not a problem as u->conf->preserve_output is only set with
r->request_body_no_buffering, but the request body might be already
written to a file in a different context.)

7 years agoHTTP/2: use scheme from original request for pushes (closes #1549).
Ruslan Ermilov [Thu, 7 Jun 2018 17:04:22 +0000 (20:04 +0300)]
HTTP/2: use scheme from original request for pushes (closes #1549).

Instead of the connection scheme, use scheme from the original request.
This fixes pushes when SSL is terminated by a proxy server in front of
nginx.

7 years agoAdded r->schema.
Ruslan Ermilov [Thu, 7 Jun 2018 17:01:41 +0000 (20:01 +0300)]
Added r->schema.

For HTTP/1, it keeps scheme from the absolute form of URI.
For HTTP/2, the :scheme request pseudo-header field value.

7 years agoRemoved extraneous check while processing request line.
Ruslan Ermilov [Thu, 7 Jun 2018 16:53:43 +0000 (19:53 +0300)]
Removed extraneous check while processing request line.

7 years agoHTTP/2: validate client request scheme.
Ruslan Ermilov [Thu, 7 Jun 2018 08:47:10 +0000 (11:47 +0300)]
HTTP/2: validate client request scheme.

The scheme is validated as per RFC 3986, Section 3.1.

7 years agoAllowed digits, '+', '-', and '.' in scheme names as per RFC 3986.
Ruslan Ermilov [Thu, 24 May 2018 09:06:35 +0000 (12:06 +0300)]
Allowed digits, '+', '-', and '.' in scheme names as per RFC 3986.

7 years agoSSL: removed extra prototype.
Sergey Kandaurov [Wed, 6 Jun 2018 10:31:05 +0000 (13:31 +0300)]
SSL: removed extra prototype.

7 years agoAdded missing space after ngx_close_socket_n.
Maxim Dounin [Tue, 5 Jun 2018 14:41:34 +0000 (17:41 +0300)]
Added missing space after ngx_close_socket_n.