]> git.kaiwu.me - nginx.git/log
nginx.git
4 years agoConfigure: ordered directories.
Ruslan Ermilov [Tue, 21 Sep 2021 11:46:25 +0000 (14:46 +0300)]
Configure: ordered directories.

4 years agoConfigure: simplified condition.
Ruslan Ermilov [Tue, 21 Sep 2021 11:46:17 +0000 (14:46 +0300)]
Configure: simplified condition.

4 years agoHTTP/3: make ngx_http_log_error() static again.
Roman Arutyunyan [Fri, 17 Sep 2021 13:32:23 +0000 (16:32 +0300)]
HTTP/3: make ngx_http_log_error() static again.

This function was only referenced from ngx_http_v3_create_push_request() to
initialize push connection log.  Now the log handler is copied from the parent
request connection.

The change reduces diff to the default branch.

4 years agoQUIC: separate event handling functions.
Roman Arutyunyan [Thu, 9 Sep 2021 13:55:00 +0000 (16:55 +0300)]
QUIC: separate event handling functions.

The functions ngx_quic_handle_read_event() and ngx_quic_handle_write_event()
are added.  Previously this code was a part of ngx_handle_read_event() and
ngx_handle_write_event().

The change simplifies ngx_handle_read_event() and ngx_handle_write_event()
by moving QUIC-related code to a QUIC source file.

4 years agoHTTP/3: added CONNECT and TRACE methods rejection.
Sergey Kandaurov [Thu, 16 Sep 2021 10:13:22 +0000 (13:13 +0300)]
HTTP/3: added CONNECT and TRACE methods rejection.

It has got lost in e1eb7f4ca9f1, let alone a subsequent update in 63c66b7cc07c.

4 years agoRemoved NGX_OPENSSL_QUIC macro, NGX_QUIC is enough.
Ruslan Ermilov [Tue, 14 Sep 2021 09:09:13 +0000 (12:09 +0300)]
Removed NGX_OPENSSL_QUIC macro, NGX_QUIC is enough.

4 years agoHTTP/3: added debug logging of response fields.
Sergey Kandaurov [Mon, 13 Sep 2021 13:25:37 +0000 (16:25 +0300)]
HTTP/3: added debug logging of response fields.

Because of QPACK compression it's hard to see what fields are actually
sent by the server.

4 years agoHTTP/3: Huffman encoding for the Location response field.
Sergey Kandaurov [Mon, 13 Sep 2021 13:25:32 +0000 (16:25 +0300)]
HTTP/3: Huffman encoding for the Location response field.

4 years agoHTTP/3: Huffman encoding for the Last-Modified response field.
Sergey Kandaurov [Mon, 13 Sep 2021 13:25:31 +0000 (16:25 +0300)]
HTTP/3: Huffman encoding for the Last-Modified response field.

4 years agoHTTP/3: Huffman encoding for the Content-Type response field.
Sergey Kandaurov [Mon, 13 Sep 2021 13:25:23 +0000 (16:25 +0300)]
HTTP/3: Huffman encoding for the Content-Type response field.

4 years agoHTTP/3: implemented QPACK Huffman encoding for response fields.
Sergey Kandaurov [Mon, 13 Sep 2021 13:25:08 +0000 (16:25 +0300)]
HTTP/3: implemented QPACK Huffman encoding for response fields.

4 years agoHTTP/3: reading body buffering in filters.
Roman Arutyunyan [Thu, 9 Sep 2021 12:47:29 +0000 (15:47 +0300)]
HTTP/3: reading body buffering in filters.

This change follows similar changes in HTTP/1 and HTTP/2 in 9cf043a5d9ca.

4 years agoQUIC: removed Firefox workaround for trailing zeroes in datagrams.
Sergey Kandaurov [Thu, 9 Sep 2021 16:12:27 +0000 (19:12 +0300)]
QUIC: removed Firefox workaround for trailing zeroes in datagrams.

This became unnecessary after discarding invalid packets since a6784cf32c13.

4 years agoQUIC: macro style.
Ruslan Ermilov [Thu, 9 Sep 2021 12:40:08 +0000 (15:40 +0300)]
QUIC: macro style.

4 years agoChanged the OpenSSL QUIC support detection.
Ruslan Ermilov [Thu, 9 Sep 2021 12:34:00 +0000 (15:34 +0300)]
Changed the OpenSSL QUIC support detection.

As was changed in 253cf267f95a.

4 years agoMerged with the default branch.
Sergey Kandaurov [Wed, 8 Sep 2021 12:53:00 +0000 (15:53 +0300)]
Merged with the default branch.

