Commit Graph

8330 Commits

Author SHA1 Message Date
Sergey Kandaurov
5d5d9adccf SSL: avoid using mismatched certificate/key cached pairs.
This can happen with certificates and certificate keys specified
with variables due to partial cache update in various scenarios:
- cache expiration with only one element of pair evicted
- on-disk update with non-cacheable encrypted keys
- non-atomic on-disk update

The fix is to retry with fresh data on X509_R_KEY_VALUES_MISMATCH.
2025-01-17 04:37:46 +04:00
Sergey Kandaurov
454ad0ef33 Upstream: caching certificates and certificate keys with variables.
Caching is enabled with proxy_ssl_certificate_cache and friends.

Co-authored-by: Aleksei Bavshin <a.bavshin@nginx.com>
2025-01-17 04:37:46 +04:00
Sergey Kandaurov
4b96ad14f3 SSL: cache revalidation of file based dynamic certificates.
Revalidation is based on file modification time and uniq file index,
and happens after the cache object validity time is expired.
2025-01-17 04:37:46 +04:00
Sergey Kandaurov
0e756d67aa SSL: caching certificates and certificate keys with variables.
A new directive "ssl_certificate_cache max=N [valid=time] [inactive=time]"
enables caching of SSL certificate chain and secret key objects specified
by "ssl_certificate" and "ssl_certificate_key" directives with variables.

Co-authored-by: Aleksei Bavshin <a.bavshin@nginx.com>
2025-01-17 04:37:46 +04:00
Sergey Kandaurov
7677d5646a SSL: encrypted certificate keys are exempt from object cache.
SSL object cache, as previously introduced in 1.27.2, did not take
into account encrypted certificate keys that might be unexpectedly
fetched from the cache regardless of the matching passphrase.  To
avoid this, caching of encrypted certificate keys is now disabled
based on the passphrase callback invocation.

A notable exception is encrypted certificate keys configured without
ssl_password_file.  They are loaded once resulting in the passphrase
prompt on startup and reused in other contexts as applicable.
2025-01-17 04:37:46 +04:00
Sergey Kandaurov
8311e14ae6 SSL: object cache inheritance from the old configuration cycle.
Memory based objects are always inherited, engine based objects are
never inherited to adhere the volatile nature of engines, file based
objects are inherited subject to modification time and file index.

The previous behaviour to bypass cache from the old configuration cycle
is preserved with a new directive "ssl_object_cache_inheritable off;".
2025-01-17 04:37:46 +04:00
Daniel Vasquez Lopez
47f862ffad Slice filter: log the expected range in case of range error. 2025-01-16 21:09:59 +04:00
Sergey Kandaurov
57d54fd922 Gzip: compatibility with recent zlib-ng 2.2.x versions.
It now uses 5/4 times more memory for the pending buffer.

Further, a single allocation is now used, which takes additional 56 bytes
for deflate_allocs in 64-bit mode aligned to 16, to store sub-allocation
pointers, and the total allocation size now padded up to 128 bytes, which
takes theoretically 200 additional bytes in total.  This fits though into
"4 * (64 + sizeof(void*))" additional space for ZALLOC used in zlib-ng
2.1.x versions.  The comment was updated to reflect this.
2025-01-09 17:19:24 +04:00
Roman Arutyunyan
febe6e728f Year 2025. 2025-01-09 17:08:02 +04:00
Roman Arutyunyan
e3a9b6ad08 QUIC: fixed accessing a released stream.
While trying to close a stream in ngx_quic_close_streams() by calling its
read event handler, the next stream saved prior to that could be destroyed
recursively.  This caused a segfault while trying to access the next stream.

The way the next stream could be destroyed in HTTP/3 is the following.
A request stream read event handler ngx_http_request_handler() could
end up calling ngx_http_v3_send_cancel_stream() to report a cancelled
request stream in the decoder stream.  If sending stream cancellation
decoder instruction fails for any reason, and the decoder stream is the
next in order after the request stream, the issue is triggered.

The fix is to postpone calling read event handlers for all streams being
closed to avoid closing a released stream.
2024-12-27 16:14:14 +04:00
Roman Arutyunyan
a52ba8ba0e QUIC: ignore version negotiation packets.
Previously, such packets were treated as long header packets with unknown
version 0, and a version negotiation packet was sent in response.  This
could be used to set up an infinite traffic reflect loop with another nginx
instance.

