Commit graph

8427 commits

Author SHA1 Message Date
Roman Arutyunyan
9b958b0007 nginx-1.28.3-RELEASE 2026-03-24 22:33:23 +04:00
Sergey Kandaurov
78f5814877 Stream: fixed client certificate validation with OCSP.
Check for OCSP status was missed in 581cf2267, resulting
in a broken validation.

Reported by Mufeed VH of Winfunc Research.
2026-03-24 22:33:23 +04:00
Sergey Kandaurov
0f71dd8ea9 Mail: fixed clearing s->passwd in auth http requests.
Previously, it was not properly cleared retaining length as part of
authenticating with CRAM-MD5 and APOP methods that expect to receive
password in auth response.  This resulted in null pointer dereference
and worker process crash in subsequent auth attempts with CRAM-MD5.

Reported by Arkadi Vainbrand.
2026-03-24 22:33:23 +04:00
Roman Arutyunyan
6a8513761f Mail: host validation.
Now host name resolved from client address is validated to only contain
the characters specified in RFC 1034, Section 3.5.  The validation allows
to avoid injections when using the resolved host name in auth_http and
smtp proxy.

Reported by Asim Viladi Oglu Manizada, Colin Warren,
Xiao Liu (Yunnan University), Yuan Tan (UC Riverside), and
Bird Liu (Lanzhou University).
2026-03-24 22:33:23 +04:00
Roman Arutyunyan
a1d18284e0 Dav: destination length validation for COPY and MOVE.
Previously, when alias was used in a location with Dav COPY or MOVE
enabled, and the destination URI was shorter than the alias, integer
underflow could happen in ngx_http_map_uri_to_path(), which could
result in heap buffer overwrite, followed by a possible segfault.
With some implementations of memcpy(), the segfault could be avoided
and the overwrite could result in a change of the source or destination
file names to be outside of the location root.

Reported by Calif.io in collaboration with Claude and Anthropic Research.
2026-03-24 22:33:23 +04:00
Roman Arutyunyan
b23ac73b00 Mp4: fixed possible integer overflow on 32-bit platforms.
Previously, a 32-bit overflow could happen while validating atom entries
count.  This allowed processing of an invalid atom with entrires beyond
its boundaries with reads and writes outside of the allocated mp4 buffer.

Reported by Prabhav Srinath (sprabhav7).
2026-03-24 22:33:23 +04:00
Roman Arutyunyan
a172c880cb Mp4: avoid zero size buffers in output.
Previously, data validation checks did not cover the cases when the output
contained empty buffers.  Such buffers are considered illegal and produce
"zero size buf in output" alerts.  The change rejects the mp4 files which
produce such alerts.

Also, the change fixes possible buffer overread and overwrite that could
happen while processing empty stco and co64 atoms, as reported by
Pavel Kohout (Aisle Research) and Tim Becker.
2026-03-24 22:33:23 +04:00
user.email
3986410e12 QUIC: improved error handling in OpenSSL compat layer.
Previously ngx_quic_compat_create_record() could try to encrypt a TLS
record even if encryption context was missing, which resulted in a NULL
pointer dereference.

The context is created by ngx_quic_compat_set_encryption_secret() called
from the OpenSSL keylog callback.  If an error occurred in that function,
the context could remain missing.  This could happen under memory pressure,
if an allocation failed inside this function.

The fix is to handle errors from ngx_quic_compat_set_encryption_secret()
and set qc->error to trigger an error after SSL_do_handshake() return.
Also, a check for context is added to ngx_quic_compat_create_record()
to avoid other similar issues.
2026-03-24 22:33:23 +04:00
Roman Arutyunyan
0fa49c5f7f QUIC: worker-bound stateless reset tokens.
Previously, it was possible to obtain a stateless reset token for a
connection by routing its packet to a wrong worker.  This allowed to
terminate the connection.

