]> git.kaiwu.me - nginx.git/log
nginx.git
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 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 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.

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

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

5 years agoCore: fixed comment about escaping in arguments.
Maxim Dounin [Mon, 28 Jun 2021 15:01:09 +0000 (18:01 +0300)]
Core: fixed comment about escaping in arguments.

After 4954530db2af, the ";" character is escaped by
ngx_escape_uri(NGX_ESCAPE_ARGS).

5 years agoDisabled requests with both Content-Length and Transfer-Encoding.
Maxim Dounin [Mon, 28 Jun 2021 15:01:06 +0000 (18:01 +0300)]
Disabled requests with both Content-Length and Transfer-Encoding.

HTTP clients are not allowed to generate such requests since Transfer-Encoding
introduction in RFC 2068, and they are not expected to appear in practice
except in attempts to perform a request smuggling attack.  While handling of
such requests is strictly defined, the most secure approach seems to reject
them.

5 years agoAdded CONNECT method rejection.
Maxim Dounin [Mon, 28 Jun 2021 15:01:04 +0000 (18:01 +0300)]
Added CONNECT method rejection.

No valid CONNECT requests are expected to appear within nginx, since it
is not a forward proxy.  Further, request line parsing will reject
proper CONNECT requests anyway, since we don't allow authority-form of
request-target.  On the other hand, RFC 7230 specifies separate message
length rules for CONNECT which we don't support, so make sure to always
reject CONNECTs to avoid potential abuse.

5 years agoMoved TRACE method rejection to a better place.
Maxim Dounin [Mon, 28 Jun 2021 15:01:00 +0000 (18:01 +0300)]
Moved TRACE method rejection to a better place.

Previously, TRACE requests were rejected before parsing Transfer-Encoding.
This is not important since keepalive is not enabled at this point anyway,
though rejecting such requests after properly parsing other headers is
less likely to cause issues in case of further code changes.

5 years agoQUIC: fixed client certificates verification in stream.
Vladimir Homutov [Wed, 23 Jun 2021 10:22:00 +0000 (13:22 +0300)]
QUIC: fixed client certificates verification in stream.

The stream session requires 'ssl' flag to be set in order to perform
certificate verification.

5 years agoREADME: updated path after moving QUIC sources.
Sergey Kandaurov [Fri, 25 Jun 2021 09:41:58 +0000 (12:41 +0300)]
README: updated path after moving QUIC sources.

5 years agoQUIC: fixed double memzero of new frames in ngx_quic_alloc_frame().
Sergey Kandaurov [Mon, 21 Jun 2021 09:47:46 +0000 (12:47 +0300)]
QUIC: fixed double memzero of new frames in ngx_quic_alloc_frame().

5 years agoCore: added the ngx_rbtree_data() macro.
Vladimir Homutov [Mon, 21 Jun 2021 06:42:43 +0000 (09:42 +0300)]
Core: added the ngx_rbtree_data() macro.

5 years agoFixed format strings for ngx_win32_version.
Maxim Dounin [Fri, 18 Jun 2021 01:00:21 +0000 (04:00 +0300)]
Fixed format strings for ngx_win32_version.

5 years agoQUIC: compact initial secrets table.
Sergey Kandaurov [Thu, 17 Jun 2021 09:35:38 +0000 (12:35 +0300)]
QUIC: compact initial secrets table.

5 years agogRPC: RST_STREAM(NO_ERROR) handling micro-optimization.
Sergey Kandaurov [Thu, 17 Jun 2021 08:44:06 +0000 (11:44 +0300)]
gRPC: RST_STREAM(NO_ERROR) handling micro-optimization.

After 2096b21fcd10, a single RST_STREAM(NO_ERROR) may not result in an error.
This change removes several unnecessary ctx->type checks for such a case.

5 years agogRPC: handling GOAWAY with a higher last stream identifier.
Sergey Kandaurov [Thu, 17 Jun 2021 08:43:55 +0000 (11:43 +0300)]
gRPC: handling GOAWAY with a higher last stream identifier.

Previously, once received from upstream, it couldn't limit
opening additional streams in a cached keepalive connection.

5 years agoQUIC: using compile time block/iv length for tokens.
Sergey Kandaurov [Wed, 16 Jun 2021 15:03:33 +0000 (18:03 +0300)]
QUIC: using compile time block/iv length for tokens.

Reference values can be found in RFC 3602, 2.1, 2.4.

5 years agoQUIC: optimized initial secrets key length computation.
Sergey Kandaurov [Wed, 16 Jun 2021 14:55:57 +0000 (17:55 +0300)]
QUIC: optimized initial secrets key length computation.

AES-128 key length is known in compile time.

5 years agoQUIC: consistent use of 12-byte buffers in nonce computation.
Sergey Kandaurov [Wed, 16 Jun 2021 14:54:21 +0000 (17:54 +0300)]
QUIC: consistent use of 12-byte buffers in nonce computation.