Now version negotiation packets are ignored.  As per RFC 9000, Section 6.1:

  An endpoint MUST NOT send a Version Negotiation packet in response to
  receiving a Version Negotiation packet.
2024-12-26 18:58:05 +04:00
Jordan Zebor
c73fb273ac Updated security policy to clarify experimental features.
The original security policy language did not capture the scope
as intended for experimental features and availability.
2024-12-23 20:36:15 +04:00
nandsky
930caed3bf QUIC: fixed client request timeout in 0-RTT scenarios.
Since 0-RTT and 1-RTT data exist in the same packet number space,
ngx_quic_discard_ctx incorrectly discards 1-RTT packets when
0-RTT keys are discarded.

The issue was introduced by 58b92177e7.
2024-12-10 17:17:20 +04:00
Roman Arutyunyan
e28ef42b97 Version bump. 2024-11-27 20:07:29 +04:00
Sergey Kandaurov
e7bd255745 nginx-1.27.3-RELEASE 2024-11-26 19:55:00 +04:00
Sergey Kandaurov
ce88b17123 Mail: handling of LOGIN IMAP command untagged response.
In particular, an untagged CAPABILITY response as described in the
interim RFC 3501 internet drafts was seen in various IMAP servers.
Previously resulted in a broken connection, now an untagged response
is proxied to client.
2024-11-26 19:07:17 +04:00
Roman Arutyunyan
b2a67d2614 Realip: allowed square brackets with portless IPv6 address.
When client address is received, IPv6 address could be specified without
square brackets and without port, as well as both with the brackets and
port.  The change allows IPv6 in square brackets and no port, which was
previously considered an error.  This format conforms to RFC 3986.

The change also affects proxy_bind and friends.
2024-11-26 18:27:07 +04:00
Sergey Kandaurov
3f755b5a9e QUIC: got rid of memory copy when initializing constant values. 2024-11-26 17:41:21 +04:00
Sergey Kandaurov
9a025219f6 QUIC: constified nonce parameter of crypto functions.
This follows OpenSSL and BoringSSL API, and gives a hint to compiler
that this parameter may not be modified.
2024-11-26 17:41:21 +04:00
Sergey Kandaurov
a448dd52ee Upstream: disallow empty path in proxy_store and friends.
Renaming a temporary file to an empty path ("") returns NGX_ENOPATH
with a subsequent ngx_create_full_path() to create the full path.
This function skips initial bytes as part of path separator lookup,
which causes out of bounds access on short strings.

The fix is to avoid renaming a temporary file to an obviously invalid
path, as well as explicitly forbid such syntax for literal values.

Although Coverity reports about potential type underflow, it is not
actually possible because the terminating '\0' is always included.

Notably, the run-time check is sufficient enough for Win32 as well.
Other short invalid values result either in NGX_ENOENT or NGX_EEXIST
and "MoveFile() .. failed" critical log messages, which involves a
separate error handling.

Prodded by Coverity (CID 1605485).
2024-11-25 17:37:11 +04:00
Roman Arutyunyan
0864cca4d7 QUIC: prevented BIO leak in case of error. 2024-11-25 16:22:40 +04:00
Sergey Kandaurov
476d6526b2 SSL: a new macro to set default protocol versions.
This simplifies merging protocol values after ea15896 and ebd18ec.

Further, as outlined in ebd18ec18, for libraries preceeding TLSv1.2+
support, only meaningful versions TLSv1 and TLSv1.1 are set by default.

While here, fixed indentation.
2024-11-22 13:47:22 +04:00
Roman Arutyunyan
569948aa12 Mp4: prevent chunk index underflow.
When cropping stsc atom, it's assumed that chunk index is never 0.
Based on this assumption, start_chunk and end_chunk are calculated
by subtracting 1 from it.  If chunk index is zero, start_chunk or
end_chunk may underflow, which will later trigger
"start/end time is out mp4 stco chunks" error.  The change adds an
explicit check for zero chunk index to avoid underflow and report
a proper error.

