Commit graph

8807 commits

Author SHA1 Message Date
Sergey Kandaurov
2e8440bcdc Version bump
Some checks failed
buildbot / buildbot (push) Has been cancelled
2026-11-18 20:40:13 +04:00
Roman Arutyunyan
c2c44702c2 nginx-1.31.9-RELEASE 2026-11-11 21:48:23 +04:00
Roman Arutyunyan
d1ffe6fa89 Try files: fix uri formating in case of script underwrite
Previously, if try_files was used with alias, and the script produced
a string smaller than the predicted size, then an integer underflow
could happen which resulted in buffer overrun.

Fix is to recalculate the length after running the script.

A similar length recalculation exists in ngx_http_index_module.
It was added by 25f920eca when fixing script overruns.

Reported by Marc Luchian & Liviu-Alexandru Bud.
2026-11-11 16:18:05 +04:00
Sergey Kandaurov
c4892abca6 Core: fixed segfault in PROXY protocol v2 with dynamic certificates
If PROXY protocol v2 was enabled with dynamic certificate loading,
notably in the stream module, a segmentation fault might happen.

The reason is that during an abbreviated handshake the certificate
callback is not called, leading to NULL being returned from
SSL_get_certificate().

The fix is similar to 5784889fb.

Reported by ruokeqx.
2026-11-11 16:17:45 +04:00
Roman Arutyunyan
b5252dae1c QUIC: avoid main connection reuse after creating a stream
Previously, ngx_quic_create_stream() cleared the main connection's
reusable flag and then called ngx_get_connection() before inserting the
new stream into the tree.  If the worker was low on free connections,
the drain inside ngx_get_connection() could close an idle stream of the
same main connection.  Since the new stream was not in the tree yet,
that close found no remaining streams and marked the main connection
reusable again.  Once reusable, the connection could later be drained
while processing one of its streams, for example when connecting to an
upstream, freeing it while still in use.

Fix is to insert the new stream into the tree before calling
ngx_get_connection(), so the main connection is not considered idle.

Reported by Xint.io.
2026-11-11 16:17:24 +04:00
Vadim Zhestikov
1d1d861a5e Mail: blocked client writes while resolving SMTP client
While the SMTP client address and name are being resolved, the client
read handler is ngx_mail_smtp_block_reading(), but the client write
handler was ngx_mail_send().  If ngx_handle_write_event() failed in it,
the client connection was closed, but the resolver context was not
cancelled, and the resolver handler accessed the freed session when the
resolving completed or timed out.

The client write handler is now ngx_mail_smtp_block_writing(), which
cancels the resolver context on errors the same way
ngx_mail_smtp_block_reading() does.  ngx_mail_send() is restored in
ngx_mail_smtp_greeting(), which is also needed with smtp_greeting_delay,
where the error is sent without s->quit, and in
ngx_mail_smtp_resolve_addr_handler() before the posted name resolving,
where s->resolver_ctx still points to a context which is already done.
2026-11-11 16:17:01 +04:00
Vadim Zhestikov
013ce18796 Mail: blocked client writes while connecting to upstream
While connecting to the upstream and reading its greeting, the client
read handler is ngx_mail_proxy_block_read(), but the client write
handler was left as it was.  If ngx_handle_write_event() failed in it,
the client connection was closed without the upstream one, and the next
upstream event accessed the freed session.

The client write handler is now ngx_mail_proxy_block_write(), which
closes both connections on errors the same way
ngx_mail_proxy_block_read() does.
2026-11-11 16:17:01 +04:00
Vadim Zhestikov
a22ab71056 Mail: blocked client writes while waiting for auth_http response
While waiting for the auth_http response, the client read handler is
ngx_mail_auth_http_block_read(), but the write handler was left as
ngx_mail_send(), so a client write event during the wait was handled
by a function which can close the client connection, destroying the
session while the auth_http connection still referenced it.