The fix is to bind stateless reset token to the worker number.
2026-03-24 22:33:23 +04:00
Sergey Kandaurov
7ac4e6b106 QUIC: Stateless Reset rate limiting.
It uses a bloom filter to limit sending Stateless Reset packets no more
than once per second in average for the given address.  This allows to
address resource asymmetry from precomputed packets, as well as to limit
potential Stateless Reset exchange.
2026-03-24 22:33:23 +04:00
Sergey Kandaurov
e0c5fd912f QUIC: refactored ngx_quic_address_hash().
Now it accepts an optional salt, to be used in a subsequent change.
2026-03-24 22:33:23 +04:00
Sergey Kandaurov
caec29ecdb QUIC: moved ngx_quic_address_hash(). 2026-03-24 22:33:23 +04:00
Sergey Kandaurov
5d1ad15bde QUIC: limited size of generated Stateless Reset packets.
Made sure to send packets smaller than the triggering packet,
following RFC 9000, Section 10.3.3.

Reported-by: cyberspace61
2026-03-24 22:33:23 +04:00
Sergey Kandaurov
eadf0aa8bc QUIC: adjusted minimum packet size to send Stateless Reset.
Now to be valid, it also assumes the Connection ID we require from a client.
2026-03-24 22:33:23 +04:00
Roman Arutyunyan
067c0b3f57 Resolver: fixed off-by-one read in ngx_resolver_copy().
It is believed to be harmless, see a similar change 077a890a76.

Reported-by: geeknik <geeknik@protonmail.ch>
2026-03-24 22:33:23 +04:00
CodeByMoriarty
4f0df130ba Mp4: validate sync sample values in stss atom.
Per ISO 14496-12 Section 8.6.2, sync sample numbers must be 1-based.
A zero-valued stss entry caused ngx_http_mp4_seek_key_frame() to
return a key_prefix exceeding the samples consumed in the forward
stts pass, which led the backward loop in ngx_http_mp4_crop_stts_data()
to walk past the beginning of the stts data buffer.

The fix validates each stss entry in ngx_http_mp4_seek_key_frame()
and returns an error if a zero sync sample is encountered.  The
function signature is changed to return ngx_int_t so it can signal
errors to the caller.
2026-03-24 22:33:23 +04:00
Sergey Kandaurov
246c744499 Updated zlib used for win32 builds. 2026-03-24 22:33:23 +04:00
Roman Arutyunyan
ed9f33a808 Updated OpenSSL and PCRE used for win32 builds. 2026-03-24 22:33:23 +04:00
Roman Arutyunyan
37366e9b7d Version bump. 2026-03-24 22:33:23 +04:00
Roman Arutyunyan
073ed33202 nginx-1.28.2-RELEASE 2026-02-04 21:22:23 +04:00
Roman Arutyunyan
6df8054cb2 Upstream: reinit upstream after reading bad response.
Previously, when connecting to a backend, if the read event handler was
called before the write event handler, and the received response triggered
a next upstream condition, then ngx_http_upstream_reinit() was not called
to clean up the old upstream context.  This had multiple implications.

For all proxy modules, since the last upstream response was not cleaned up,
it was mixed with the next upstream response.  This could result in ignoring
the second response status code, duplicate response headers or reporting
old upstream header errors.

With ngx_http_grpc_module and ngx_http_proxy_v2_module, ctx->connection
was left dangling since the object it referenced was allocated from the
last upstream connection pool, which was deleted when freeing last upstream.
This lead to use-after-free when trying to reuse this object for the next
upstream.
2026-02-04 21:22:23 +04:00
Roman Arutyunyan
784fa05025 Upstream: detect premature plain text response from SSL backend.
When connecting to a backend, the connection write event is triggered
first in most cases.  However if a response arrives quickly enough, both
read and write events can be triggered together within the same event loop
iteration.  In this case the read event handler is called first and the
write event handler is called after it.

SSL initialization for backend connections happens only in the write event
handler since SSL handshake starts with sending Client Hello.  Previously,
if a backend sent a quick plain text response, it could be parsed by the
read event handler prior to starting SSL handshake on the connection.
The change adds protection against parsing such responses on SSL-enabled
connections.
2026-02-04 21:22:23 +04:00
Aleksei Bavshin
dc50b86db8 Win32: fixed C4319 warning with MSVC 2022 x86.
The warning started to appear in Visual Studio 2022 version 17.14.21,
which corresponds to the C/C++ compiler version 19.44.35221.