Zero chunk index is explicitly banned in ISO/IEC 14496-12, 8.7.4
Sample To Chunk Box.  It's also implicitly banned in QuickTime File
Format specification.  Description of chunk offset table references
"Chunk 1" as the first table element.
2024-11-21 16:08:48 +04:00
Roman Arutyunyan
d1a02451c3 Mp4: unordered stsc chunks error for the final chunk.
Currently an error is triggered if any of the chunk runs in stsc are
unordered.  This however does not include the final chunk run, which
ends with trak->chunks + 1.  The previous chunk index can be larger
leading to a 32-bit overflow.  This could allow to skip the validity
check "if (start_sample > n)".  This could later lead to a large
trak->start_chunk/trak->end_chunk, which would be caught later in
ngx_http_mp4_update_stco_atom() or ngx_http_mp4_update_co64_atom().

While there are no implications of the validity check being avoided,
the change still adds a check to ensure the final chunk run is ordered,
to produce a meaningful error and avoid a potential integer overflow.
2024-11-21 16:08:48 +04:00
Roman Arutyunyan
6ec099a378 Mp4: fixed handling an empty run of chunks in stsc atom.
A specially crafted mp4 file with an empty run of chunks in the stsc atom
and a large value for samples per chunk for that run, combined with a
specially crafted request, allowed to store that large value in prev_samples
and later in trak->end_chunk_samples while in ngx_http_mp4_crop_stsc_data().
Later in ngx_http_mp4_update_stsz_atom() this could result in buffer
overread while calculating trak->end_chunk_samples_size.

Now the value of samples per chunk specified for an empty run is ignored.
2024-11-21 16:08:48 +04:00
Nathan Mentze
cb1857407b Fixed missing double quote. 2024-11-20 15:30:05 +04:00
Sergey Kandaurov
0ebc3242d9 SSL: error message default in object caching API.
This change initializes the "err" variable, used to produce a meaningful
diagnostics on error path, to a good safe value.
2024-11-19 21:37:03 +04:00
Andy Pan
7cd60cd475 On DragonFly BSD 5.8+, TCP_KEEPIDLE and TCP_KEEPINTVL are in secs. 2024-11-19 00:30:47 +04:00
Dan Callahan
36ca44f26f Fixed link to contributing guidelines.
Absolute paths in links end up being rooted at github.com.
The contributing guidelines link is broken unless we use the full URL.
Also, remove superfluous "monospace formatting" for the link.
2024-11-12 07:30:08 -08:00
Sergey Kandaurov
d10bf73eba Uwsgi: added create_loc_conf comments. 2024-11-12 17:21:22 +04:00
Sergey Kandaurov
1ac6a18585 SCGI: added create_loc_conf comments. 2024-11-12 17:21:22 +04:00
Sergey Kandaurov
a5e152b3d9 FastCGI: fixed create_loc_conf comments after 05b1a8f1e. 2024-11-12 17:21:22 +04:00
蕭澧邦
ea15896c1a SSL: fixed MSVC compilation after ebd18ec181.
MSVC generates a compilation error in case #if/#endif is used in a macro
parameter.
2024-11-11 22:29:55 +04:00
Mini Hawthorne
29aec5720f Upstream: copy upstream zone DNS valid time during config reload.
Previously, all upstream DNS entries would be immediately re-resolved
on config reload.  With a large number of upstreams, this creates
a spike of DNS resolution requests.  These spikes can overwhelm the
DNS server or cause drops on the network.

This patch retains the TTL of previous resolutions across reloads
by copying each upstream's name's expiry time across configuration
cycles.  As a result, no additional resolutions are needed.
2024-11-07 07:57:42 -08:00
Vladimir Homutov
ea4654550a Upstream: per-upstream resolver.
The "resolver" and "resolver_timeout" directives can now be specified
directly in the "upstream" block.
2024-11-07 07:57:42 -08:00
Ruslan Ermilov
5ebe7a4122 Upstream: pre-resolve servers on reload.
After configuration is reloaded, it may take some time for the
re-resolvable upstream servers to resolve and become available
as peers.  During this time, client requests might get dropped.