All supported cipher suites produce 96-bit IV (RFC 5116, 5.1, RFC 8439, 2.3).
This eliminates a few magic numbers and run-time overhead.

5 years agoQUIC: consistent use of 5-byte buffers for header protection.
Sergey Kandaurov [Wed, 16 Jun 2021 14:53:18 +0000 (17:53 +0300)]
QUIC: consistent use of 5-byte buffers for header protection.

The output buffer is now also of 5 bytes.  Header protection uses
stream ciphers, which don't produce extra output nor PKCS padding.

5 years agoQUIC: updated specification references.
Sergey Kandaurov [Wed, 16 Jun 2021 08:55:12 +0000 (11:55 +0300)]
QUIC: updated specification references.

This includes updating citations and further clarification.

5 years agoHTTP/3: client GOAWAY support.
Roman Arutyunyan [Fri, 11 Jun 2021 10:24:24 +0000 (13:24 +0300)]
HTTP/3: client GOAWAY support.

5 years agoHTTP/3: generate more H3_FRAME_UNEXPECTED.
Roman Arutyunyan [Fri, 11 Jun 2021 09:11:08 +0000 (12:11 +0300)]
HTTP/3: generate more H3_FRAME_UNEXPECTED.

As per quic-http-34, these are the cases when this error should be generated:

   If an endpoint receives a second SETTINGS frame
   on the control stream, the endpoint MUST respond with a connection
   error of type H3_FRAME_UNEXPECTED

   SETTINGS frames MUST NOT be sent on any stream other than the control
   stream.  If an endpoint receives a SETTINGS frame on a different
   stream, the endpoint MUST respond with a connection error of type
   H3_FRAME_UNEXPECTED.

   A client MUST NOT send a PUSH_PROMISE frame.  A server MUST treat the
   receipt of a PUSH_PROMISE frame as a connection error of type
   H3_FRAME_UNEXPECTED; see Section 8.

   The MAX_PUSH_ID frame is always sent on the control stream.  Receipt
   of a MAX_PUSH_ID frame on any other stream MUST be treated as a
   connection error of type H3_FRAME_UNEXPECTED.

   Receipt of an invalid sequence of frames MUST be treated as a
   connection error of type H3_FRAME_UNEXPECTED; see Section 8.  In
   particular, a DATA frame before any HEADERS frame, or a HEADERS or
   DATA frame after the trailing HEADERS frame, is considered invalid.

   A CANCEL_PUSH frame is sent on the control stream.  Receiving a
   CANCEL_PUSH frame on a stream other than the control stream MUST be
   treated as a connection error of type H3_FRAME_UNEXPECTED.

   The GOAWAY frame is always sent on the control stream.

5 years agoHTTP/3: reordered H3_MISSING_SETTINGS and H3_FRAME_UNEXPECTED.
Roman Arutyunyan [Fri, 11 Jun 2021 07:56:51 +0000 (10:56 +0300)]
HTTP/3: reordered H3_MISSING_SETTINGS and H3_FRAME_UNEXPECTED.

The quic-http-34 is ambiguous as to what error should be generated for the
first frame in control stream:

   Each side MUST initiate a single control stream at the beginning of
   the connection and send its SETTINGS frame as the first frame on this
   stream.  If the first frame of the control stream is any other frame
   type, this MUST be treated as a connection error of type
   H3_MISSING_SETTINGS.

   If a DATA frame is received on a control stream, the recipient MUST
   respond with a connection error of type H3_FRAME_UNEXPECTED.

   If a HEADERS frame is received on a control stream, the recipient MUST
   respond with a connection error of type H3_FRAME_UNEXPECTED.

Previously, H3_FRAME_UNEXPECTED had priority, but now H3_MISSING_SETTINGS has.
The arguments in the spec sound more compelling for H3_MISSING_SETTINGS.

5 years agoQUIC: improved errors readability.
Vladimir Homutov [Thu, 10 Jun 2021 20:17:51 +0000 (23:17 +0300)]
QUIC: improved errors readability.

5 years agoQUIC: persistent congestion calculation.
Vladimir Homutov [Wed, 9 Jun 2021 12:11:43 +0000 (15:11 +0300)]
QUIC: persistent congestion calculation.

According to RFC 9002 (quic-recovery) 7.6.

5 years agoQUIC: stream flow control refactored.
Roman Arutyunyan [Mon, 7 Jun 2021 07:12:46 +0000 (10:12 +0300)]
QUIC: stream flow control refactored.

- Function ngx_quic_control_flow() is introduced.  This functions does
both MAX_DATA and MAX_STREAM_DATA flow controls.  The function is called
from STREAM and RESET_STREAM frame handlers.  Previously, flow control
was only accounted for STREAM.  Also, MAX_DATA flow control was not accounted
at all.

- Function ngx_quic_update_flow() is introduced.  This function advances flow
control windows and sends MAX_DATA/MAX_STREAM_DATA.  The function is called
from RESET_STREAM frame handler, stream cleanup handler and stream recv()
handler.