The appropriate fix is to avoid mixing uint64_t and ngx_uint_t in an
expression with bitwise operations.  We can do that here because both
the original shm->size value and the result of the expression are 32-bit
platform words.
2026-02-04 21:22:23 +04:00
Roman Arutyunyan
c9e4b6a5ca Version bump. 2026-02-04 21:22:23 +04:00
Sergey Kandaurov
95078974cf nginx-1.28.1-RELEASE 2025-12-23 22:40:33 +04:00
Sergey Kandaurov
eec047c936 Proxy: fixed segfault in URI change.
If request URI was shorter than location prefix, as after replacement
with try_files, location length was used to copy the remaining URI part
leading to buffer overread.

The fix is to replace full request URI in this case.  In the following
configuration, request "/123" is changed to "/" when sent to backend.

    location /1234 {
        try_files /123 =404;
        proxy_pass http://127.0.0.1:8080/;
    }

Closes #983 on GitHub.
2025-12-23 22:40:33 +04:00
Sergey Kandaurov
2b50246858 HTTP/2: extended guard for NULL buffer and zero length.
In addition to moving memcpy() under the length condition in 15bf6d8cc,
which addressed a reported UB due to string function conventions, this
is repeated for advancing an input buffer, to make the resulting code
more clean and readable.

Additionally, although considered harmless for both string functions and
additive operators, as previously discussed in GitHub PR 866, this fixes
the main source of annoying sanitizer reports in the module.

Prodded by UndefinedBehaviorSanitizer (pointer-overflow).
2025-12-23 22:40:33 +04:00
Thierry Bastian
35dfd3f1c9 Configure: MSVC compatibility with PCRE2 10.47. 2025-12-23 22:40:33 +04:00
Roman Semenov
366b5c65ad OCSP: fixed invalid type for the 'ssl_ocsp' directive. 2025-12-23 22:40:33 +04:00
Sergey Kandaurov
d3cc7ec076 Updated OpenSSL and PCRE used for win32 builds. 2025-12-23 22:40:33 +04:00
Sergey Kandaurov
592bda7bb6 SSL: fixed "key values mismatch" with object cache inheritance.
In rare cases, it was possible to get into this error state on reload
with improperly updated file timestamps for certificate and key pairs.

The fix is to retry on X509_R_KEY_VALUES_MISMATCH, similar to 5d5d9adcc.
Additionally, loading SSL certificate is updated to avoid certificates
discarded on retry to appear in ssl->certs and in extra chain.
2025-12-23 22:40:33 +04:00
Sergey Kandaurov
aa714a1e87 Mail: xtext encoding (RFC 3461) in XCLIENT LOGIN.
The XCLIENT command uses xtext encoding for attribute values,
as specified in https://www.postfix.org/XCLIENT_README.html.

Reported by Igor Morgenstern of Aisle Research.
2025-12-23 22:40:33 +04:00
Sergey Kandaurov
40aff4f241 Upstream: overflow detection in Cache-Control delta-seconds.
Overflowing calculations are now aligned to the greatest positive integer
as specified in RFC 9111, Section 1.2.2.
2025-12-23 22:40:33 +04:00
willmafh
ffad76677c Fixed inaccurate index directive error report. 2025-12-23 22:40:33 +04:00
Sergey Kandaurov
1d6a17b02f Updated link to xslscript. 2025-12-23 22:40:33 +04:00
Sergey Kandaurov
8d75cffc65 Updated OpenSSL used for win32 builds. 2025-12-23 22:40:33 +04:00
Sergey Kandaurov
144a911e2b Mail: reset stale auth credentials with "smtp_auth none;".
They might be reused in a session if an SMTP client proceeded
unauthenticated after previous invalid authentication attempts.
This could confuse an authentication server when passing stale
credentials along with "Auth-Method: none".

The condition to send the "Auth-Salt" header is similarly refined.
2025-12-23 22:40:33 +04:00
Sergey Kandaurov
fbbbf189da Mail: improved error handling in plain/login/cram-md5 auth methods.
Previously, login and password storage could be left in inconsistent
state in a session after decoding errors.
2025-12-23 22:40:33 +04:00
Sergey Kandaurov
95b81d1c20 Auth basic: fixed file descriptor leak on memory allocation error.
Found by Coverity (CID 1662016).
2025-12-23 22:40:33 +04:00
Sergey Kandaurov
62e757ec60 HTTP/2: fixed handling of the ":authority" header.
Previously, it misused the Host header processing resulting in
400 (Bad Request) errors for a valid request that contains both
":authority" and Host headers with the same value, treating it
after 37984f0be as if client sent more than one Host header.
Such an overly strict handling violates RFC 9113.

