Commit Graph

8076 Commits

Author SHA1 Message Date
Maxim Dounin 9fcbfb1255 Updated OpenSSL used for win32 builds. 2022-07-19 17:03:30 +03:00
Maxim Dounin b585c3b74e Events: fixed EPOLLRDHUP with FIONREAD (ticket #2367).
When reading exactly rev->available bytes, rev->available might become 0
after FIONREAD usage introduction in efd71d49bde0.  On the next call of
ngx_readv_chain() on systems with EPOLLRDHUP this resulted in return without
any actions, that is, with rev->ready set, and this in turn resulted in no
timers set in event pipe, leading to socket leaks.

Fix is to reset rev->ready in ngx_readv_chain() when returning due to
rev->available being 0 with EPOLLRDHUP, much like it is already done in
ngx_unix_recv().  This ensures that if rev->available will become 0, on
systems with EPOLLRDHUP support appropriate EPOLLRDHUP-specific handling
will happen on the next ngx_readv_chain() call.

While here, also synced ngx_readv_chain() to match ngx_unix_recv() and
reset rev->ready when returning due to rev->available being 0 with kqueue.
This is mostly cosmetic change, as rev->ready is anyway reset when
rev->available is set to 0.
2022-07-15 15:19:32 +03:00
Maxim Dounin ce67cac0ba Range filter: clearing of pre-existing Content-Range headers.
Some servers might emit Content-Range header on 200 responses, and this
does not seem to contradict RFC 9110: as per RFC 9110, the Content-Range
header has no meaning for status codes other than 206 and 416.  Previously
this resulted in duplicate Content-Range headers in nginx responses handled
by the range filter.  Fix is to clear pre-existing headers.
2022-07-15 07:01:44 +03:00
Sergey Kandaurov ec2ecdd62b Resolver: fixed memory leak for the "ipv4=off" case.
This change partially reverts 2a77754cd9fe to properly free rn->query.

Found by Coverity (CID 1507244).
2022-07-14 21:26:54 +04:00
Ruslan Ermilov bcf1402445 The "ipv4=" parameter of the "resolver" directive.
When set to "off", only IPv6 addresses will be resolved, and no
A queries are ever sent (ticket #2196).
2022-07-12 21:44:02 +04:00
Maxim Dounin f94e5b01a7 SSL: logging levels of various errors added in OpenSSL 1.1.1.
Starting with OpenSSL 1.1.1, various additional errors can be reported
by OpenSSL in case of client-related issues, most notably during TLSv1.3
handshakes.  In particular, SSL_R_BAD_KEY_SHARE ("bad key share"),
SSL_R_BAD_EXTENSION ("bad extension"), SSL_R_BAD_CIPHER ("bad cipher"),
SSL_R_BAD_ECPOINT ("bad ecpoint").  These are now logged at the "info"
level.
2022-07-12 15:55:22 +03:00
Maxim Dounin 86fa8882c8 Upstream: optimized use of SSL contexts (ticket #1234).
To ensure optimal use of memory, SSL contexts for proxying are now
inherited from previous levels as long as relevant proxy_ssl_* directives
are not redefined.

Further, when no proxy_ssl_* directives are redefined in a server block,
we now preserve plcf->upstream.ssl in the "http" section configuration
to inherit it to all servers.

Similar changes made in uwsgi, grpc, and stream proxy.
2022-06-29 02:47:45 +03:00
Maxim Dounin ef4919f875 Version bump. 2022-06-29 02:47:38 +03:00
Maxim Dounin e5accc5b36 release-1.23.0 tag 2022-06-21 17:25:37 +03:00
Maxim Dounin 266ad70b19 nginx-1.23.0-RELEASE 2022-06-21 17:25:36 +03:00
Maxim Dounin bfe9ab90ba Updated OpenSSL used for win32 builds. 2022-06-21 17:09:34 +03:00
Maxim Dounin cd4f57ef8d Misc: win32 sources now preserved in release tarballs.
This makes it possible to build nginx under Windows from release tarballs
instead of using source code repository.
2022-06-20 19:30:50 +03:00
Gena Makhomed 4a4d67a03d Contrib: vim syntax, update core and 3rd party module directives.
List of 3rd party modules github repositories are obtained from
https://github.com/freebsd/freebsd-ports/blob/main/www/nginx-devel/Makefile.extmod
2022-06-18 15:54:40 +03:00
Sergey Kandaurov 9912eb8939 Perl: removed unused variables, forgotten in ef6a3a99a81a. 2022-06-14 10:39:58 +04:00
Aleksei Bavshin b29e4652bb Resolver: make TCP write timer event cancelable.
Similar to 70e65bf8dfd7, the change is made to ensure that the ability to
cancel resolver tasks is fully controlled by the caller.  As mentioned in the
referenced commit, it is safe to make this timer cancelable because resolve
tasks can have their own timeouts that are not cancelable.

The scenario where this may become a problem is a periodic background resolve
task (not tied to a specific request or a client connection), which receives a
response with short TTL, large enough to warrant fallback to a TCP query.
With each event loop wakeup, we either have a previously set write timer
instance or schedule a new one.  The non-cancelable write timer can delay or
block graceful shutdown of a worker even if the ngx_resolver_ctx_t->cancelable
flag is set by the API user, and there are no other tasks or connections.

We use the resolver API in this way to maintain the list of upstream server
addresses specified with the 'resolve' parameter, and there could be third-party
modules implementing similar logic.
2022-06-01 20:17:23 -07:00
Vladimir Homutov d3d5a9b8a4 QUIC: avoided pool usage in token calculation. 2022-05-31 11:05:22 +04:00
Vladimir Homutov fe6cac822c QUIC: removed ngx_quic_keys_new().
The ngx_quic_keys_t structure is now exposed.
2022-07-27 17:31:16 +04:00
Vladimir Homutov da18efff87 QUIC: avoided pool usage in ngx_quic_protection.c. 2022-07-27 17:16:40 +04:00
Vladimir Homutov 17c9506b58 QUIC: fixed-length buffers for secrets. 2022-07-27 17:15:33 +04:00
Sergey Kandaurov 03b740ba06 Merged with the default branch. 2022-07-26 19:54:11 +04:00
Sergey Kandaurov f2bc2e05d0 Merged with the default branch. 2022-06-22 18:34:58 +04:00
Sergey Kandaurov 658e350aae HTTP/3: updated SETTINGS_MAX_FIELD_SECTION_SIZE name. 2022-06-08 16:19:01 +04:00
Sergey Kandaurov 62e6a35da7 README: updated after HTTP/3 RFC publication, minor refinements. 2022-06-08 15:30:08 +04:00
Roman Arutyunyan b752b1ec26 HTTP/3: require that field section base index is not negative.
RFC 9204 explicitly requires that.
2022-05-26 16:17:56 +04:00
Aleksei Bavshin 663445ba7a Stream: don't flush empty buffers created for read errors.
When we generate the last_buf buffer for an UDP upstream recv error, it does
not contain any data from the wire. ngx_stream_write_filter attempts to forward
it anyways, which is incorrect (e.g., UDP upstream ECONNREFUSED will be
translated to an empty packet).

This happens because we mark the buffer as both 'flush' and 'last_buf', and
ngx_stream_write_filter has special handling for flush with certain types of
connections (see d127837c714f, 32b0ba4855a6).  The flags are meant to be
mutually exclusive, so the fix is to ensure that flush and last_buf are not set
at the same time.

Reproduction:

stream {
    upstream unreachable {
        server     127.0.0.1:8880;
    }
    server {
        listen     127.0.0.1:8998 udp;
        proxy_pass unreachable;
    }
}

1 0.000000000    127.0.0.1 → 127.0.0.1    UDP 47 45588 → 8998 Len=5
2 0.000166300    127.0.0.1 → 127.0.0.1    UDP 47 51149 → 8880 Len=5
3 0.000172600    127.0.0.1 → 127.0.0.1    ICMP 75 Destination unreachable (Port
unreachable)
4 0.000202400    127.0.0.1 → 127.0.0.1    UDP 42 8998 → 45588 Len=0

Fixes d127837c714f.
2022-05-23 11:29:44 -07:00
Maxim Dounin 8d3f47c131 Mp4: fixed potential overflow in ngx_http_mp4_crop_stts_data().
Both "count" and "duration" variables are 32-bit, so their product might
potentially overflow.  It is used to reduce 64-bit start_time variable,
and with very large start_time this can result in incorrect seeking.

Found by Coverity (CID 1499904).
2022-06-07 21:58:52 +03:00
Sergey Kandaurov 82ff3c2d8c Upstream: handling of certificates specified as an empty string.
Now, if the directive is given an empty string, such configuration cancels
loading of certificates, in particular, if they would be otherwise inherited
from the previous level.  This restores previous behaviour, before variables
support in certificates was introduced (3ab8e1e2f0f7).
2022-06-07 20:08:57 +04:00
Maxim Dounin bb4d3b091d Upstream: fixed X-Accel-Expires/Cache-Control/Expires handling.
Previously, if caching was disabled due to Expires in the past, nginx
failed to cache the response even if it was cacheable as per subsequently
parsed Cache-Control header (ticket #964).

Similarly, if caching was disabled due to Expires in the past,
"Cache-Control: no-cache" or "Cache-Control: max-age=0", caching was not
used if it was cacheable as per subsequently parsed X-Accel-Expires header.

Fix is to avoid disabling caching immediately after parsing Expires in
the past or Cache-Control, but rather set flags which are later checked by
ngx_http_upstream_process_headers() (and cleared by "Cache-Control: max-age"
and X-Accel-Expires).

Additionally, now X-Accel-Expires does not prevent parsing of cache control
extensions, notably stale-while-revalidate and stale-if-error.  This
ensures that order of the X-Accel-Expires and Cache-Control headers is not
important.

Prodded by Vadim Fedorenko and Yugo Horie.
2022-06-07 00:07:12 +03:00
Maxim Dounin e571a75ba4 Upstream: fixed build without http cache (broken by cd73509f21e2). 2022-05-31 00:14:11 +03:00
Maxim Dounin 7ec70432d4 Headers filter: improved memory allocation error handling. 2022-05-30 21:25:57 +03:00
Maxim Dounin c43e768c74 Multiple WWW-Authenticate headers with "satisfy any;".
If a module adds multiple WWW-Authenticate headers (ticket #485) to the
response, linked in r->headers_out.www_authenticate, all headers are now
cleared if another module later allows access.

This change is a nop for standard modules, since the only access module which
can add multiple WWW-Authenticate headers is the auth request module, and
it is checked after other standard access modules.  Though this might
affect some third party access modules.

Note that if a 3rd party module adds a single WWW-Authenticate header
and not yet modified to set the header's next pointer to NULL, attempt to
clear such a header with this change will result in a segmentation fault.
2022-05-30 21:25:56 +03:00
Maxim Dounin ac4d19865a Auth request: multiple WWW-Authenticate headers (ticket #485).
When using auth_request with an upstream server which returns 401
(Unauthorized), multiple WWW-Authenticate headers from the upstream server
response are now properly copied to the response.
2022-05-30 21:25:54 +03:00
Maxim Dounin 3d731d9748 Upstream: multiple WWW-Authenticate headers (ticket #485).
When using proxy_intercept_errors and an error page for error 401
(Unauthorized), multiple WWW-Authenticate headers from the upstream server
response are now properly copied to the response.
2022-05-30 21:25:53 +03:00
Maxim Dounin 12bd0b0884 Upstream: handling of multiple Vary headers (ticket #1423).
Previously, only the last header value was used when caching.
2022-05-30 21:25:51 +03:00
Maxim Dounin 027b46b7ea Upstream: duplicate headers ignored or properly linked.
Most of the known duplicate upstream response headers are now ignored
with a warning.

If syntax permits multiple headers, these are now properly linked to
the lists, notably Vary and WWW-Authenticate.  This makes it possible
to further handle such lists where it makes sense.
2022-05-30 21:25:49 +03:00
Maxim Dounin 47e9ce390d Upstream: header handlers can now return parsing errors.
With this change, duplicate Content-Length and Transfer-Encoding headers
are now rejected.  Further, responses with invalid Content-Length or
Transfer-Encoding headers are now rejected, as well as responses with both
Content-Length and Transfer-Encoding.
2022-05-30 21:25:48 +03:00
Maxim Dounin 4e5ce1fa2e Upstream: all known headers in u->headers_in are linked lists now. 2022-05-30 21:25:46 +03:00
Maxim Dounin dd06c6b586 All known output headers can be linked lists now.
The h->next pointer properly provided as NULL in all cases where known
output headers are added.

Note that there are 3rd party modules which might not do this, and it
might be risky to rely on this for arbitrary headers.
2022-05-30 21:25:45 +03:00
Maxim Dounin 95ec5e3d95 Upstream: simplified Accept-Ranges handling.
The u->headers_in.accept_ranges field is not used anywhere and hence removed.
2022-05-30 21:25:43 +03:00
Maxim Dounin f77cf83837 Upstream: simplified Content-Encoding handling.
Since introduction of offset handling in ngx_http_upstream_copy_header_line()
in revision 573:58475592100c, the ngx_http_upstream_copy_content_encoding()
function is no longer needed, as its behaviour is exactly equivalent to
ngx_http_upstream_copy_header_line() with appropriate offset.  As such,
the ngx_http_upstream_copy_content_encoding() function was removed.

Further, the u->headers_in.content_encoding field is not used anywhere,
so it was removed as well.

Further, Content-Encoding handling no longer depends on NGX_HTTP_GZIP,
as it can be used even without any gzip handling compiled in (for example,
in the charset filter).
2022-05-30 21:25:42 +03:00
Maxim Dounin e1778b75f3 Upstream: style. 2022-05-30 21:25:40 +03:00
Maxim Dounin bf8acaa78a Perl: combining unknown headers during $r->header_in() lookup. 2022-05-30 21:25:38 +03:00
Maxim Dounin 7de2b91556 Perl: all known input headers are handled identically.
As all known input headers are now linked lists, these are now handled
identically.  In particular, this makes it possible to access properly
combined values of headers not specifically handled previously, such
as "Via" or "Connection".
2022-05-30 21:25:36 +03:00
Maxim Dounin 0c2a0ef934 All non-unique input headers are now linked lists.
The ngx_http_process_multi_header_lines() function is removed, as it is
exactly equivalent to ngx_http_process_header_line().  Similarly,
ngx_http_variable_header() is used instead of ngx_http_variable_headers().
2022-05-30 21:25:35 +03:00
Maxim Dounin 29a1e8e317 Reworked multi headers to use linked lists.
Multi headers are now using linked lists instead of arrays.  Notably,
the following fields were changed: r->headers_in.cookies (renamed
to r->headers_in.cookie), r->headers_in.x_forwarded_for,
r->headers_out.cache_control, r->headers_out.link, u->headers_in.cache_control
u->headers_in.cookies (renamed to u->headers_in.set_cookie).

The r->headers_in.cookies and u->headers_in.cookies fields were renamed
to r->headers_in.cookie and u->headers_in.set_cookie to match header names.

The ngx_http_parse_multi_header_lines() and ngx_http_parse_set_cookie_lines()
functions were changed accordingly.

With this change, multi headers are now essentially equivalent to normal
headers, and following changes will further make them equivalent.
2022-05-30 21:25:33 +03:00
Maxim Dounin ad8f9f7411 Combining unknown headers during variables lookup (ticket #1316).
Previously, $http_*, $sent_http_*, $sent_trailer_*, $upstream_http_*,
and $upstream_trailer_* variables returned only the first header (with
a few specially handled exceptions: $http_cookie, $http_x_forwarded_for,
$sent_http_cache_control, $sent_http_link).

With this change, all headers are returned, combined together.  For
example, $http_foo variable will be "a, b" if there are "Foo: a" and
"Foo: b" headers in the request.

Note that $upstream_http_set_cookie will also return all "Set-Cookie"
headers (ticket #1843), though this might not be what one want, since
the "Set-Cookie" header does not follow the list syntax (see RFC 7230,
section 3.2.2).
2022-05-30 21:25:32 +03:00
Maxim Dounin f6087d2731 Uwsgi: combining headers with identical names (ticket #1724).
The uwsgi specification states that "The uwsgi block vars represent a
dictionary/hash".  This implies that no duplicate headers are expected.

Further, provided headers are expected to follow CGI specification,
which also requires to combine headers (RFC 3875, section "4.1.18.
Protocol-Specific Meta-Variables"): "If multiple header fields with
the same field-name are received then the server MUST rewrite them
as a single value having the same semantics".
2022-05-30 21:25:30 +03:00
Maxim Dounin d86b7da869 SCGI: combining headers with identical names (ticket #1724).
SCGI specification explicitly forbids headers with duplicate names
(section "3. Request Format"): "Duplicate names are not allowed in
the headers".

Further, provided headers are expected to follow CGI specification,
which also requires to combine headers (RFC 3875, section "4.1.18.
Protocol-Specific Meta-Variables"): "If multiple header fields with
the same field-name are received then the server MUST rewrite them
as a single value having the same semantics".
2022-05-30 21:25:28 +03:00
Maxim Dounin 189568930e FastCGI: combining headers with identical names (ticket #1724).
FastCGI responder is expected to receive CGI/1.1 environment variables
in the parameters (see section "6.2 Responder" of the FastCGI specification).
Obviously enough, there cannot be multiple environment variables with
the same name.

Further, CGI specification (RFC 3875, section "4.1.18. Protocol-Specific
Meta-Variables") explicitly requires to combine headers: "If multiple
header fields with the same field-name are received then the server MUST
rewrite them as a single value having the same semantics".
2022-05-30 21:25:27 +03:00
Maxim Dounin 021a3fbc4e Perl: fixed $r->header_in("Connection").
Previously, the r->header_in->connection pointer was never set despite
being present in ngx_http_headers_in, resulting in incorrect value returned
by $r->header_in("Connection") in embedded perl.
2022-05-30 21:25:25 +03:00