The client write handler is now blocked while waiting for the auth_http
response, with proper cleanup on errors, and restored right after the
auth_http connection is closed.
2026-11-11 16:17:01 +04:00
Vadim Zhestikov
754fe68c2e Mail: fixed use-after-free on client reset during auth_http request
When a client command starts an auth_http request, the default reply
set by the POP3, IMAP and SMTP auth state handlers remains in s->out,
though it is never used: the actual reply depends on the auth_http
response.  With ngx_mail_send() as the client write handler, the reply
could be sent before the authentication result was known, and if the
client reset the connection, the failed send destroyed the session
while the auth_http connection still referenced it.

The queued reply is now discarded when the auth_http request starts,
similarly to ngx_mail_proxy_init().

Reported by Xint.io.
2026-11-11 16:17:01 +04:00
Maxim Dounin
e505109a3f Mail: updated ngx_mail_send() to set handlers on s->quit.
Most notably, this fixes potential issues when a fatal error message is
sent with ngx_mail_send() with s->quit set, but the read handler is not
updated.  Despite s->quit, ngx_mail_send() might not be able to send the
error message immediately, and the read handler might be called on read
events.  In particular, in ngx_mail_auth_http_block_read() and in
ngx_mail_proxy_block_read() this could potentially cause accesses to
freed memory or already closed connections in ngx_handle_read_event()
error handling code paths.

Reported by Evan Hellman,
https://github.com/freenginx/nginx/issues/23
https://github.com/freenginx/nginx/issues/24

Signed-off-by: Vadim Zhestikov <v.zhestikov@f5.com>
Origin: <https://freenginx.org/hg/nginx/rev/87725983f346>
2026-11-11 16:17:01 +04:00
Roman Arutyunyan
e27f5fa84f HTTP/2: account for queued frames when validating WINDOW_UPDATE
When a stream is terminated, its unsent payload length is refunded back
to the connection flow control.  Previously, this could increase the
flow control beyond NGX_HTTP_V2_MAX_WINDOW, if it was increased by the
client after the stream frames were queued and before the stream was
terminated.  This eventually resulted in broken buffer size control in
ngx_http_v2_send_chain() followed by memory corruption and a possible
segmentation fault.

The fix is to account for the queued frames when validating a client
WINDOW_UPDATE.  From the client's point of view, the queued frames
still belong to the flow control window.

Reported by Xint.io.
2026-11-11 16:16:37 +04:00
Roman Arutyunyan
e39708edc6 Resolver: fix non-current resolve finalization from resolve handler
Previously, when a resolve handler called ngx_resolve_name_done() or
ngx_resolve_addr_done() for another resolve of the same name/address,
a use-after-free could happen while reporting the finalized resolve.
This may happen with upstream resolve when at least one subrequest is
resolving the same name, and the request is terminated from the
upstream resolve handler.

The problem occurs when finalizing a non-current resolve that is
already detached from rn->waiting and is about to be reported.  Such
cases produced "could not cancel" alerts.  The resolve may also be
detached with its node reset, while following a CNAME, in which case
no alert was produced.

Now the alerts are converted to debug messages and a finalizer is
installed into ctx->handler to release the context memory later.

Reported by Xint.io.
2026-11-11 16:15:47 +04:00
Roman Arutyunyan
8492a8b8a9 Resolver: report error on CNAME restart failure
Previously, if restarting a resolve with a CNAME name failed due to a
memory allocation error, no error was reported.  The waiting requests
were left detached from any node until their timeouts expired.

Now the error is reported to the waiting requests immediately.
2026-11-11 16:15:47 +04:00
Roman Arutyunyan
c51ffa2d1a HTTP/3: explicit handling of NGX_AGAIN
Following the previous change, this change adds explicit handling
of NGX_AGAIN while reading HTTP/3 request body for the sake of
correctness.
2026-11-11 16:15:24 +04:00
Maxim Dounin
2b129b9363 Request body: explicit handling of NGX_AGAIN.
Request body reading indirectly uses the "do { c->recv() } while
(c->read->ready)" form, which is not really correct, as for example with
SSL c->read->ready may be still set when c->recv() returns NGX_AGAIN due
to SSL_ERROR_WANT_WRITE (see 7351:2b5528023f6b), and therefore this form
might be an infinite loop.

Added explicit NGX_AGAIN handling for the sake of correctness.