4 years agorelease-1.21.3 tag
Maxim Dounin [Tue, 7 Sep 2021 15:21:03 +0000 (18:21 +0300)]
release-1.21.3 tag

4 years agonginx-1.21.3-RELEASE release-1.21.3
Maxim Dounin [Tue, 7 Sep 2021 15:21:02 +0000 (18:21 +0300)]
nginx-1.21.3-RELEASE

4 years agoQUIC: store QUIC connection fd in stream fake connection.
Roman Arutyunyan [Mon, 6 Sep 2021 13:59:00 +0000 (16:59 +0300)]
QUIC: store QUIC connection fd in stream fake connection.

Previously it had -1 as fd.  This fixes proxying, which relies on downstream
connection having a real fd.  Also, this reduces diff to the default branch for
ngx_close_connection().

4 years agoHTTP/2: optimized processing of small DATA frames.
Maxim Dounin [Mon, 6 Sep 2021 11:54:50 +0000 (14:54 +0300)]
HTTP/2: optimized processing of small DATA frames.

The request body filter chain is no longer called after processing
a DATA frame.  Instead, we now post a read event to do this.  This
ensures that multiple small DATA frames read during the same event loop
iteration are coalesced together, resulting in much faster processing.

Since rb->buf can now contain unprocessed data, window update is no
longer sent in ngx_http_v2_state_read_data() in case of flow control
being used due to filter buffering.  Instead, window will be updated
by ngx_http_v2_read_client_request_body_handler() in the posted read
event.

4 years agoHTTP/2: fixed timers left after request body reading.
Maxim Dounin [Mon, 6 Sep 2021 11:54:48 +0000 (14:54 +0300)]
HTTP/2: fixed timers left after request body reading.

Following rb->filter_need_buffering changes, request body reading is
only finished after the filter chain is called and rb->last_saved is set.
As such, with r->request_body_no_buffering, timer on fc->read is no
longer removed when the last part of the body is received, potentially
resulting in incorrect behaviour.

The fix is to call ngx_http_v2_process_request_body() from the
ngx_http_v2_read_unbuffered_request_body() function instead of
directly calling ngx_http_v2_filter_request_body(), so the timer
is properly removed.

4 years agoHTTP/2: fixed window updates when buffering in filters.
Maxim Dounin [Mon, 6 Sep 2021 11:54:47 +0000 (14:54 +0300)]
HTTP/2: fixed window updates when buffering in filters.

In the body read handler, the window was incorrectly calculated
based on the full buffer size instead of the amount of free space
in the buffer.  If the request body is buffered by a filter, and
the buffer is not empty after the read event is generated by the
filter to resume request body processing, this could result in
"http2 negative window update" alerts.

Further, in the body ready handler and in ngx_http_v2_state_read_data()
the buffer wasn't cleared when the data were already written to disk,
so the client might stuck without window updates.

4 years agoQUIC: fixed null pointer dereference in MAX_DATA handler.
Mariano Di Martino [Fri, 3 Sep 2021 11:23:50 +0000 (14:23 +0300)]
QUIC: fixed null pointer dereference in MAX_DATA handler.

If a MAX_DATA frame was received before any stream was created, then the worker
process would crash in nginx_quic_handle_max_data_frame() while traversing the
stream tree.  The issue is solved by adding a check that makes sure the tree is
not empty.

4 years agoFixed debug logging.
Roman Arutyunyan [Thu, 2 Sep 2021 09:25:37 +0000 (12:25 +0300)]
Fixed debug logging.

4 years agoVersion bump.
Roman Arutyunyan [Fri, 3 Sep 2021 14:19:33 +0000 (17:19 +0300)]
Version bump.

4 years agoREADME: HTTP/3 trailers are now supported.
Sergey Kandaurov [Wed, 1 Sep 2021 08:12:23 +0000 (11:12 +0300)]
README: HTTP/3 trailers are now supported.

4 years agoMerged with the default branch.
Sergey Kandaurov [Wed, 1 Sep 2021 07:57:25 +0000 (10:57 +0300)]
Merged with the default branch.

4 years agorelease-1.21.2 tag
Maxim Dounin [Tue, 31 Aug 2021 15:13:47 +0000 (18:13 +0300)]
release-1.21.2 tag

4 years agonginx-1.21.2-RELEASE release-1.21.2
Maxim Dounin [Tue, 31 Aug 2021 15:13:46 +0000 (18:13 +0300)]
nginx-1.21.2-RELEASE

4 years agoUpdated OpenSSL used for win32 builds.
Maxim Dounin [Tue, 31 Aug 2021 14:54:54 +0000 (17:54 +0300)]
Updated OpenSSL used for win32 builds.

