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

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

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

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

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

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

5 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

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

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

5 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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

5 years agoFixed SSL logging with lingering close.
Maxim Dounin [Tue, 1 Jun 2021 14:37:51 +0000 (17:37 +0300)]
Fixed SSL logging with lingering close.

Recent fixes to SSL shutdown with lingering close (554c6ae25ffc, 1.19.5)
broke logging of SSL variables.  To make sure logging of SSL variables
works properly, avoid freeing c->ssl when doing an SSL shutdown before
lingering close.

Reported by Reinis Rozitis
(http://mailman.nginx.org/pipermail/nginx/2021-May/060670.html).

5 years agoSSL: ngx_ssl_shutdown() rework.
Maxim Dounin [Tue, 1 Jun 2021 14:37:49 +0000 (17:37 +0300)]
SSL: ngx_ssl_shutdown() rework.

Instead of calling SSL_free() with each return point, introduced a single
place where cleanup happens.  As a positive side effect, this fixes two
potential memory leaks on ngx_handle_read_event() and ngx_handle_write_event()
errors where there were no SSL_free() calls (though unlikely practical,
as errors there are only expected to happen due to bugs or kernel issues).

5 years agoHTTP/3: undo 5a92523e50d3 after parser refactoring (e1eb7f4ca9f1).
Sergey Kandaurov [Tue, 1 Jun 2021 09:02:08 +0000 (12:02 +0300)]
HTTP/3: undo 5a92523e50d3 after parser refactoring (e1eb7f4ca9f1).

This is no longer needed after HTTP/3 request processing has moved
into its own function ngx_http_v3_process_header().

5 years agoHTTP/3: fixed parsing encoder insertions with empty header value.
Sergey Kandaurov [Tue, 1 Jun 2021 08:41:38 +0000 (11:41 +0300)]
HTTP/3: fixed parsing encoder insertions with empty header value.

When starting processing a new encoder instruction, the header state is not
memzero'ed because generally it's burdensome.  If the header value is empty,
this resulted in inserting a stale value left from the previous instruction.

Based on a patch by Zhiyong Sun.

5 years agoHTTP/3: removed $http3 that served its purpose.
Sergey Kandaurov [Mon, 31 May 2021 08:54:47 +0000 (11:54 +0300)]
HTTP/3: removed $http3 that served its purpose.

To specify final protocol version by hand:

    add_header Alt-Svc h3=":443";

5 years agoContrib: vim syntax, update core and 3rd party module directives.
Gena Makhomed [Sun, 30 May 2021 09:26:00 +0000 (12:26 +0300)]
Contrib: vim syntax, update core and 3rd party module directives.

5 years agoCore: disabled SO_REUSEADDR on UDP sockets while testing config.
Maxim Dounin [Mon, 31 May 2021 13:36:51 +0000 (16:36 +0300)]
Core: disabled SO_REUSEADDR on UDP sockets while testing config.

On Linux, SO_REUSEADDR allows completely duplicate UDP sockets, so using
SO_REUSEADDR when testing configuration results in packets being dropped
if there is an existing traffic on the sockets being tested (ticket #2187).
While dropped packets are expected with UDP, it is better to avoid this
when possible.

With this change, SO_REUSEADDR is no longer set on datagram sockets when
testing configuration.

5 years agoCore: disabled cloning sockets when testing config (ticket #2188).
Maxim Dounin [Mon, 31 May 2021 13:36:37 +0000 (16:36 +0300)]
Core: disabled cloning sockets when testing config (ticket #2188).

Since we anyway do not set SO_REUSEPORT when testing configuration
(see ecb5cd305b06), trying to open additional sockets does not make much
sense, as all these additional sockets are expected to result in EADDRINUSE
errors from bind().  On the other hand, there are reports that trying
to open these sockets takes significant time under load: total configuration
testing time greater than 15s was observed in ticket #2188, compared to less
than 1s without load.

With this change, no additional sockets are opened during testing
configuration.

5 years agoVersion bump.
Maxim Dounin [Mon, 31 May 2021 13:36:12 +0000 (16:36 +0300)]
Version bump.

5 years agoREADME: updated after QUIC RFC publication, nginx 1.21 rebase.
Sergey Kandaurov [Fri, 28 May 2021 10:45:09 +0000 (13:45 +0300)]
README: updated after QUIC RFC publication, nginx 1.21 rebase.

5 years agoMerged with the default branch.
Sergey Kandaurov [Fri, 28 May 2021 10:33:08 +0000 (13:33 +0300)]
Merged with the default branch.

5 years agoHTTP/3: fixed Insert With Name Reference index processing.
Sergey Kandaurov [Thu, 27 May 2021 10:29:00 +0000 (13:29 +0300)]
HTTP/3: fixed Insert With Name Reference index processing.

Based on a patch by Zhiyong Sun.

5 years agoQUIC: call stream read handler on new data arrival.
Roman Arutyunyan [Wed, 26 May 2021 10:07:06 +0000 (13:07 +0300)]
QUIC: call stream read handler on new data arrival.

This was broken in b3f6ad181df4.

5 years agoQUIC: make sure stream data size is lower than final size.
Roman Arutyunyan [Tue, 25 May 2021 13:41:59 +0000 (16:41 +0300)]
QUIC: make sure stream data size is lower than final size.

As per quic-transport 34, FINAL_SIZE_ERROR is generated if an endpoint received
a STREAM frame or a RESET_STREAM frame containing a final size that was lower
than the size of stream data that was already received.

5 years agorelease-1.21.0 tag
Maxim Dounin [Tue, 25 May 2021 12:28:56 +0000 (15:28 +0300)]
release-1.21.0 tag

5 years agonginx-1.21.0-RELEASE release-1.21.0
Maxim Dounin [Tue, 25 May 2021 12:28:55 +0000 (15:28 +0300)]
nginx-1.21.0-RELEASE

5 years agoResolver: explicit check for compression pointers in question.
Maxim Dounin [Tue, 25 May 2021 12:17:50 +0000 (15:17 +0300)]
Resolver: explicit check for compression pointers in question.

Since nginx always uses exactly one entry in the question section of
a DNS query, and never uses compression pointers in this entry, parsing
of a DNS response in ngx_resolver_process_response() does not expect
compression pointers to appear in the question section of the DNS
response.  Indeed, compression pointers in the first name of a DNS response
hardly make sense, do not seem to be allowed by RFC 1035 (which says
"a pointer to a prior occurance of the same name", note "prior"), and
were never observed in practice.

Added an explicit check to ngx_resolver_process_response()'s parsing
of the question section to properly report an error if compression pointers
nevertheless appear in the question section.

5 years agoResolver: simplified ngx_resolver_copy().
Maxim Dounin [Tue, 25 May 2021 12:17:45 +0000 (15:17 +0300)]
Resolver: simplified ngx_resolver_copy().

Instead of checking on each label if we need to place a dot or not,
now it always adds a dot after a label, and reduces the resulting
length afterwards.