Signed-off-by: Elijah Zupancic <e.zupancic@f5.com>
Origin: <https://freenginx.org/hg/nginx/rev/392e8e2fd22a8461e75a67d5d33d85c07974e1e3>
2026-11-11 16:15:24 +04:00
Vadim Zhestikov
6f9fceed8d Stream: client SSL certificates were not checked with SNI
If the SSL handshake completed in the first call of
ngx_stream_ssl_handler(), the client certificate was verified using the
configuration of the default server, rather than the virtual server
selected by SNI during the handshake.

The problem appeared in d21675228 (1.25.5).  It is similar to the one
fixed in 620c9a4c4.

The fix is to re-read the server configuration before verifying the
client certificate.

Reported by CERT.PL.
2026-11-11 16:14:46 +04:00
Aleksei Bavshin
d9fd14eb3e Stream ssl_preread: forbid duplicate SNI and ALPN
As stated in the TLS Extensions specification (RFC 3546) and all
subsequent TLS specification updates,

: There MUST NOT be more than one extension of the same type.

Such a ClientHello is now treated as malformed, as with other parsing
errors.
2026-11-11 16:14:17 +04:00
Aleksei Bavshin
30b8bf67e2 Stream ssl_preread: forbid trailing data in extensions
As required explicitly in RFC 9846 Section 4.3 and implicitly in all the
previous versions of TLS extensions specification.

Reported by Vivek Parikh, BreachX Zero Day Labs using Typhon AI Mil v2.
2026-11-11 16:14:17 +04:00
Roman Arutyunyan
2df48a501d HTTP/2: reset reusable connection status on stream creation
Previously, an HTTP/2 connection could be reusable while having streams.
This could result in an attempt to drain the connection while processing
one if its streams, for example when connecting to an upstream.  After
recognizing that the connection has streams, an attempt to send the
GOAWAY frame was made.  On send failure, the connection was immediately
closed and its pool released.  This triggered a use-after-free up the
stack.

Having an HTTP/2 connection with streams registered as reusable became
possible after 76672e650.  A connection with no streams and a partial
frame read from client was registered as reusable to avoid DoS attacks.
So if a client sends only the first HEADERS frame byte, the connection
becomes reusable.  Later, when the remaining HEADERS bytes are received
and a new stream is created, the reusable status is not reset until the
connection becomes idle.

Fix is to mark the connection non-reusable upon stream creation.

Reported by Albert @ Vexera AI.
2026-11-11 16:13:49 +04:00
Sergey Kandaurov
2a3a19c6fd Updated zlib used for win32 builds
Some checks failed
buildbot / buildbot (push) Has been cancelled
2026-11-09 17:29:49 +04:00
Roman Arutyunyan
d17f1d249d Map: fixed regex pattern lifetime
Some checks failed
buildbot / buildbot (push) Has been cancelled
The regex pattern was referenced from the temporary pool used for
map block parsing, which is destroyed once the block is parsed.  The
pattern is later used for logging if regex matching fails, e.g., due
to PCRE2 match limit, JIT stack limit, or invalid UTF-8 with (*UTF),
resulting in released memory being logged.

The fix is to copy the pattern into the configuration pool.
2026-11-06 21:04:11 +04:00
Maxim Dounin
62f94cf696 Index: fixed handling of non-cacheable variables.
Some checks are pending
buildbot / buildbot (push) Waiting to run
Previously, "e.flushed = 1;" was incorrectly used during initial length
calculations, and as a result non-cacheable variables were not flushed.
The fix is to only set "e.flushed" when evaluating values.

A similar issue in try_files was fixed in 2424:46d11bff21ef (0.7.29).

Origin: <https://freenginx.org/hg/nginx/rev/511b31fbc525>
Signed-off-by: Roman Arutyunyan <arut@nginx.com>
2026-11-05 19:50:02 +04:00
Aleksei Bavshin
d45e6c5c49 OCSP: preserved serial number sign in cache keys
Some checks are pending
buildbot / buildbot (push) Waiting to run
As OpenSSL does not store the sign in the ASN1_INTEGER string data,
it is not possible to distinguish positive and negative serial numbers.
While negative serials are forbidden in RFC 5280 4.1.2.2, it also says
that we SHOULD expect these from non-conforming CAs.
The solution is to use full DER-encoding of a signed integer obtained
with i2d_ASN1_INTEGER.