Such servers are now pre-resolved using the "cache" of already
resolved peers from the old shared memory zone.
2024-11-07 07:57:42 -08:00
Ruslan Ermilov
1524c5e3fc Core: inheritance of non-reusable shared memory zones.
When re-creating a non-reusable zone, make the pointer to the old zone
available during the new zone initialization.
2024-11-07 07:57:42 -08:00
Dmitry Volyntsev
9fe119b431 Upstream: construct upstream peers from DNS SRV records. 2024-11-07 07:57:42 -08:00
Ruslan Ermilov
db6870e06d Upstream: re-resolvable servers.
Specifying the upstream server by a hostname together with the
"resolve" parameter will make the hostname to be periodically
resolved, and upstream servers added/removed as necessary.

This requires a "resolver" at the "http" configuration block.

The "resolver_timeout" parameter also affects when the failed
DNS requests will be attempted again.  Responses with NXDOMAIN
will be attempted again in 10 seconds.

Upstream has a configuration generation number that is incremented each
time servers are added/removed to the primary/backup list.  This number
is remembered by the peer.init method, and if peer.get detects a change
in configuration, it returns NGX_BUSY.

Each server has a reference counter.  It is incremented by peer.get and
decremented by peer.free.  When a server is removed, it is removed from
the list of servers and is marked as "zombie".  The memory allocated by
a zombie peer is freed only when its reference count becomes zero.

Co-authored-by: Roman Arutyunyan <arut@nginx.com>
Co-authored-by: Sergey Kandaurov <pluknet@nginx.com>
Co-authored-by: Vladimir Homutov <vl@nginx.com>
2024-11-07 07:57:42 -08:00
Sergey Kandaurov
ebd18ec181 SSL: disabled TLSv1 and TLSv1.1 by default.
TLSv1 and TLSv1.1 are formally deprecated and forbidden to negotiate due
to insufficient security reasons outlined in RFC 8996.

TLSv1 and TLSv1.1 are disabled in BoringSSL e95b0cad9 and LibreSSL 3.8.1
in the way they cannot be enabled in nginx configuration.  In OpenSSL 3.0,
they are only permitted at security level 0 (disabled by default).

The support is dropped in Chrome 84, Firefox 78, and deprecated in Safari.

This change disables TLSv1 and TLSv1.1 by default for OpenSSL 1.0.1 and
newer, where TLSv1.2 support is available.  For older library versions,
which do not have alternatives, these protocol versions remain enabled.
2024-10-31 19:49:00 +04:00
jzebor-at-f5
f45c2707ea Updated security policy to include disclosure details. 2024-10-21 19:43:25 +04:00
Thierry Bastian
b394d44cfa Configure: MSVC compatibility with PCRE2 10.43. 2024-10-15 18:18:33 +04:00
nandsky
3f6d94d888 QUIC: prevent deleted stream frame retransmissions.
Since a2a513b93c, stream frames no longer need to be retransmitted after it
was deleted.  The frames which were retransmitted before, could be stream data
frames sent prior to a RESET_STREAM. Such retransmissions are explicitly
prohibited by RFC 9000, Section 19.4.
2024-10-08 19:55:14 +04:00
Sergey Kandaurov
144778aee6 Version bump. 2024-10-08 18:29:01 +04:00
Sergey Kandaurov
e24f7ccc16 nginx-1.27.2-RELEASE 2024-10-02 19:13:19 +04:00
Sergey Kandaurov
0e7c9ddb27 Updated OpenSSL used for win32 builds. 2024-10-02 19:13:19 +04:00
Sergey Kandaurov
5917e9de5a SSL: caching CA certificates.
This can potentially provide a large amount of savings,
because CA certificates can be quite large.

Based on previous work by Mini Hawthorne.
2024-10-01 17:59:24 +04:00
Sergey Kandaurov
61314518de SSL: caching CRLs.
Based on previous work by Mini Hawthorne.
2024-10-01 17:59:24 +04:00
Sergey Kandaurov
7ea2fb6cb1 SSL: caching certificate keys.
EVP_KEY objects are a reference-counted container for key material, shallow
copies and OpenSSL stack management aren't needed as with certificates.

Based on previous work by Mini Hawthorne.
2024-10-01 17:59:24 +04:00
Sergey Kandaurov
78ed123e71 SSL: caching certificates.
Certificate chains are now loaded once.

The certificate cache provides each chain as a unique stack of reference
counted elements.  This shallow copy is required because OpenSSL stacks
aren't reference counted.

Based on previous work by Mini Hawthorne.
2024-10-01 17:59:24 +04:00