summaryrefslogtreecommitdiffhomepage
AgeCommit message (Collapse)AuthorFilesLines
2021-08-31nginx-1.21.2-RELEASErelease-1.21.2Maxim Dounin1-0/+107
2021-08-31Updated OpenSSL used for win32 builds.Maxim Dounin1-1/+1
2021-08-31HTTP/2: avoid memcpy() with NULL source and zero length.Maxim Dounin1-1/+3
Prodded by Clang Static Analyzer.
2021-08-30Give GCC atomics precedence over deprecated Darwin atomic(3).Sergey Kandaurov1-33/+33
This allows to build nginx on macOS with -Wdeprecated-declarations.
2021-08-29Request body: reading body buffering in filters.Maxim Dounin3-26/+182
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.)
2021-08-29Request body: introduced rb->last_saved flag.Maxim Dounin2-15/+54
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.
2021-08-29Request body: added alert to catch duplicate body saving.Maxim Dounin1-0/+6
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.
2021-08-29Request body: missing comments about initialization.Maxim Dounin1-0/+2
2021-08-29HTTP/2: improved handling of preread unbuffered requests.Maxim Dounin1-1/+1
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.
2021-08-29HTTP/2: improved handling of END_STREAM in a separate DATA frame.Maxim Dounin1-0/+3
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.
2021-08-29HTTP/2: reworked body reading to better match HTTP/1.x code.Maxim Dounin1-62/+96
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.
2021-08-29HTTP/2: improved body reading logging.Maxim Dounin1-0/+6
2021-08-20Upstream: fixed timeouts with gRPC, SSL and select (ticket #2229).Maxim Dounin1-0/+4
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).
2021-08-13Mail: Auth-SSL-Protocol and Auth-SSL-Cipher headers (ticket #2134).Rob Mueller1-2/+39
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.
2021-08-16SSL: ciphers now set before loading certificates (ticket #2035).Maxim Dounin7-43/+43
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.
2021-08-16Dark mode support in welcome and 50x error pages.Maxim Dounin2-0/+2
Prodded by Duncan Lock.
2021-08-16Welcome and 50x error pages style.Maxim Dounin2-10/+4
Indentation of the CSS code removed to match style of the HTML code.
2021-08-10SSL: removed use of the SSL_OP_MSIE_SSLV2_RSA_PADDING option.Sergey Kandaurov1-5/+0
It has no effect since OpenSSL 0.9.7h and 0.9.8a.
2021-08-10SSL: removed export ciphers support.Sergey Kandaurov2-36/+0
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.
2021-08-10SSL: use of the SSL_OP_IGNORE_UNEXPECTED_EOF option.Sergey Kandaurov1-0/+4
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
2021-08-10SSL: silenced warnings when building with OpenSSL 3.0.Sergey Kandaurov1-0/+2
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.
2021-08-10SSL: ERR_peek_error_line_data() compatibility with OpenSSL 3.0.Sergey Kandaurov2-1/+6
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.
2021-08-10SSL: using SSL_CTX_set0_tmp_dh_pkey() with OpenSSL 3.0 in dhparam.Sergey Kandaurov1-1/+31
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
2021-08-10SSL: SSL_get_peer_certificate() is deprecated in OpenSSL 3.0.Sergey Kandaurov1-0/+5
Switch to SSL_get1_peer_certificate() when building with OpenSSL 3.0 and OPENSSL_NO_DEPRECATED defined.
2021-08-10SSL: RSA data type is deprecated in OpenSSL 3.0.Sergey Kandaurov2-1/+7
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.
2021-08-09Disabled HTTP/1.0 requests with Transfer-Encoding.Sergey Kandaurov1-0/+8
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.
2021-08-04SSL: SSL_CTX_set_tmp_dh() error handling.Sergey Kandaurov1-1/+7
For example, it can fail due to weak DH parameters.
2021-08-03SSL: set events ready flags after handshake.Maxim Dounin1-0/+6
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.
2021-08-03Version bump.Maxim Dounin1-2/+2
2021-07-06release-1.21.1 tagMaxim Dounin1-0/+1
2021-07-06nginx-1.21.1-RELEASErelease-1.21.1Maxim Dounin1-0/+119
2021-07-05Win32: use only preallocated memory in send/recv chain functions.Ruslan Ermilov2-12/+20
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.
2021-07-05Use only preallocated memory in ngx_readv_chain() (ticket #1408).Ruslan Ermilov1-1/+1
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.
2021-06-28Disabled control characters in the Host header.Maxim Dounin1-3/+4
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.
2021-06-28Improved logging of invalid headers.Maxim Dounin6-13/+28
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.
2021-06-28Disabled control characters and space in header names.Maxim Dounin3-4/+4
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).
2021-06-28Disabled control characters in URIs.Maxim Dounin1-14/+28
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.
2021-06-28Disabled spaces in URIs (ticket #196).Maxim Dounin4-70/+11
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.
2021-06-28Core: escaping of chars not allowed in URIs per RFC 3986.Maxim Dounin1-16/+29
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.
2021-06-28Core: fixed comment about escaping in arguments.Maxim Dounin1-1/+1
After 4954530db2af, the ";" character is escaped by ngx_escape_uri(NGX_ESCAPE_ARGS).
2021-06-28Disabled requests with both Content-Length and Transfer-Encoding.Maxim Dounin1-2/+9
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.
2021-06-28Added CONNECT method rejection.Maxim Dounin4-17/+31
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.
2021-06-28Moved TRACE method rejection to a better place.Maxim Dounin1-7/+7
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.
2021-06-21Core: added the ngx_rbtree_data() macro.Vladimir Homutov3-5/+6
2021-06-18Fixed format strings for ngx_win32_version.Maxim Dounin1-3/+3
2021-06-17gRPC: RST_STREAM(NO_ERROR) handling micro-optimization.Sergey Kandaurov1-0/+4
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.
2021-06-17gRPC: handling GOAWAY with a higher last stream identifier.Sergey Kandaurov1-0/+9
Previously, once received from upstream, it couldn't limit opening additional streams in a cached keepalive connection.
2021-06-01Fixed SSL logging with lingering close.Maxim Dounin3-0/+9
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).
2021-06-01SSL: ngx_ssl_shutdown() rework.Maxim Dounin1-22/+21
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).
2021-05-30Contrib: vim syntax, update core and 3rd party module directives.Gena Makhomed1-2/+13