summaryrefslogtreecommitdiffhomepage
path: root/src (follow)
AgeCommit message (Collapse)AuthorFilesLines
2020-06-29SSL: fixed unexpected certificate requests (ticket #2008).Maxim Dounin1-1/+2
Using SSL_CTX_set_verify(SSL_VERIFY_PEER) implies that OpenSSL will send a certificate request during an SSL handshake, leading to unexpected certificate requests from browsers as long as there are any client certificates installed. Given that ngx_ssl_trusted_certificate() is called unconditionally by the ngx_http_ssl_module, this affected all HTTPS servers. Broken by 699f6e55bbb4 (not released yet). Fix is to set verify callback in the ngx_ssl_trusted_certificate() function without changing the verify mode.
2020-06-15Fixed potential leak of temp pool.Eran Kornblau1-2/+2
In case ngx_hash_add_key() fails, need to goto failed instead of returning, so that temp_pool will be destoryed.
2020-06-22Cache: introduced min_free cache clearing.Maxim Dounin6-3/+89
Clearing cache based on free space left on a file system is expected to allow better disk utilization in some cases, notably when disk space might be also used for something other than nginx cache (including nginx own temporary files) and while loading cache (when cache size might be inaccurate for a while, effectively disabling max_size cache clearing). Based on a patch by Adam Bambuch.
2020-06-22Too large st_blocks values are now ignored (ticket #157).Maxim Dounin1-1/+4
With XFS, using "allocsize=64m" mount option results in large preallocation being reported in the st_blocks as returned by fstat() till the file is closed. This in turn results in incorrect cache size calculations and wrong clearing based on max_size. To avoid too aggressive cache clearing on such volumes, st_blocks values which result in sizes larger than st_size and eight blocks (an arbitrary limit) are no longer trusted, and we use st_size instead. The ngx_de_fs_size() counterpart is intentionally not modified, as it is used on closed files and hence not affected by this problem.
2020-06-22Large block sizes on Linux are now ignored (ticket #1168).Maxim Dounin1-0/+12
NFS on Linux is known to report wsize as a block size (in both f_bsize and f_frsize, both in statfs() and statvfs()). On the other hand, typical file system block sizes on Linux (ext2/ext3/ext4, XFS) are limited to pagesize. (With FAT, block sizes can be at least up to 512k in extreme cases, but this doesn't really matter, see below.) To avoid too aggressive cache clearing on NFS volumes on Linux, block sizes larger than pagesize are now ignored. Note that it is safe to ignore large block sizes. Since 3899:e7cd13b7f759 (1.0.1) cache size is calculated based on fstat() st_blocks, and rounding to file system block size is preserved mostly for Windows. Note well that on other OSes valid block sizes seen are at least up to 65536. In particular, UFS on FreeBSD is known to work well with block and fragment sizes set to 65536.
2020-06-15OCSP: fixed use-after-free on error.Roman Arutyunyan1-21/+20
When validating second and further certificates, ssl callback could be called twice to report the error. After the first call client connection is terminated and its memory is released. Prior to the second call and in it released connection memory is accessed. Errors triggering this behavior: - failure to create the request - failure to start resolving OCSP responder name - failure to start connecting to the OCSP responder The fix is to rearrange the code to eliminate the second call.
2020-06-15Correctly flush request body to uwsgi with SSL.Quantum1-0/+1
The flush flag was not set when forwarding the request body to the uwsgi server. When using uwsgi_pass suwsgi://..., this causes the uwsgi server to wait indefinitely for the request body and eventually time out due to SSL buffering. This is essentially the same change as 4009:3183165283cc, which was made to ngx_http_proxy_module.c. This will fix the uwsgi bug https://github.com/unbit/uwsgi/issues/1490.
2020-06-08Stream: fixed processing of zero length UDP packets (ticket #1982).Vladimir Homutov3-2/+11
2020-06-03SSL: added verify callback to ngx_ssl_trusted_certificate().Maxim Dounin1-0/+2
This ensures that certificate verification is properly logged to debug log during upstream server certificate verification. This should help with debugging various certificate issues.
2020-06-01Fixed SIGQUIT not removing listening UNIX sockets (closes #753).Ruslan Ermilov1-12/+2
Listening UNIX sockets were not removed on graceful shutdown, preventing the next runs. The fix is to replace the custom socket closing code in ngx_master_process_cycle() by the ngx_close_listening_sockets() call.
2020-06-01Fixed removing of listening UNIX sockets when "changing binary".Ruslan Ermilov3-1/+4
When changing binary, sending a SIGTERM to the new binary's master process should not remove inherited UNIX sockets unless the old binary's master process has exited.
2020-05-26Version bump.Maxim Dounin1-2/+2
2020-05-25HTTP/2: invalid connection preface logging (ticket #1981).Maxim Dounin1-6/+4
Previously, invalid connection preface errors were only logged at debug level, providing no visible feedback, in particular, when a plain text HTTP/2 listening socket is erroneously used for HTTP/1.x connections. Now these are explicitly logged at the info level, much like other client-related errors.
2020-05-23Fixed format specifiers.Sergey Kandaurov1-2/+2
2020-05-22OCSP: certificate status cache.Roman Arutyunyan4-5/+401
When enabled, certificate status is stored in cache and is used to validate the certificate in future requests. New directive ssl_ocsp_cache is added to configure the cache.
2020-05-22SSL: client certificate validation with OCSP (ticket #1534).Roman Arutyunyan6-20/+681
OCSP validation for client certificates is enabled by the "ssl_ocsp" directive. OCSP responder can be optionally specified by "ssl_ocsp_responder". When session is reused, peer chain is not available for validation. If the verified chain contains certificates from the peer chain not available at the server, validation will fail.
2020-05-22OCSP stapling: iterate over all responder addresses.Roman Arutyunyan1-13/+54
Previously only the first responder address was used per each stapling update. Now, in case of a network or parsing error, next address is used. This also fixes the issue with unsupported responder address families (ticket #1330).
2020-05-17OCSP stapling: keep extra chain in the staple object.Roman Arutyunyan1-29/+18
2020-05-06OCSP stapling: moved response verification to a separate function.Roman Arutyunyan1-136/+154
2020-05-13Upstream: jump out of loop after matching the status code.Jinhua Tan1-0/+2
2020-05-08Variables: fixed buffer over-read when evaluating "$arg_".Sergey Kandaurov1-1/+1
2020-04-23gRPC: WINDOW_UPDATE after END_STREAM handling (ticket #1797).Ruslan Ermilov1-1/+2
As per https://tools.ietf.org/html/rfc7540#section-6.9, WINDOW_UPDATE received after a frame with the END_STREAM flag should be handled and not treated as an error.
2020-04-23gRPC: RST_STREAM(NO_ERROR) handling (ticket #1792).Ruslan Ermilov1-5/+19
As per https://tools.ietf.org/html/rfc7540#section-8.1, : A server can send a complete response prior to the client : sending an entire request if the response does not depend on : any portion of the request that has not been sent and : received. When this is true, a server MAY request that the : client abort transmission of a request without error by : sending a RST_STREAM with an error code of NO_ERROR after : sending a complete response (i.e., a frame with the : END_STREAM flag). Clients MUST NOT discard responses as a : result of receiving such a RST_STREAM, though clients can : always discard responses at their discretion for other : reasons. Previously, RST_STREAM(NO_ERROR) received from upstream after a frame with the END_STREAM flag was incorrectly treated as an error. Now, a single RST_STREAM(NO_ERROR) is properly handled. This fixes problems observed with modern grpc-c [1], as well as with the Go gRPC module. [1] https://github.com/grpc/grpc/pull/1661
2020-04-23Version bump.Ruslan Ermilov1-2/+2
2020-04-08The new auth_delay directive for delaying unauthorized requests.Ruslan Ermilov2-1/+82
The request processing is delayed by a timer. Since nginx updates internal time once at the start of each event loop iteration, this normally ensures constant time delay, adding a mitigation from time-based attacks. A notable exception to this is the case when there are no additional events before the timer expires. To ensure constant-time processing in this case as well, we trigger an additional event loop iteration by posting a dummy event for the next event loop iteration.
2020-03-13Auth basic: explicitly zero out password buffer.Ruslan Ermilov1-19/+18
2020-03-16Version bump.Ruslan Ermilov1-2/+2
2020-02-28Simplified subrequest finalization.Roman Arutyunyan1-23/+11
Now it looks similar to what it was before background subrequests were introduced in 9552758a786e.
2020-03-02Fixed premature background subrequest finalization.Dmitry Volyntsev1-9/+9
When "aio" or "aio threads" is used while processing the response body of an in-memory background subrequest, the subrequest could be finalized with an aio operation still in progress. Upon aio completion either parent request is woken or the old r->write_event_handler is called again. The latter may result in request errors. In either case post_subrequest handler is never called with the full response body, which is typically expected when using in-memory subrequests. Currently in nginx background subrequests are created by the upstream module and the mirror module. The issue does not manifest itself with these subrequests because they are header-only. But it can manifest itself with third-party modules which create in-memory background subrequests.
2020-02-28Added default overwrite in error_page 494.Maxim Dounin1-0/+1
We used to have default error_page overwrite for 495, 496, and 497, so a configuration like error_page 495 /error; will result in error 400, much like without any error_page configured. The 494 status code was introduced later (in 3848:de59ad6bf557, nginx 0.9.4), and relevant changes to ngx_http_core_error_page() were missed, resulting in inconsistent behaviour of "error_page 494" - with error_page configured it results in 494 being returned instead of 400. Reported by Frank Liu, http://mailman.nginx.org/pipermail/nginx/2020-February/058957.html.
2020-02-26Mp4: fixed possible chunk offset overflow.Roman Arutyunyan1-11/+64
In "co64" atom chunk start offset is a 64-bit unsigned integer. When trimming the "mdat" atom, chunk offsets are casted to off_t values which are typically 64-bit signed integers. A specially crafted mp4 file with huge chunk offsets may lead to off_t overflow and result in negative trim boundaries. The consequences of the overflow are: - Incorrect Content-Length header value in the response. - Negative left boundary of the response file buffer holding the trimmed "mdat". This leads to pread()/sendfile() errors followed by closing the client connection. On rare systems where off_t is a 32-bit integer, this scenario is also feasible with the "stco" atom. The fix is to add checks which make sure data chunks referenced by each track are within the mp4 file boundaries. Additionally a few more checks are added to ensure mp4 file consistency and log errors.
2020-02-27Disabled connection reuse while in SSL handshake.Sergey Kandaurov1-2/+2
During SSL handshake, the connection could be reused in the OCSP stapling callback, if configured, which subsequently leads to a segmentation fault.
2020-02-20Disabled duplicate "Host" headers (ticket #1724).Maxim Dounin1-2/+10
Duplicate "Host" headers were allowed in nginx 0.7.0 (revision b9de93d804ea) as a workaround for some broken Motorola phones which used to generate requests with two "Host" headers[1]. It is believed that this workaround is no longer relevant. [1] http://mailman.nginx.org/pipermail/nginx-ru/2008-May/017845.html
2020-02-20Removed "Transfer-Encoding: identity" support.Maxim Dounin1-4/+1
The "identity" transfer coding has been removed in RFC 7230. It is believed that it is not used in real life, and at the same time it provides a potential attack vector.
2020-02-20Disabled multiple Transfer-Encoding headers.Maxim Dounin1-1/+1
We anyway do not support more than one transfer encoding, so accepting requests with multiple Transfer-Encoding headers doesn't make sense. Further, we do not handle multiple headers, and ignore anything but the first header. Reported by Filippo Valsorda.
2020-02-11Made ngx_http_get_forwarded_addr_internal() non-recursive.Vladimir Homutov1-27/+25
2020-02-05HTTP/2: fixed socket leak with an incomplete HEADERS frame.Sergey Kandaurov1-2/+7
A connection could get stuck without timers if a client has partially sent the HEADERS frame such that it was split on the individual header boundary. In this case, it cannot be processed without the rest of the HEADERS frame. The fix is to call ngx_http_v2_state_headers_save() in this case. Normally, it would be called from the ngx_http_v2_state_header_block() handler on the next iteration, when there is not enough data to continue processing. This isn't the case if recv_buffer became empty and there's no more data to read.
2020-02-05Version bump.Sergey Kandaurov1-2/+2
2020-01-17gRPC: variables support in the "grpc_pass" directive.Vladimir Homutov1-38/+190
2020-01-14HTTP/2: removed ngx_debug_point() call.Daniil Bondarev1-4/+0
     With the recent change to prevent frames flood in d4448892a294, nginx will finalize the connection with NGX_HTTP_V2_INTERNAL_ERROR whenever flood is detected, causing nginx aborting or stopping if the debug_points directive is used in nginx config.
2019-12-27SSL: reworked posted next events again.Maxim Dounin4-14/+16
Previous change 1ce3f01a4355 incorrectly introduced processing of the ngx_posted_next_events queue at the end of operation, effectively making posted next events a nop, since at the end of an event loop iteration the queue is always empty. Correct approach is to move events to the ngx_posted_events queue at an iteration start, as it was done previously. Further, in some cases the c->read event might be already in the ngx_posted_events queue, and calling ngx_post_event() with the ngx_posted_next_events queue won't do anything. To make sure the event will be correctly placed into the ngx_posted_next_events queue we now check if it is already posted.
2019-12-27Version bump.Maxim Dounin1-2/+2
2019-12-24SSL: reworked posted next events.Maxim Dounin5-34/+28
Introduced in 9d2ad2fb4423 available bytes handling in SSL relied on connection read handler being overwritten to set the ready flag and the amount of available bytes. This approach is, however, does not work properly when connection read handler is changed, for example, when switching to a next pipelined request, and can result in unexpected connection timeouts, see here: http://mailman.nginx.org/pipermail/nginx-devel/2019-December/012825.html Fix is to introduce ngx_event_process_posted_next() instead, which will set ready and available regardless of how event handler is set.
2019-12-23HTTP/2: introduced separate handler to retry stream close.Maxim Dounin1-2/+19
When ngx_http_v2_close_stream_handler() is used to retry stream close after queued frames are sent, client timeouts on the stream can be logged multiple times and/or in addition to already happened errors. To resolve this, separate ngx_http_v2_retry_close_stream_handler() was introduced, which does not try to log timeouts.
2019-12-23HTTP/2: fixed socket leak with queued frames (ticket #1689).Maxim Dounin1-1/+2
If a stream is closed with queued frames, it is possible that no further write events will occur on the stream, leading to the socket leak. To fix this, the stream's fake connection read handler is set to ngx_http_v2_close_stream_handler(), to make sure that finalizing the connection with ngx_http_v2_finalize_connection() will be able to close the stream regardless of the current number of queued frames. Additionally, the stream's fake connection fc->error flag is explicitly set, so ngx_http_v2_handle_stream() will post a write event when queued frames are finally sent even if stream flow control window is exhausted.
2019-12-23Dav: added checks for chunked to body presence conditions.Maxim Dounin1-3/+5
These checks were missed when chunked support was introduced. And also added an explicit error message to ngx_http_dav_copy_move_handler() (it was missed for some reason, in contrast to DELETE and MKCOL handlers).
2019-12-23Discard request body when redirecting to a URL via error_page.Ruslan Ermilov1-0/+6
Reported by Bert JW Regeer and Francisco Oca Gonzalez.
2019-12-16Rewrite: disallow empty replacements.Ruslan Ermilov1-0/+5
While empty replacements were caught at run-time, parsing code of the "rewrite" directive expects that a minimum length of the "replacement" argument is 1.
2019-12-16Tolerate '\0' in URI when mapping URI to path.Ruslan Ermilov1-1/+2
If a rewritten URI has the null character, only a part of URI was copied to a memory buffer allocated for path. In some setups this could be exploited to expose uninitialized memory via the Location header.
2019-12-16Rewrite: fixed segfault with rewritten URI and "alias".Ruslan Ermilov1-1/+8
The "alias" directive cannot be used in the same location where URI was rewritten. This has been detected in the "rewrite ... break" case, but not when the standalone "break" directive was used. This change also fixes proxy_pass with URI component in a similar case: location /aaa/ { rewrite ^ /xxx/yyy; break; proxy_pass http://localhost:8080/bbb/; } Previously, the "/bbb/yyy" would be sent to a backend instead of "/xxx/yyy". And if location's prefix was longer than the rewritten URI, a segmentation fault might occur.