4 years agoHTTP/2: avoid memcpy() with NULL source and zero length.
Maxim Dounin [Tue, 31 Aug 2021 13:44:13 +0000 (16:44 +0300)]
HTTP/2: avoid memcpy() with NULL source and zero length.

Prodded by Clang Static Analyzer.

4 years agoGive GCC atomics precedence over deprecated Darwin atomic(3).
Sergey Kandaurov [Mon, 30 Aug 2021 11:45:21 +0000 (14:45 +0300)]
Give GCC atomics precedence over deprecated Darwin atomic(3).

This allows to build nginx on macOS with -Wdeprecated-declarations.

4 years agoRequest body: reading body buffering in filters.
Maxim Dounin [Sun, 29 Aug 2021 19:22:02 +0000 (22:22 +0300)]
Request body: reading body buffering in filters.

If a filter wants to buffer the request body during reading (for
example, to check an external scanner), it can now do so.  To make
it possible, the code now checks rb->last_saved (introduced in the
previous change) along with rb->rest == 0.

Since in HTTP/2 this requires flow control to avoid overflowing the
request body buffer, so filters which need buffering have to set
the rb->filter_need_buffering flag on the first filter call.  (Note
that each filter is expected to call the next filter, so all filters
will be able set the flag if needed.)

4 years agoRequest body: introduced rb->last_saved flag.
Maxim Dounin [Sun, 29 Aug 2021 19:21:03 +0000 (22:21 +0300)]
Request body: introduced rb->last_saved flag.

It indicates that the last buffer was received by the save filter,
and can be used to check this at higher levels.  To be used in the
following changes.

4 years agoRequest body: added alert to catch duplicate body saving.
Maxim Dounin [Sun, 29 Aug 2021 19:20:54 +0000 (22:20 +0300)]
Request body: added alert to catch duplicate body saving.

If due to an error ngx_http_request_body_save_filter() is called
more than once with rb->rest == 0, this used to result in a segmentation
fault.  Added an alert to catch such errors, just in case.

4 years agoRequest body: missing comments about initialization.
Maxim Dounin [Sun, 29 Aug 2021 19:20:49 +0000 (22:20 +0300)]
Request body: missing comments about initialization.

4 years agoHTTP/2: improved handling of preread unbuffered requests.
Maxim Dounin [Sun, 29 Aug 2021 19:20:44 +0000 (22:20 +0300)]
HTTP/2: improved handling of preread unbuffered requests.

Previously, fully preread unbuffered requests larger than client body
buffer size were saved to disk, despite the fact that "unbuffered" is
expected to imply no disk buffering.

4 years agoHTTP/2: improved handling of END_STREAM in a separate DATA frame.
Maxim Dounin [Sun, 29 Aug 2021 19:20:38 +0000 (22:20 +0300)]
HTTP/2: improved handling of END_STREAM in a separate DATA frame.

The save body filter saves the request body to disk once the buffer is full.
Yet in HTTP/2 this might happen even if there is no need to save anything
to disk, notably when content length is known and the END_STREAM flag is
sent in a separate empty DATA frame.  Workaround is to provide additional
byte in the buffer, so saving the request body won't be triggered.

This fixes unexpected request body disk buffering in HTTP/2 observed after
the previous change when content length is known and the END_STREAM flag
is sent in a separate empty DATA frame.

4 years agoHTTP/2: reworked body reading to better match HTTP/1.x code.
Maxim Dounin [Sun, 29 Aug 2021 19:20:36 +0000 (22:20 +0300)]
HTTP/2: reworked body reading to better match HTTP/1.x code.

In particular, now the code always uses a buffer limited by
client_body_buffer_size.  At the cost of an additional copy it
ensures that small DATA frames are not directly mapped to small
write() syscalls, but rather buffered in memory before writing.
Further, requests without Content-Length are no longer forced
to use temporary files.

4 years agoHTTP/2: improved body reading logging.
Maxim Dounin [Sun, 29 Aug 2021 19:20:34 +0000 (22:20 +0300)]
HTTP/2: improved body reading logging.