The change also addresses a correctness issue, as ASN1_STRING accessors
should not be used on ASN1_INTEGER.
2026-11-05 18:27:12 +04:00
Aleksei Bavshin
d56c3fb5dc OCSP: removed padding of serial in cache keys
Right-padding the serials makes it impossible to distinguish between n,
n * 256 and so on.  This has no practical impact, as small, predictable
serial numbers have been discouraged for the last two decades.

While the change has a potential of introducing memory fragmentation,
current allocations stay within a single slab bucket on all supported
architectures.

Reported by Gyejin Lee, QED Audit.
2026-11-05 18:27:12 +04:00
Y.Horie
45ae79aa6a GeoIP: rejected out-of-range coordinates from MMDB lookups
Some checks are pending
buildbot / buildbot (push) Waiting to run
The $geoip_latitude and $geoip_longitude values are formatted with
ngx_sprintf(buf, "%.4f", value) into a buffer sized for a coordinate,
but the DOUBLE/FLOAT value is taken from the database with no range
check.  A crafted or corrupted MMDB can store a huge magnitude (e.g.
1e30 or an infinity), and ngx_sprintf, which is unbounded, then writes
past the buffer in the request or connection pool.

Coordinates outside [-180, 180] are now rejected, so the variables
report "not found" as they do for a missing entry.  The comparison also
rejects a NaN.

Closes: https://github.com/nginx/nginx/issues/1907
2026-11-05 10:54:49 +05:30
Piotr Przybylski
f7504639fa Control API: warn in single process mode only if API is enabled
Previously, the "control API unavailable in single process mode"
warning was logged on every start in single process mode, even
without the "-l" option.
2026-11-04 16:16:45 -08:00
Sourav Bhowmik
a4b482207d Request body: flood detection for chunked request body
Some checks are pending
buildbot / buildbot (push) Waiting to run
Chunk sizes (including leading zeros), chunk extensions and trailers
of a chunked request body were not accounted, allowing a client to send
an unbounded amount of framing with little or no body data.

Now all received bytes are counted in rb->received and compared to
the body data, using the same flood detection as in HTTP/2 and HTTP/3.

Reported by jskoetsier.
2026-11-05 00:42:24 +04:00
Marek Ludha
cc1bbc7f7e HTTP/2: ignore unknown flags in the SETTINGS message
This is required by RFC9113 section 4.1:
"Unused flags MUST be ignored on receipt"
2026-11-05 00:11:29 +04:00
Sergey Kandaurov
867aefddbc HTTP/2: do not block the output queue on trailers
Unlike response headers, trailers are queued along with the stream data.
Blocking the queue on them would hold back every frame queued later,
including higher priority streams.

Also, this way unsent trailers are discarded along with the stream data
when the stream is reset.
2026-11-04 22:09:10 +04:00
Sergey Kandaurov
61031503dc HTTP/2: optimized queuing of DATA frames
With priorities from RFC 9218, streams of the same urgency are ordered
by their identifiers, so queuing a frame of an older stream traverses
the frames of all newer ones.

Frames queued in ngx_http_v2_send_chain() belong to a single stream, and
hence to a single position in the output queue, which does not change
while they are queued.  Now the position is searched once per call.
2026-11-04 22:09:10 +04:00
최대우 (Daewoo Choi)
050076e2b4 Control API: fixed handling of oversized requests
A request line larger than the receive buffer was answered with no
response at all, while every other malformed request gets a status
code.  The buffer-full check also ran at the start of the next read
event, which may never arrive, since SIGIO is raised by new data.
The check is now made after parsing, so 400 is returned right away.
2026-11-04 08:16:34 -08:00
Vadim Zhestikov
67290bfea6 Fixed $cookie_ after a cookie without a name
Some checks failed
buildbot / buildbot (push) Has been cancelled
A cookie without a name, such as "a" in "Cookie: a; a=1", was skipped
together with the separator that follows it, so the next cookie was
skipped as well and $cookie_a was not found.  The userid module was
affected in the same way.