The fix is to process ":authority" as a distinct header, similarly
to processing an authority component in the HTTP/1.x request line.
This allows to disambiguate and compare Host and ":authority"
values after all headers were processed.

With this change, the ngx_http_process_request_header() function
can no longer be used here, certain parts were inlined similar to
the HTTP/3 module.

To provide compatibility for misconfigurations that use $http_host
to return the value of the ":authority" header, the Host header,
if missing, is now reconstructed from ":authority".
2025-12-23 22:40:33 +04:00
Sergey Kandaurov
86dacb7ebe HTTP/2: factored out constructing the Host header.
No functional changes.
2025-12-23 22:40:33 +04:00
Roman Arutyunyan
bbf65b6e87 HTTP/3: fixed handling of :authority and Host with port.
RFC 9114, Section 4.3.1. specifies a restriction for :authority and Host
coexistence in an HTTP/3 request:

: If both fields are present, they MUST contain the same value.

Previously, this restriction was correctly enforced only for portless
values.  When Host contained a port, the request failed as if :authority
and Host were different, regardless of :authority presence.

This happens because the value of r->headers_in.server used for :authority
has port stripped.  The fix is to use r->host_start / r->host_end instead.
2025-12-23 22:40:33 +04:00
Sergey Kandaurov
a5cfa096d2 HTTP/3: fixed potential type overflow in string literal parser.
This might happen for Huffman encoded string literals as the result
of length expansion.  Notably, the maximum length of string literals
is already limited with the "large_client_header_buffers" directive,
so this was only possible with nonsensically large configured limits.
2025-12-23 22:40:33 +04:00
Sergey Kandaurov
8d00372555 Events: compatibility with NetBSD 10.0 in kqueue.
The kevent udata field was changed from intptr_t to "void *",
similar to other BSDs and Darwin.

The NGX_KQUEUE_UDATA_T macro is adjusted to reflect that change,
fixing -Werror=int-conversion errors.
2025-12-23 22:40:33 +04:00
Sergey Kandaurov
089da0a48b Configure: set NGX_KQUEUE_UDATA_T at compile time.
The NGX_KQUEUE_UDATA_T macro is used to compensate the incompatible
kqueue() API in NetBSD, it doesn't really belong to feature tests.

The change limits the macro visibility to the kqueue event module.
Moving from autotests also simplifies testing a particular NetBSD
version as seen in a subsequent change.
2025-12-23 22:40:33 +04:00
Sergey Kandaurov
2009d46d6d Events: fixed -Wzero-as-null-pointer-constant warnings in kqueue.
The kevent udata field is special in that we maintain compatibility
with NetBSD versions that predate using the "void *" type.

The fix is to cast to intermediate uintptr_t that is casted back to
"void *" where appropriate.
2025-12-23 22:40:33 +04:00
Sergey Kandaurov
2787d67e89 SSL: fixed testing OPENSSL_VERSION_NUMBER for OpenSSL 3.0+.
Prior to OpenSSL 3.0, OPENSSL_VERSION_NUMBER used the following format:

MNNFFPPS: major minor fix patch status

Where the status nibble (S) has 0+ for development and f for release.

The format was changed in OpenSSL 3.0.0, where it is always zero:

MNN00PP0: major minor patch
2025-12-23 22:40:33 +04:00
Sergey Kandaurov
4bd5b1b59a SSL: SSL_group_to_name() compatibility macro.
No functional changes.
2025-12-23 22:40:33 +04:00
Sergey Kandaurov
10792c3644 Win32: fixed PCRE license for nginx/Windows zip. 2025-12-23 22:40:33 +04:00
Sergey Kandaurov
eaf5446984 Updated OpenSSL and PCRE used for win32 builds. 2025-12-23 22:40:33 +04:00