4 years agoUpstream: fixed timeouts with gRPC, SSL and select (ticket #2229).
Maxim Dounin [Fri, 20 Aug 2021 00:53:56 +0000 (03:53 +0300)]
Upstream: fixed timeouts with gRPC, SSL and select (ticket #2229).

With SSL it is possible that an established connection is ready for
reading after the handshake.  Further, events might be already disabled
in case of level-triggered event methods.  If this happens and
ngx_http_upstream_send_request() blocks waiting for some data from
the upstream, such as flow control in case of gRPC, the connection
will time out due to no read events on the upstream connection.

Fix is to explicitly check the c->read->ready flag if sending request
blocks and post a read event if it is set.

Note that while it is possible to modify ngx_ssl_handshake() to keep
read events active, this won't completely resolve the issue, since
there can be data already received during the SSL handshake
(see 573bd30e46b4).

4 years agoMail: Auth-SSL-Protocol and Auth-SSL-Cipher headers (ticket #2134).
Rob Mueller [Fri, 13 Aug 2021 07:57:47 +0000 (03:57 -0400)]
Mail: Auth-SSL-Protocol and Auth-SSL-Cipher headers (ticket #2134).

This adds new Auth-SSL-Protocol and Auth-SSL-Cipher headers to
the mail proxy auth protocol when SSL is enabled.

This can be useful for detecting users using older clients that
negotiate old ciphers when you want to upgrade to newer
TLS versions of remove suppport for old and insecure ciphers.
You can use your auth backend to notify these users before the
upgrade that they either need to upgrade their client software
or contact your support team to work out an upgrade path.

4 years agoSSL: ciphers now set before loading certificates (ticket #2035).
Maxim Dounin [Mon, 16 Aug 2021 19:40:31 +0000 (22:40 +0300)]
SSL: ciphers now set before loading certificates (ticket #2035).

To load old/weak server or client certificates it might be needed to adjust
the security level, as introduced in OpenSSL 1.1.0.  This change ensures that
ciphers are set before loading the certificates, so security level changes
via the cipher string apply to certificate loading.

4 years agoDark mode support in welcome and 50x error pages.
Maxim Dounin [Mon, 16 Aug 2021 13:36:08 +0000 (16:36 +0300)]
Dark mode support in welcome and 50x error pages.

Prodded by Duncan Lock.

4 years agoWelcome and 50x error pages style.
Maxim Dounin [Mon, 16 Aug 2021 13:36:06 +0000 (16:36 +0300)]
Welcome and 50x error pages style.

Indentation of the CSS code removed to match style of the HTML code.

4 years agoSSL: removed use of the SSL_OP_MSIE_SSLV2_RSA_PADDING option.
Sergey Kandaurov [Tue, 10 Aug 2021 20:43:17 +0000 (23:43 +0300)]
SSL: removed use of the SSL_OP_MSIE_SSLV2_RSA_PADDING option.

It has no effect since OpenSSL 0.9.7h and 0.9.8a.

4 years agoSSL: removed export ciphers support.
Sergey Kandaurov [Tue, 10 Aug 2021 20:43:17 +0000 (23:43 +0300)]
SSL: removed export ciphers support.

Export ciphers are forbidden to negotiate in TLS 1.1 and later protocol modes.
They are disabled since OpenSSL 1.0.2g by default unless explicitly configured
with "enable-weak-ssl-ciphers", and completely removed in OpenSSL 1.1.0.

4 years agoSSL: use of the SSL_OP_IGNORE_UNEXPECTED_EOF option.
Sergey Kandaurov [Tue, 10 Aug 2021 20:43:17 +0000 (23:43 +0300)]
SSL: use of the SSL_OP_IGNORE_UNEXPECTED_EOF option.

A new behaviour was introduced in OpenSSL 1.1.1e, when a peer does not send
close_notify before closing the connection.  Previously, it was to return
SSL_ERROR_SYSCALL with errno 0, known since at least OpenSSL 0.9.7, and is
handled gracefully in nginx.  Now it returns SSL_ERROR_SSL with a distinct
reason SSL_R_UNEXPECTED_EOF_WHILE_READING ("unexpected eof while reading").
This leads to critical errors seen in nginx within various routines such as
SSL_do_handshake(), SSL_read(), SSL_shutdown().  The behaviour was restored
in OpenSSL 1.1.1f, but presents in OpenSSL 3.0 by default.

Use of the SSL_OP_IGNORE_UNEXPECTED_EOF option added in OpenSSL 3.0 allows
to set a compatible behaviour to return SSL_ERROR_ZERO_RETURN:
https://git.openssl.org/?p=openssl.git;a=commitdiff;h=09b90e0

See for additional details: https://github.com/openssl/openssl/issues/11381

4 years agoSSL: silenced warnings when building with OpenSSL 3.0.
Sergey Kandaurov [Tue, 10 Aug 2021 20:43:16 +0000 (23:43 +0300)]
SSL: silenced warnings when building with OpenSSL 3.0.

The OPENSSL_SUPPRESS_DEPRECATED macro is used to suppress deprecation warnings.
This covers Session Tickets keys, SSL Engine, DH low level API for DHE ciphers.

Unlike OPENSSL_API_COMPAT, it works well with OpenSSL built with no-deprecated.
In particular, it doesn't unhide various macros in OpenSSL includes, which are
meant to be hidden under OPENSSL_NO_DEPRECATED.

4 years agoSSL: ERR_peek_error_line_data() compatibility with OpenSSL 3.0.
Sergey Kandaurov [Tue, 10 Aug 2021 20:43:16 +0000 (23:43 +0300)]
SSL: ERR_peek_error_line_data() compatibility with OpenSSL 3.0.

ERR_peek_error_line_data() was deprecated in favour of ERR_peek_error_all().
Here we use the ERR_peek_error_data() helper to pass only used arguments.

4 years agoSSL: using SSL_CTX_set0_tmp_dh_pkey() with OpenSSL 3.0 in dhparam.
Sergey Kandaurov [Tue, 10 Aug 2021 20:43:16 +0000 (23:43 +0300)]
SSL: using SSL_CTX_set0_tmp_dh_pkey() with OpenSSL 3.0 in dhparam.

Using PEM_read_bio_DHparams() and SSL_CTX_set_tmp_dh() is deprecated
as part of deprecating the low level DH functions in favor of EVP_PKEY:
https://git.openssl.org/?p=openssl.git;a=commitdiff;h=163f6dc

4 years agoSSL: SSL_get_peer_certificate() is deprecated in OpenSSL 3.0.
Sergey Kandaurov [Tue, 10 Aug 2021 20:43:16 +0000 (23:43 +0300)]
SSL: SSL_get_peer_certificate() is deprecated in OpenSSL 3.0.

Switch to SSL_get1_peer_certificate() when building with OpenSSL 3.0
and OPENSSL_NO_DEPRECATED defined.

4 years agoSSL: RSA data type is deprecated in OpenSSL 3.0.
Sergey Kandaurov [Tue, 10 Aug 2021 20:42:59 +0000 (23:42 +0300)]
SSL: RSA data type is deprecated in OpenSSL 3.0.

The only consumer is a callback function for SSL_CTX_set_tmp_rsa_callback()
deprecated in OpenSSL 1.1.0.  Now the function is conditionally compiled too.

4 years agoDisabled HTTP/1.0 requests with Transfer-Encoding.
Sergey Kandaurov [Mon, 9 Aug 2021 15:12:12 +0000 (18:12 +0300)]
Disabled HTTP/1.0 requests with Transfer-Encoding.

The latest HTTP/1.1 draft describes Transfer-Encoding in HTTP/1.0 as having
potentially faulty message framing as that could have been forwarded without
handling of the chunked encoding, and forbids processing subsequest requests
over that connection: https://github.com/httpwg/http-core/issues/879.

While handling of such requests is permitted, the most secure approach seems
to reject them.

4 years agoSSL: SSL_CTX_set_tmp_dh() error handling.
Sergey Kandaurov [Wed, 4 Aug 2021 18:27:51 +0000 (21:27 +0300)]
SSL: SSL_CTX_set_tmp_dh() error handling.

For example, it can fail due to weak DH parameters.

4 years agoSSL: set events ready flags after handshake.
Maxim Dounin [Tue, 3 Aug 2021 17:50:30 +0000 (20:50 +0300)]
SSL: set events ready flags after handshake.

The c->read->ready and c->write->ready flags might be reset during
the handshake, and not set again if the handshake was finished on
the other event.  At the same time, some data might be read from
the socket during the handshake, so missing c->read->ready flag might
result in a connection hang, for example, when waiting for an SMTP
greeting (which was already received during the handshake).

Found by Sergey Kandaurov.

4 years agoVersion bump.
Maxim Dounin [Tue, 3 Aug 2021 17:50:08 +0000 (20:50 +0300)]
Version bump.

4 years agoHTTP/3: bulk parse functions.
Roman Arutyunyan [Thu, 8 Jul 2021 18:52:47 +0000 (21:52 +0300)]
HTTP/3: bulk parse functions.

Previously HTTP/3 streams were parsed by one character.  Now all parse functions
receive buffers.  This should optimize parsing time and CPU load.

4 years agoQUIC: Stateless Reset Token debug logging cleanup.
Sergey Kandaurov [Tue, 24 Aug 2021 11:41:31 +0000 (14:41 +0300)]
QUIC: Stateless Reset Token debug logging cleanup.

4 years agoQUIC: removed duplicate logging of Stateless Reset Token.
Sergey Kandaurov [Tue, 24 Aug 2021 11:40:33 +0000 (14:40 +0300)]
QUIC: removed duplicate logging of Stateless Reset Token.

4 years agoHTTP/3: fixed dead store assignment.
Sergey Kandaurov [Tue, 24 Aug 2021 10:03:48 +0000 (13:03 +0300)]
HTTP/3: fixed dead store assignment.

Found by Clang Static Analyzer.

4 years agoQUIC: fixed dead store assignment.
Sergey Kandaurov [Tue, 24 Aug 2021 10:03:46 +0000 (13:03 +0300)]
QUIC: fixed dead store assignment.

Found by Clang Static Analyzer.

4 years agoQUIC: fixed format specifiers in ngx_quic_bpf module.
Sergey Kandaurov [Tue, 17 Aug 2021 08:41:11 +0000 (11:41 +0300)]
QUIC: fixed format specifiers in ngx_quic_bpf module.

4 years agoHTTP/3: disabled control characters and space in header names.
Sergey Kandaurov [Tue, 10 Aug 2021 09:35:12 +0000 (12:35 +0300)]
HTTP/3: disabled control characters and space in header names.

This is a follow up to 41f4bd4c51f1.

4 years agoQUIC: better ordering in auto/modules.
Vladimir Homutov [Thu, 5 Aug 2021 08:13:29 +0000 (11:13 +0300)]
QUIC: better ordering in auto/modules.

4 years agoHTTP/3: got rid of HTTP/2 module dependency.
Vladimir Homutov [Thu, 5 Aug 2021 08:09:13 +0000 (11:09 +0300)]
HTTP/3: got rid of HTTP/2 module dependency.

The Huffman encoder/decoder now can be built separately from HTTP/2 module.

4 years agoHTTP/3: replaced macros with values.
Roman Arutyunyan [Wed, 4 Aug 2021 14:35:11 +0000 (17:35 +0300)]
HTTP/3: replaced macros with values.

4 years agoQUIC: asynchronous shutdown.
Roman Arutyunyan [Thu, 5 Aug 2021 06:20:32 +0000 (09:20 +0300)]
QUIC: asynchronous shutdown.

Previously, when cleaning up a QUIC stream in shutdown mode,
ngx_quic_shutdown_quic() was called, which could close the QUIC connection
right away.  This could be a problem if the connection was referenced up the
stack.  For example, this could happen in ngx_quic_init_streams(),
ngx_quic_close_streams(), ngx_quic_create_client_stream() etc.

With a typical HTTP/3 client the issue is unlikely because of HTTP/3 uni
streams which need a posted event to close.  In this case QUIC connection
cannot be closed right away.

Now QUIC connection read event is posted and it will shut down the connection
asynchronously.

4 years agoQUIC: client certificate validation with OCSP.
Sergey Kandaurov [Wed, 4 Aug 2021 12:49:18 +0000 (15:49 +0300)]
QUIC: client certificate validation with OCSP.

4 years agoHTTP/3: close connection on keepalive_requests * 2.
Roman Arutyunyan [Thu, 29 Jul 2021 13:01:37 +0000 (16:01 +0300)]
HTTP/3: close connection on keepalive_requests * 2.

After receiving GOAWAY, client is not supposed to create new streams.  However,
until client reads this frame, we allow it to create new streams, which are
gracefully rejected.  To prevent client from abusing this algorithm, a new
limit is introduced.  Upon reaching keepalive_requests * 2, server now closes
the entire QUIC connection claiming excessive load.

4 years agoQUIC: stream limits in "hq" mode.
Roman Arutyunyan [Mon, 2 Aug 2021 12:48:21 +0000 (15:48 +0300)]
QUIC: stream limits in "hq" mode.

The "hq" mode is HTTP/0.9-1.1 over QUIC.  The following limits are introduced:

- uni streams are not allowed
- keepalive_requests is enforced
- keepalive_time is enforced

In case of error, QUIC connection is finalized with 0x101 code.  This code
corresponds to HTTP/3 General Protocol Error.

4 years agoHTTP/3: http3_max_uni_streams directive.
Roman Arutyunyan [Thu, 29 Jul 2021 09:17:56 +0000 (12:17 +0300)]
HTTP/3: http3_max_uni_streams directive.

The directive limits the number of uni streams client is allowed to create.

4 years agoQUIC: limit in-flight bytes by congestion window.
Roman Arutyunyan [Thu, 29 Jul 2021 09:49:16 +0000 (12:49 +0300)]
QUIC: limit in-flight bytes by congestion window.

Previously, in-flight byte counter and congestion window were properly
maintained, but the limit was not properly implemented.

Now a new datagram is sent only if in-flight byte counter is less than window.
The limit is datagram-based, which means that a single datagram may lead to
exceeding the limit, but the next one will not be sent.

4 years agoQUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov [Wed, 28 Jul 2021 14:23:18 +0000 (17:23 +0300)]
QUIC: handle EAGAIN properly on UDP sockets.

Previously, the error was ignored leading to unnecessary retransmits.
Now, unsent frames are returned into output queue, state is reset, and
timer is started for the next send attempt.

4 years agoHTTP/3: require mandatory uni streams before additional ones.
Roman Arutyunyan [Thu, 29 Jul 2021 07:03:36 +0000 (10:03 +0300)]
HTTP/3: require mandatory uni streams before additional ones.

As per quic-http-34:

   Endpoints SHOULD create the HTTP control stream as well as the
   unidirectional streams required by mandatory extensions (such as the
   QPACK encoder and decoder streams) first, and then create additional
   streams as allowed by their peer.

Previously, client could create and destroy additional uni streams unlimited
number of times before creating mandatory streams.

4 years agoQUIC: eliminated stream type from ngx_quic_stream_frame_t.
Roman Arutyunyan [Wed, 28 Jul 2021 10:21:47 +0000 (13:21 +0300)]
QUIC: eliminated stream type from ngx_quic_stream_frame_t.

The information about the type is contained in off/len/fin bits.

Also, where possible, only the first stream type (0x08) is used for simplicity.

4 years agoQUIC: updated README with GSO details.
Vladimir Homutov [Fri, 23 Jul 2021 08:25:16 +0000 (11:25 +0300)]
QUIC: updated README with GSO details.

4 years agoHTTP/3: use request pool instead of connection pool.
Roman Arutyunyan [Fri, 16 Jul 2021 12:43:01 +0000 (15:43 +0300)]
HTTP/3: use request pool instead of connection pool.

In several parts of ngx_http_v3_header_filter() connection pool was used for
request-related data.

4 years agoHTTP/3: response trailers support.
Roman Arutyunyan [Tue, 13 Jul 2021 19:44:03 +0000 (22:44 +0300)]
HTTP/3: response trailers support.

4 years agoQUIC: avoid processing 1-RTT with incomplete handshake in OpenSSL.
Sergey Kandaurov [Thu, 22 Jul 2021 12:00:37 +0000 (15:00 +0300)]
QUIC: avoid processing 1-RTT with incomplete handshake in OpenSSL.

OpenSSL is known to provide read keys for an encryption level before the
level is active in TLS, following the old BoringSSL API.  In BoringSSL,
it was then fixed to defer releasing read keys until QUIC may use them.

4 years agoQUIC: the "quic_gso" directive.
Vladimir Homutov [Tue, 20 Jul 2021 09:37:12 +0000 (12:37 +0300)]
QUIC: the "quic_gso" directive.

The directive enables usage of UDP segmentation offloading by quic.
By default, gso is disabled since it is not always operational when
detected (depends on interface configuration).

4 years agoCore: fixed errno clobbering in ngx_sendmsg().
Vladimir Homutov [Tue, 20 Jul 2021 09:04:58 +0000 (12:04 +0300)]
Core: fixed errno clobbering in ngx_sendmsg().

This was broken by 2dfd313f22f2.

4 years agoMerged with the default branch.
Sergey Kandaurov [Thu, 15 Jul 2021 13:28:21 +0000 (16:28 +0300)]
Merged with the default branch.

4 years agoCore: added separate function for local source address cmsg.
Vladimir Homutov [Thu, 15 Jul 2021 11:22:54 +0000 (14:22 +0300)]
Core: added separate function for local source address cmsg.

4 years agoQUIC: added support for segmentation offloading.
Vladimir Homutov [Thu, 15 Jul 2021 11:22:00 +0000 (14:22 +0300)]
QUIC: added support for segmentation offloading.

To improve output performance, UDP segmentation offloading is used
if available.  If there is a significant amount of data in an output
queue and path is verified, QUIC packets are not sent one-by-one,
but instead are collected in a buffer, which is then passed to kernel
in a single sendmsg call, using UDP GSO.  Such method greatly decreases
number of system calls and thus system load.

4 years agoCore: made the ngx_sendmsg() function non-static.
Vladimir Homutov [Thu, 15 Jul 2021 11:21:39 +0000 (14:21 +0300)]
Core: made the ngx_sendmsg() function non-static.

Additionally, the ngx_init_srcaddr_cmsg() function is introduced which
initializes control message with connection local address.

The NGX_HAVE_ADDRINFO_CMSG macro is defined when at least one of methods
to deal with corresponding control message is available.

4 years agoCore: the ngx_event_udp.h header file.
Vladimir Homutov [Mon, 12 Jul 2021 13:40:57 +0000 (16:40 +0300)]
Core: the ngx_event_udp.h header file.

4 years agorelease-1.21.1 tag
Maxim Dounin [Tue, 6 Jul 2021 14:59:17 +0000 (17:59 +0300)]
release-1.21.1 tag

4 years agonginx-1.21.1-RELEASE release-1.21.1
Maxim Dounin [Tue, 6 Jul 2021 14:59:16 +0000 (17:59 +0300)]
nginx-1.21.1-RELEASE

5 years agoWin32: use only preallocated memory in send/recv chain functions.
Ruslan Ermilov [Mon, 5 Jul 2021 10:26:49 +0000 (13:26 +0300)]
Win32: use only preallocated memory in send/recv chain functions.

The ngx_wsasend_chain() and ngx_wsarecv_chain() functions were
modified to use only preallocated memory, and the number of
preallocated wsabufs was increased to 64.

5 years agoQUIC: fixed padding calculation.
Vladimir Homutov [Mon, 5 Jul 2021 10:17:10 +0000 (13:17 +0300)]
QUIC: fixed padding calculation.

Sometimes, QUIC packets need to be of certain (or minimal) size.  This is
achieved by adding PADDING frames.  It is possible, that adding padding will
affect header size, thus forcing us to recalculate padding size once more.

5 years agoUse only preallocated memory in ngx_readv_chain() (ticket #1408).
Ruslan Ermilov [Mon, 5 Jul 2021 10:09:23 +0000 (13:09 +0300)]
Use only preallocated memory in ngx_readv_chain() (ticket #1408).

In d1bde5c3c5d2, the number of preallocated iovec's for ngx_readv_chain()
was increased.  Still, in some setups, the function might allocate memory
for iovec's from a connection pool, which is only freed when closing the
connection.

The ngx_readv_chain() function was modified to use only preallocated
memory, similarly to the ngx_writev_chain() change in 8e903522c17a.

5 years agoHTTP/3: quic-qpack term updates.
Sergey Kandaurov [Thu, 1 Jul 2021 12:37:53 +0000 (15:37 +0300)]
HTTP/3: quic-qpack term updates.

Renamed header -> field per quic-qpack naming convention, in particular:
- Header Field -> Field Line
- Header Block -> (Encoded) Field Section
- Without Name Reference -> With Literal Name
- Header Acknowledgement -> Section Acknowledgment

5 years agoQUIC: consider max_ack_delay=16384 invalid.
Roman Arutyunyan [Wed, 30 Jun 2021 10:47:38 +0000 (13:47 +0300)]
QUIC: consider max_ack_delay=16384 invalid.

As per RFC 9000:

   Values of 2^14 or greater are invalid.

5 years agoDisabled control characters in the Host header.
Maxim Dounin [Mon, 28 Jun 2021 15:01:24 +0000 (18:01 +0300)]
Disabled control characters in the Host header.

Control characters (0x00-0x1f, 0x7f) and space are not expected to appear
in the Host header.  Requests with such characters in the Host header are
now unconditionally rejected.

5 years agoImproved logging of invalid headers.
Maxim Dounin [Mon, 28 Jun 2021 15:01:20 +0000 (18:01 +0300)]
Improved logging of invalid headers.

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.

5 years agoDisabled control characters and space in header names.
Maxim Dounin [Mon, 28 Jun 2021 15:01:18 +0000 (18:01 +0300)]
Disabled control characters and space in header names.

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).

5 years agoDisabled control characters in URIs.
Maxim Dounin [Mon, 28 Jun 2021 15:01:15 +0000 (18:01 +0300)]
Disabled control characters in URIs.

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.

5 years agoDisabled spaces in URIs (ticket #196).
Maxim Dounin [Mon, 28 Jun 2021 15:01:13 +0000 (18:01 +0300)]
Disabled spaces in URIs (ticket #196).

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.

5 years agoCore: escaping of chars not allowed in URIs per RFC 3986.
Maxim Dounin [Mon, 28 Jun 2021 15:01:11 +0000 (18:01 +0300)]
Core: escaping of chars not allowed in URIs per RFC 3986.

Per RFC 3986 only the following characters are allowed in URIs unescaped:

unreserved    = ALPHA / DIGIT / "-" / "." / "_" / "~"
gen-delims    = ":" / "/" / "?" / "#" / "[" / "]" / "@"
sub-delims    = "!" / "$" / "&" / "'" / "(" / ")"
              / "*" / "+" / "," / ";" / "="

And "%" can appear as a part of escaping itself.  The following
characters are not allowed and need to be escaped: %00-%1F, %7F-%FF,
" ", """, "<", ">", "\", "^", "`", "{", "|", "}".

Not escaping ">" is known to cause problems at least with MS Exchange (see
http://nginx.org/pipermail/nginx-ru/2010-January/031261.html) and in
Tomcat (ticket #2191).

The patch adds escaping of the following chars in all URI parts: """, "<",
">", "\", "^", "`", "{", "|", "}".  Note that comments are mostly preserved
to outline important characters being escaped.