User agents send a cookie with an empty name as a bare value (RFC
6265bis, section 5.8.3), so such a token is a valid part of the Cookie
header.

The fix is to not consume the character that fails the "=" check.

The problem appeared in 899b44eab (0.1.29).
2026-10-28 12:37:18 -07:00
Vadim Zhestikov
5cb1e207b1 OCSP: disabled handling of headers without a colon
Header names not followed by a colon and a value in an OCSP responder
reply were accepted as headers with an empty value, similarly to
ngx_http_parse_header_line().  With this change, such headers are
rejected with the "OCSP responder sent invalid response" error, and the
response is not used.

The problem appeared in 74ad4494a (1.3.7).
2026-10-28 10:08:44 -07:00
Vadim Zhestikov
297861bf6c Mail: disabled handling of headers without a colon in auth_http
Header names not followed by a colon and a value in an auth_http server
response were accepted as headers with an empty value, similarly to
ngx_http_parse_header_line().  With this change, such headers are
rejected with the "sent invalid header in response" error, and the
client gets the internal server error reply.

The problem appeared in 5192b3651 (0.1.38).
2026-10-28 10:08:44 -07:00
Maxim Dounin
da92f58a06 Disabled handling of headers without a colon.
Starting with nginx 0.1.29 (509:9b8c906f6e63), header names not followed
by a colon and a value were allowed.  Such headers were interpreted as
headers with an empty value.  With this change, such headers are
unconditionally rejected.

Requested by Maksim Yevmenkin.

Closes: https://github.com/nginx/nginx/issues/1499
Signed-off-by: Vadim Zhestikov <v.zhestikov@f5.com>
Origin: <https://freenginx.org/hg/nginx/rev/9a5e2296c1be>
2026-10-28 10:08:44 -07:00
Nexory
835be60c92 HTTP/3: fix QPACK static table values to match RFC 9204
Five values of the static table lacked the space after a semicolon
compared to RFC 9204, Appendix A: indexes 52, 57, 58, 62 and 85.  A
field sent by a client as an indexed static entry was thus decoded
without the space, for example "text/html;charset=utf-8" instead of
"text/html; charset=utf-8" in the Content-Type header.  The encoder
is not affected, it does not use these indexes.
2026-10-28 20:26:26 +04:00
Andrew Clayton
797c039a98 SSL: explicitly clear the session staging buffer
Some checks are pending
buildbot / buildbot (push) Waiting to run
Since 3d7304b52, sessions are serialized into the static buffer
ngx_ssl_session_buffer, so the last cached, resumed, or proxied session
remains in memory, master secret included, until overwritten. Clear the
buffer on all exits that write to it.

While here, the session id length check is moved before serialization,
which removes an exit path with a populated buffer and a needless
i2d_SSL_SESSION() call for sessions that are not cached.

Note that sessions are still kept in shared memory until evicted.

Assisted-by: opencode:claude-opus-5
Closes: https://github.com/nginx/nginx/issues/1736
2026-10-27 16:51:17 +00:00
Vadim Zhestikov
9a7439fd79 Core: made initgroups() failures fatal
Some checks failed
buildbot / buildbot (push) Has been cancelled
Previously, an initgroups() failure was only logged, and the worker
process went on with the supplementary groups inherited from the master
process, since setgid() does not change them.  Anything relying on the
configured user's groups then failed at run time, far from the log
message, and the outcome depended on which worker hit the error.

Now such a failure is fatal, similarly to setgid() and setuid().  The
exception is EPERM, which is logged and ignored: it is returned when
supplementary groups cannot be changed at all, for example, in a user
namespace with setgroups denied, see user_namespaces(7), or under
seccomp.

This dates back to 42b12b34f (0.1.11).
2026-10-23 07:54:13 -07:00
Maxim Dounin
148c75678c Proxy: use zero Content-Length while discarding request body.
Some checks are pending
buildbot / buildbot (push) Waiting to run
Previously, r->headers_in.content_length_n was used, which is not 0 till
the request body is fully discarded, and the request might hang.

Adapted for nginx: the same change is applied to the HTTP/2 proxy
module (proxy_http_version 2), which is not present in freenginx and
used r->headers_in.content_length_n in the same way.  With an HTTP/2
upstream, the stale length resulted in the request being rejected
by the upstream, since the stream was closed without the body.

Co-authored-by: Elijah Zupancic <e.zupancic@f5.com>
Signed-off-by: Elijah Zupancic <e.zupancic@f5.com>
Origin: <https://freenginx.org/hg/nginx/rev/51e0dc7137843feda75b497773f598d3836c60a1>
2026-10-22 17:05:26 +04:00
Maxim Dounin
807e53d990 Limit conn: fixed counter leak on memory allocation errors.
Some checks are pending
buildbot / buildbot (push) Waiting to run
Previously, if ngx_pool_cleanup_add() failed, already incremented
connection counter was left as is, eventually resulting in unexpected
connection limiting or shared memory exhaustion.  Fix is to decrement
the counter by calling the cleanup handler with data on stack.

Signed-off-by: Elijah Zupancic <e.zupancic@f5.com>
Origin: <https://freenginx.org/hg/nginx/rev/722e252fcabe6413eb63555890273d7b0e7fc132>
2026-10-22 15:59:04 +04:00
Roman Arutyunyan
83f041908b Version bump 2026-10-22 15:57:45 +04:00
Sergey Kandaurov
140aa94271 nginx-1.31.8-RELEASE
Some checks are pending
buildbot / buildbot (push) Waiting to run
2026-10-21 18:24:51 +04:00
Sergey Kandaurov
80f0b3b840 Core: working_directory validation
Some checks are pending
buildbot / buildbot (push) Waiting to run
Previously, an invalid working_directory was only detected on worker
process startup: if chdir() failed, worker processes exited and were
not respawned, while "nginx -t" reported success.

Now the directory is checked during configuration parsing.  Note that
this doesn't cover insufficient permissions for worker processes.
2026-10-21 11:48:28 +04:00
Sergey Kandaurov
0e20f1fb0f Core: working_directory relative to prefix
Previously, a relative path was resolved against the current working
directory of the master process, which depends on how nginx is started.
Now it is resolved relative to prefix, similar to pid and error_log.
2026-10-21 11:48:28 +04:00
최대우 (Daewoo Choi)
b38c9d8068 HTTP/3: avoid unaligned stores in Huffman encoding
Some checks are pending
buildbot / buildbot (push) Waiting to run
The encoder wrote accumulated bits by casting the destination to
uint64_t *, or uint32_t * on 32-bit platforms, and assigning through
it, which requires the destination to be suitably aligned.

In HTTP/2 the destination is a temporary buffer from ngx_palloc() and
is always aligned.  In HTTP/3 it points past a variable number of
prefix integer bytes, so its alignment is arbitrary and the store is
undefined behaviour.

Byte order conversion is now separated from the store, which is done
with ngx_memcpy().
2026-10-20 13:54:33 +01:00
Sergey Kandaurov
4953fc6f02 Misc: fixed "zip" target with GNU sed
Some checks are pending
buildbot / buildbot (push) Waiting to run
2026-10-20 14:52:02 +04:00
Konstantin Pavlov
97e4e7a224 GH: request an id token and pass secrets to a callee in buildbot.yml
Both are required to be able to do authentication in a callee workflow.
2026-10-20 14:51:36 +04:00
Sai Krishna Kumar Reddy YADAMAKANTI
398a48e33d GH: workflow to generate windows zip
Some checks are pending
buildbot / buildbot (push) Waiting to run
2026-10-19 23:54:18 +05:30
Sergey A. Osokin
c42f8fa5ca Fixed a typo 2026-10-19 10:24:03 -07:00
Evgeny Shirykalov
1725db9059 JSON: report escaped strings as separate parser events
Some checks failed
buildbot / buildbot (push) Has been cancelled
The parser now emits NGX_JSON_KEY_ESCAPED and
NGX_JSON_VALUE_STRING_ESCAPED for strings holding escape sequences, so
consumers no longer rescan tokens.
2026-10-16 09:42:01 -07:00