]> git.kaiwu.me - nginx.git/log
nginx.git
6 days agoOCSP: removed padding of serial in cache keys
Aleksei Bavshin [Thu, 17 Sep 2026 20:22:33 +0000 (13:22 -0700)]
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.

6 days agoGeoIP: rejected out-of-range coordinates from MMDB lookups
Y.Horie [Tue, 27 Oct 2026 22:25:20 +0000 (07:25 +0900)]
GeoIP: rejected out-of-range coordinates from MMDB lookups

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
6 days agoControl API: warn in single process mode only if API is enabled
Piotr Przybylski [Sun, 25 Oct 2026 12:54:45 +0000 (13:54 +0100)]
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.

6 days agoRequest body: flood detection for chunked request body
Sourav Bhowmik [Tue, 4 Aug 2026 13:34:19 +0000 (06:34 -0700)]
Request body: flood detection for chunked request body

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.

6 days agoHTTP/2: ignore unknown flags in the SETTINGS message
Marek Ludha [Fri, 25 Sep 2026 13:19:04 +0000 (15:19 +0200)]
HTTP/2: ignore unknown flags in the SETTINGS message

This is required by RFC9113 section 4.1:
"Unused flags MUST be ignored on receipt"

6 days agoHTTP/2: do not block the output queue on trailers
Sergey Kandaurov [Fri, 25 Sep 2026 15:34:44 +0000 (15:34 +0000)]
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.

6 days agoHTTP/2: optimized queuing of DATA frames
Sergey Kandaurov [Fri, 25 Sep 2026 14:16:36 +0000 (14:16 +0000)]
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.

7 days agoControl API: fixed handling of oversized requests
최대우 (Daewoo Choi) [Mon, 2 Nov 2026 04:07:30 +0000 (13:07 +0900)]
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.

13 days agoFixed $cookie_ after a cookie without a name
Vadim Zhestikov [Fri, 9 Oct 2026 19:08:23 +0000 (12:08 -0700)]
Fixed $cookie_ after a cookie without a name

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).

2 weeks agoOCSP: disabled handling of headers without a colon
Vadim Zhestikov [Wed, 28 Oct 2026 15:55:50 +0000 (08:55 -0700)]
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).

2 weeks agoMail: disabled handling of headers without a colon in auth_http
Vadim Zhestikov [Wed, 28 Oct 2026 15:55:50 +0000 (08:55 -0700)]
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).

2 weeks agoDisabled handling of headers without a colon.
Maxim Dounin [Wed, 8 May 2024 20:00:07 +0000 (23:00 +0300)]
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>

2 weeks agoHTTP/3: fix QPACK static table values to match RFC 9204
Nexory [Fri, 23 Oct 2026 04:47:25 +0000 (06:47 +0200)]
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.

2 weeks agoSSL: explicitly clear the session staging buffer
Andrew Clayton [Tue, 29 Sep 2026 20:36:48 +0000 (21:36 +0100)]
SSL: explicitly clear the session staging buffer

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
2 weeks agoCore: made initgroups() failures fatal
Vadim Zhestikov [Fri, 9 Oct 2026 21:57:16 +0000 (14:57 -0700)]
Core: made initgroups() failures fatal

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).

2 weeks agoProxy: use zero Content-Length while discarding request body.
Maxim Dounin [Sat, 27 Apr 2024 15:18:13 +0000 (18:18 +0300)]
Proxy: use zero Content-Length while discarding request body.

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>

2 weeks agoLimit conn: fixed counter leak on memory allocation errors.
Maxim Dounin [Mon, 7 Jul 2025 01:34:18 +0000 (04:34 +0300)]
Limit conn: fixed counter leak on memory allocation errors.

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>

2 weeks agoVersion bump
Roman Arutyunyan [Thu, 22 Oct 2026 11:55:01 +0000 (15:55 +0400)]
Version bump

3 weeks agonginx-1.31.8-RELEASE release-1.31.8
Sergey Kandaurov [Wed, 21 Oct 2026 11:29:49 +0000 (11:29 +0000)]
nginx-1.31.8-RELEASE

3 weeks agoCore: working_directory validation
Sergey Kandaurov [Mon, 19 Oct 2026 15:53:30 +0000 (15:53 +0000)]
Core: working_directory validation

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.

3 weeks agoCore: working_directory relative to prefix
Sergey Kandaurov [Mon, 19 Oct 2026 15:53:30 +0000 (15:53 +0000)]
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.

3 weeks agoHTTP/3: avoid unaligned stores in Huffman encoding
최대우 (Daewoo Choi) [Thu, 1 Oct 2026 03:59:44 +0000 (12:59 +0900)]
HTTP/3: avoid unaligned stores in Huffman encoding

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().

3 weeks agoMisc: fixed "zip" target with GNU sed
Sergey Kandaurov [Mon, 19 Oct 2026 19:17:59 +0000 (19:17 +0000)]
Misc: fixed "zip" target with GNU sed

3 weeks agoGH: request an id token and pass secrets to a callee in buildbot.yml
Konstantin Pavlov [Mon, 28 Sep 2026 21:13:07 +0000 (14:13 -0700)]
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.

3 weeks agoGH: workflow to generate windows zip
Sai Krishna Kumar Reddy YADAMAKANTI [Wed, 30 Sep 2026 13:12:44 +0000 (13:12 +0000)]
GH: workflow to generate windows zip

3 weeks agoFixed a typo
Sergey A. Osokin [Mon, 19 Oct 2026 17:06:39 +0000 (13:06 -0400)]
Fixed a typo

3 weeks agoJSON: report escaped strings as separate parser events
Evgeny Shirykalov [Wed, 30 Sep 2026 16:52:47 +0000 (09:52 -0700)]
JSON: report escaped strings as separate parser events

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.

3 weeks agoJSON: modified ngx_json_unescape_string() to unescape into a new buffer
Evgeny Shirykalov [Wed, 30 Sep 2026 16:52:19 +0000 (09:52 -0700)]
JSON: modified ngx_json_unescape_string() to unescape into a new buffer

3 weeks agoFixed Priority parsing of large integers on 32-bit platforms
nishat shabbir [Thu, 15 Oct 2026 14:45:37 +0000 (20:15 +0530)]
Fixed Priority parsing of large integers on 32-bit platforms

On 32-bit platforms, ngx_atoi() fails on syntactically valid Integers
above 2147483647, and the whole Priority field was rejected.  Now such
values are ignored, similar to Decimals.

3 weeks agoCore: fixed ioctl(FIOASYNC) argument type
Aleksei Bavshin [Thu, 1 Oct 2026 19:49:15 +0000 (12:49 -0700)]
Core: fixed ioctl(FIOASYNC) argument type

The documented argument type for this operation is an integer boolean.
Passing 1 as u_long makes the call silently fail on 64-bit big-endian
platforms, as the kernel receives only high 4 bytes set to 0.

3 weeks agoControl API: use more portable ioctl(FIOASYNC)
Aleksei Bavshin [Thu, 1 Oct 2026 16:44:28 +0000 (09:44 -0700)]
Control API: use more portable ioctl(FIOASYNC)

While both FIOASYNC and O_ASYNC are non-standard, the former is more
widespread and is already used in ngx_process.c.

Fixes build on Solaris and Illumos.

3 weeks agoSSL: workaround for i2d_SSL_SESSION() negative values
Vadim Zhestikov [Wed, 22 Jul 2026 23:10:18 +0000 (16:10 -0700)]
SSL: workaround for i2d_SSL_SESSION() negative values

i2d_SSL_SESSION() may unexpectedly return a negative value on
memory allocation failure, even though the NULL buffer was passed,
notably in LibreSSL.

Reported by szzzy.

3 weeks agoSSL: ignored EIO after shutdown with kernel TLS
Vadim Zhestikov [Tue, 29 Sep 2026 16:33:47 +0000 (09:33 -0700)]
SSL: ignored EIO after shutdown with kernel TLS

After SSL shutdown, lingering close reads the socket with recv().  With
kernel TLS receive offload, which OpenSSL enables for TLS 1.3 since
3.2.0, recv() fails with EIO on a record other than application data,
such as the "close notify" alert from the client, and this was logged
at the "alert" level.

Now ngx_ssl_shutdown() marks connections with kernel TLS receive
offload, and EIO on such connections is ignored, so the read ends as
at EOF.

Reported by soukichi on GitHub.

Closes: https://github.com/nginx/nginx/issues/651
3 weeks agoDav: restored the request URI on a destination mapping error.
Vadim Zhestikov [Thu, 17 Sep 2026 17:23:21 +0000 (10:23 -0700)]
Dav: restored the request URI on a destination mapping error.

The COPY and MOVE handler temporarily replaces r->uri with the
destination to map it to a path, restoring it only on success.  When
ngx_http_map_uri_to_path() failed for the destination, the handler
returned without restoring r->uri, leaving it set to the client-supplied
destination.  Later processing that derives a target from the request
URI, such as an error_page with a variable, then resolved against the
destination instead of the request target.

3 weeks agoControl API: log errors from accepted socket setup
Oskar Eichler [Fri, 4 Sep 2026 15:52:07 +0000 (22:52 +0700)]
Control API: log errors from accepted socket setup

Accepted control connections discarded errno when setting close-on-exec,
nonblocking I/O, or signal ownership. The error log identified the failed
fcntl() operation but omitted the operating system reason.

Pass ngx_socket_errno to the three error logs, consistently with listener
setup and inherited socket handling.

3 weeks agoWin32: removed unused winsock extension function pointers
Vadim Zhestikov [Mon, 5 Oct 2026 20:28:14 +0000 (13:28 -0700)]
Win32: removed unused winsock extension function pointers

3 weeks agoWin32: removed the iocp event module
Vadim Zhestikov [Mon, 5 Oct 2026 20:27:47 +0000 (13:27 -0700)]
Win32: removed the iocp event module

The I/O completion ports event method has never been completed: the
module is compiled into Windows builds, but is not documented or
supported.

Prodded by Marek Ludha.

3 weeks agoHTTP/3: avoid undefined behaviour with empty encoder field values
dgprivate [Sat, 29 Aug 2026 05:53:38 +0000 (05:53 +0000)]
HTTP/3: avoid undefined behaviour with empty encoder field values

A zero length field value in encoder stream instructions left the value
data pointer NULL, passed then to ngx_memcpy() in ngx_http_v3_insert().
For the reasons outlined in b0a4d0fb8, it is now set to an empty string.

3 weeks agoVersion bump
Sergey Kandaurov [Thu, 15 Oct 2026 11:46:43 +0000 (15:46 +0400)]
Version bump

5 weeks agonginx-1.31.7-RELEASE release-1.31.7
Roman Arutyunyan [Wed, 30 Sep 2026 14:34:53 +0000 (18:34 +0400)]
nginx-1.31.7-RELEASE

5 weeks agoAvoid post-rewrite URI to path mapping with alias
Roman Arutyunyan [Fri, 10 Jul 2026 16:10:12 +0000 (20:10 +0400)]
Avoid post-rewrite URI to path mapping with alias

Previously, after a "rewrite" had changed the URI, and before a new
location was chosen, the new URI might not match the current location
prefix.  This becomes a problem when the location uses "alias", which
is why normally such inconsistency is detected by checking the
r->valid_location flag.  Meanwhile this flag only handles the
inconsistency when using the "break" directive or parameter.  However
in absence of those, there's still an inconsistency window from URI
change up until the end of the current set of rewrite directives.
URI to path mapping within this window might result in a buffer
overflow if location's prefix was longer than the rewritten URI.

The following example resulted in a buffer overflow with the request
"/foo/1":

location /foo/ {
    alias /bar/;
    rewrite ^/foo/.*$ /x;
    return 200 $request_filename;
}

Alternatively, $request_filename might be used in access log format,
"set", "if", "add_header", etc.

The fix is to reject URI mapping in ngx_http_map_uri_to_path() if the
r->uri_changed flag is set.

5 weeks agoScript: reserved memory overrun protection in ngx_http_script_run()
Roman Arutyunyan [Wed, 29 Jul 2026 12:57:59 +0000 (16:57 +0400)]
Script: reserved memory overrun protection in ngx_http_script_run()

In b76754049 buffer overrun protection in script was introduced.
However in ngx_http_script_run() data could still spill over to the
reserved area.  This had no visible effects except the return value
which could extend beyond the maximum formatted string size.  This
value is however currently unused in the nginx code.

Later in a8289aa69 string length recalculation was implemented to
protect against buffer underwrite.  Considering a possible spillover to
the reserved area, the final string size could become larger than the
allocated buffer size.  This could later result in writing beyond
the buffer boundaries.  Maximum buffer overflow is the size of the
reserved area.

This could affect calculating document root from variables in HTTP
or using access logging in HTTP or Stream.  In the case of access
logging a possible impact is limited by an off-by-one write of a null
byte.

Reported by Matt Suiche of Tolmo Inc.

5 weeks agoSSL: synced all session ticket keys to the worker process
Vadim Zhestikov [Wed, 22 Jul 2026 23:48:37 +0000 (16:48 -0700)]
SSL: synced all session ticket keys to the worker process

The per-worker ticket key mirror is allocated with three slots
(ngx_array_push_n(keys, 3)), matching the shared memory
ticket_keys[3] array and the decrypt callback, which scans all
keys->nelts slots by key name.  Key rotation, however, synced
only two slots from shared memory, leaving the third slot's
name, hmac_key, and aes_key uninitialized.

A ticket whose key name matched the uninitialized slot (which
holds unspecified pool memory, all zero in the best case) could
therefore be HMAC-verified and decrypted with uninitialized key
material, allowing a forged session.

Sync all keys->nelts slots, as ngx_ssl_ticket_keys_cleanup()
already assumes.

Reported by PhiNode Labs.

5 weeks agoHTTP/3: kept the skipped frame length separate from data length
Vadim Zhestikov [Thu, 23 Jul 2026 00:48:55 +0000 (17:48 -0700)]
HTTP/3: kept the skipped frame length separate from data length

ngx_http_v3_parse_data() stored the remaining length of a skipped
(unknown) frame in st->length -- the same field the request body
filter uses for the number of DATA payload bytes to pass on as
request body.  When an unknown frame was split across parser
invocations, the skip was interrupted with st->length holding the
skip remainder; on the next buffer the body filter, which calls
the parser only while st->length == 0, treated that remainder as
request body.

When proxying, this could result in sending unframed bytes, potentially
allowing for bypass of client_max_body_size, which is enforced only on
the DATA path, or an injection.

The fix is to keep unknown frame payload in a separate st->skip counter.

Reported by Hansol Lee of GOTROOT.

5 weeks agoLimited the number of pending operations per request
Vadim Zhestikov [Mon, 17 Aug 2026 16:19:46 +0000 (09:19 -0700)]
Limited the number of pending operations per request

Each pending asynchronous operation holds a reference in
r->main->blocked, an 8-bit field, and the increments were not checked.
With 256 operations pending on a single request the counter wrapped to
zero, after which the request could be freed while those operations
still referenced its pool.  This is the same overflow that 4ec67cf86
addressed for r->main->count, and left unaddressed for r->main->blocked.

Operations beyond the limit are now performed synchronously where a
synchronous path exists, and refused otherwise, so that the counter
cannot overflow.

Reported by cyberlancer.

5 weeks agoUpstream: fixed X-Accel-Redirect handling from cache files.
Maxim Dounin [Mon, 19 Feb 2024 22:23:43 +0000 (01:23 +0300)]
Upstream: fixed X-Accel-Redirect handling from cache files.

The X-Accel-Redirect header might appear in cache files if its handling
is ignored with the "proxy_ignore_headers" directive.  If the cache file
is later served with different settings, ngx_http_upstream_process_headers()
used to call ngx_http_upstream_finalize_request(NGX_DECLINED), which
is not expected to happen before the cleanup handler is installed and
resulted in ngx_http_finalize_request(NGX_DONE) (after 2b032e8df,
nginx 1.7.11), leading to unexpected request counter decrement, "request
count is zero" alerts, and segmentation faults.

Similarly, errors in ngx_http_upstream_process_headers() resulted in
ngx_http_upstream_finalize_request(NGX_HTTP_INTERNAL_SERVER_ERROR) being
called.  This is also not expected to happen before the cleanup handler is
installed, and resulted in ngx_http_finalize_request(NGX_DONE) without
proper request finalization.

Fix is to avoid calling ngx_http_upstream_finalize_request() from
ngx_http_upstream_process_headers(), notably when the cleanup handler
is not yet installed.  Errors are now simply return NGX_ERROR, so the
caller is responsible for proper finalization by calling either
ngx_http_finalize_request() or ngx_http_upstream_finalize_request().
And X-Accel-Redirect handling now does not call
ngx_http_upstream_finalize_request(NGX_DECLINED) if no cleanup handler
is installed.

Reported by Jiří Setnička
(https://mailman.nginx.org/pipermail/nginx-devel/2024-February/HWLYHOO3DDB3XTFT6X3GRMXIEJ3SJRUA.html).

6 weeks agoGeoIP: support for the MaxMind DB (MMDB) databases
Sergey Kandaurov [Tue, 8 Sep 2026 19:56:49 +0000 (19:56 +0000)]
GeoIP: support for the MaxMind DB (MMDB) databases

The MaxMind DB format is now recognized, with the fallback to the
legacy format (reached End-of-Life in May 2022).  Migration requires
switching to MMDB database files:

    geoip_country  /usr/share/GeoIP/GeoLite2-Country.mmdb;
    geoip_city     /usr/share/GeoIP/GeoLite2-City.mmdb;
    geoip_org      /usr/share/GeoIP/GeoLite2-ASN.mmdb;

Either libmaxminddb or libGeoIP is sufficient to build the modules;
configure fails if neither is found.

Notes on the MMDB lookups:

*) $geoip_country_code3 and $geoip_city_country_code3 are converted from
   the alpha-2 codes with a compiled-in ISO 3166-1 table, as the MMDB
   databases provide alpha-2 codes only.

*) $geoip_org looks up "autonomous_system_organization", "isp",
   "organization", and "domain" in turn, to match the legacy ASNum, ISP,
   Org, and Domain database editions.

*) $geoip_area_code has no MMDB counterpart and is never found.

*) $geoip_region and $geoip_region_name come from subdivisions[0], and
   thus may differ in value from the legacy ones.

*) $geoip_dma_code comes from location.metro_code, which is deprecated
   by MaxMind and may be absent.

Co-authored-by: Nitin Swami <n.swami@f5.com>
6 weeks agoUpdated OpenSSL and PCRE used for win32 builds
Sergey Kandaurov [Wed, 30 Sep 2026 13:23:05 +0000 (17:23 +0400)]
Updated OpenSSL and PCRE used for win32 builds

6 weeks agoQUIC: fixed binary upgrade from older versions
Ivan Ovchinnikov [Tue, 29 Sep 2026 21:09:54 +0000 (21:09 +0000)]
QUIC: fixed binary upgrade from older versions

Before 63af971a1 (1.31.7), the NGINX_BPF_MAPS environment variable
was passed to the new binary on binary upgrade whenever the quic_bpf
module was built, even if "quic_bpf" was not enabled, with an empty
value if there were no QUIC BPF socket groups.

Since 63af971a1, such an empty value was treated as inherited maps,
and the new binary refused to start: with the "cannot be disabled
during binary upgrade" error if "quic_bpf" was not enabled, or with
a parsing error otherwise.

The fix is to ignore an empty value, which means there are no maps
to inherit.

6 weeks agoQUIC: support BPF reload and binary upgrade
Sai Krishna Kumar Reddy YADAMAKANTI [Tue, 29 Sep 2026 15:07:24 +0000 (15:07 +0000)]
QUIC: support BPF reload and binary upgrade

The SO_COOKIE dependency is removed.  QUIC BPF dispatching now uses
separate sockets for new and established connections: listener sockets
handle new connections, while per-worker sockets handle established
ones.  Server connection IDs encode a random worker key, which BPF
uses to route established packets directly to the correct worker
socket.  New connections are routed through listen keys using a
dual slot scheme that enables both reload and binary upgrade.

On reload, new workers register new sockets and keys while old workers
continue receiving established connections through their encoded keys.
On binary upgrade, the new master uses the opposite slot, and exiting
masters clear their entries so traffic shifts to the surviving
instance.

Co-authored-by: Roman Arutyunyan <arut@nginx.com>
6 weeks agoQUIC: added BPF packet data fallback
Sai Krishna Kumar Reddy YADAMAKANTI [Tue, 29 Sep 2026 15:04:37 +0000 (15:04 +0000)]
QUIC: added BPF packet data fallback

Use bpf_skb_load_bytes() in the reuseport BPF helper when the required
QUIC header bytes are not available through direct packet access.  This
keeps the direct access fast path while allowing the helper to parse the
flags byte, DCID length byte, and DCID key from non linear skb data.

A similar approach was implemented in [1].

[1] https://git.angie.software/web-server/angie/commit/4b527f5

6 weeks agoHTTP/2: switch to RFC 9218 priorities
Andrew Clayton [Thu, 24 Sep 2026 15:40:33 +0000 (16:40 +0100)]
HTTP/2: switch to RFC 9218 priorities

Advertise SETTINGS_NO_RFC7540_PRIORITIES (0x9) in the initial SETTINGS
frame and order the output by the RFC 9218 effective priority instead of
the RFC 7540 dependency tree, which is removed in the same step.
Placing the switch last keeps it self-contained and easy to revert.

RFC 9218, Section 2.1: a server can send SETTINGS_NO_RFC7540_PRIORITIES
with a value of 1 to indicate that it will ignore RFC 7540 priority
signals.  A received value other than 0 or 1 is a connection error.

Frames are ordered by urgency first, then non-incremental ahead of
incremental, then by stream id, which keeps streams of equal priority
in the order their requests arrived (RFC 8941, Section 4.2).  The same
order is applied to ngx_http_v2_waiting_queue().

The RFC 7540 priority scheme is removed: PRIORITY frames are validated
for framing errors and then ignored, the priority fields of a HEADERS
frame are skipped, and the dependency tree (node parent/children/weight,
the dependencies queue, ngx_http_v2_set_dependency(),
ngx_http_v2_node_children_update() and the per-connection
priority_limit) is gone.  RFC 9113, Sections 5.3.1 and 5.3.2, deprecate
stream prioritization: it proved complex, was implemented unevenly and
widely ignored, and its protocol elements are retained for wire
compatibility only.

With the tree gone, a buffered PRIORITY_UPDATE node no longer needs to
be attached to it, so the set_dependency() call from the buffering path
falls away, leaving the node parked in h2c->closed on its own.

Assisted-by: opencode:claude-opus-4.8
6 weeks agoHTTP/2: merge upstream Priority header for proxied requests
Andrew Clayton [Tue, 22 Sep 2026 00:53:10 +0000 (01:53 +0100)]
HTTP/2: merge upstream Priority header for proxied requests

When nginx proxies a request over HTTP/2 and the upstream returns a
Priority response header, record it as the stream's server priority and
recompute the effective priority by merging it with the client's value
(RFC 9218, Section 8): a parameter present in the response overrides the
client's, a parameter absent leaves it unchanged.  The client and server
inputs are kept separate so a later client PRIORITY_UPDATE does not
discard the server hint.

The merge affects only how this hop schedules the stream; the Priority
header forwarded to the client is left unchanged, so
$upstream_http_priority continues to report what the origin sent.

Assisted-by: opencode:claude-opus-4.8
6 weeks agoHTTP/2: parse Priority request header
Andrew Clayton [Tue, 22 Sep 2026 00:52:41 +0000 (01:52 +0100)]
HTTP/2: parse Priority request header

Parse the RFC 9218 Priority request header, an RFC 8941 Structured
Fields Dictionary such as "u=3, i".

The header lines are collected during header block processing and, once
the block is complete, combined into a single value and parsed once in
ngx_http_v2_run_request(), as RFC 8941, Section 4.2, requires all field
lines of the same field to be combined before parsing.  This mirrors how
cookies are handled.  The header is still passed through to the request
so it stays visible to variables and proxying.

A malformed field is ignored, leaving the defaults.  A PRIORITY_UPDATE
frame overrides the header (RFC 9218, Section 7): if a frame has already
been applied to the stream the header is not consulted.

Assisted-by: opencode:claude-opus-4.8
6 weeks agoHTTP/2: handle PRIORITY_UPDATE frames
Andrew Clayton [Wed, 23 Sep 2026 20:17:33 +0000 (21:17 +0100)]
HTTP/2: handle PRIORITY_UPDATE frames

Implement the RFC 9218 PRIORITY_UPDATE frame (type 0x10).  The frame is
sent on stream 0 and carries a prioritized stream id and a Priority
Field Value; it is validated for framing errors and dispatched from
ngx_http_v2_state_head().

A PRIORITY_UPDATE conveys a complete set of parameters (RFC 9218,
Section 7): omitted parameters reset to their defaults, so the value
replaces any earlier signal.  A frame for a stream that already exists
is applied at once.  A frame for a not-yet-created stream is buffered on
its node until the HEADERS frame arrives; the node is parked in
h2c->closed and, while the RFC 7540 tree is still present, attached to
the root as is done for a PRIORITY frame with a zero dependency.  The
number of buffered signals is bounded by the node reuse budget.

A malformed value is logged and ignored, leaving the current priority
untouched.  A value that does not fit the state buffer while the frame
is fragmented is skipped.

The signals are only collected here; the scheduler still uses the
RFC 7540 dependency tree until the switch to RFC 9218.

Assisted-by: opencode:claude-opus-4.8
6 weeks agoAdd RFC 9218 priority types and parser
Andrew Clayton [Wed, 23 Sep 2026 20:09:36 +0000 (21:09 +0100)]
Add RFC 9218 priority types and parser

Implement a strict RFC 8941 Structured Fields Dictionary parser for the
RFC 9218 Extensible Prioritization Scheme, shared by HTTP/2 (and, later,
HTTP/3).

New files:
- ngx_http_priority.h: the ngx_http_priority_t and
  ngx_http_priority_state_t types and the parse/state API.
- ngx_http_priority.c: the parser plus ngx_http_priority_state_init()
  and ngx_http_priority_state_update() (client/server merge).

The field is parsed strictly: a syntax error fails the whole field
(RFC 8941, Section 4.2, treats it as absent), and only on a successful
parse are the RFC 9218, Section 4, rules applied, ignoring unknown
members, out-of-range urgency and members of an unexpected type.  On
error the caller keeps any previously signalled priority.  The parser
bounds the number of members, inner-list items and parameters, and the
length of individual strings, tokens and byte sequences, that it will
accept.

The sources are built only with HTTP/2 (for now), alongside the Huffman
sources, rather than unconditionally into the core HTTP module.

Assisted-by: opencode:claude-opus-4.8
6 weeks agoQUIC: fixed frame threshold with a small stream buffer size
Sourav Bhowmik [Wed, 23 Sep 2026 18:31:48 +0000 (11:31 -0700)]
QUIC: fixed frame threshold with a small stream buffer size

Since 2fb32ff (1.27.5), the connection frame threshold degraded to a
few or zero frames when using a small stream buffer.  The previously
hardcoded minimum of 10000 frames is now used.

6 weeks agoRejected zero size in buffer-size directives
Sourav Bhowmik [Thu, 13 Aug 2026 12:40:29 +0000 (05:40 -0700)]
Rejected zero size in buffer-size directives

When set to zero, this resulted in a buffer with no room to read into.
As there is no meaningful interpretation of a zero-sized buffer, such
configuration is explicitly rejected.

Reported by kh-lee

6 weeks agoSSL: avoid matching IP addresses in dNSName and commonName
Eugene Grebenschikov [Mon, 21 Sep 2026 20:32:36 +0000 (13:32 -0700)]
SSL: avoid matching IP addresses in dNSName and commonName

OpenSSL 1.0.2+ validates IP addresses only against iPAddress
subjectAltName entries via X509_check_ip().  For older OpenSSL
versions, equivalent validation is now performed.

Note that dNSName entries are still logged when checking an IP
address, they are not used for matching.

Co-authored-by: Sergey Kandaurov <pluknet@nginx.com>
6 weeks agoSSL: support for iPAddress subjectAltName in certificates.
Maxim Dounin [Thu, 21 Aug 2025 01:41:27 +0000 (04:41 +0300)]
SSL: support for iPAddress subjectAltName in certificates.

Known public services with iPAddress subject altnames include 1.1.1.1
and 8.8.8.8.  IP address certificates from Let's Encrypt are expected
to be available soon:

https://letsencrypt.org/2025/07/01/issuing-our-first-ip-address-certificate

Origin: <https://freenginx.org/hg/nginx/rev/5e23335edf67>
Co-authored-by: Eugene Grebenschikov <e.grebenshchikov@f5.com>
Co-authored-by: Sergey Kandaurov <pluknet@nginx.com>
6 weeks agoSSL: fixed subjectAltName and commonName debug logging.
Maxim Dounin [Thu, 21 Aug 2025 01:40:59 +0000 (04:40 +0300)]
SSL: fixed subjectAltName and commonName debug logging.

Previously, ASN1_STRING_length() was used as a length for "%*s" format
specifier, which is wrong, since string length is expected to be "size_t",
and ASN1_STRING_length() returns "int".

Origin: <https://freenginx.org/hg/nginx/rev/a540fac7e04a>
Signed-off-by: Eugene Grebenschikov <e.grebenshchikov@f5.com>
6 weeks agoSSL: avoid writing to a connection with a failed read
Sergey Kandaurov [Mon, 14 Sep 2026 13:34:42 +0000 (13:34 +0000)]
SSL: avoid writing to a connection with a failed read

It is possible to receive application data together with socket close.
In this case, SSL_read() may return SSL_ERROR_SYSCALL with ECONNRESET,
specifically after OpenSSL sent TLSv1.3 tickets on a closed connection.

Before OpenSSL 4.0, a subsequent SSL_write() returned SSL_ERROR_SYSCALL
with EPIPE in this case.  The behaviour was changed to remember the
error state and handle such a call as a protocol error, see for details
https://github.com/openssl/openssl/issues/30631.  This makes SSL_write()
return SSL_ERROR_SSL with the empty error queue, which results in
"[crit] ... SSL_write() failed" errors, as caught by ssl_stapling.t.

The fix is to check the result of the last read stored in c->ssl->last,
to avoid calling SSL_write() after a failed read.  For consistency, the
check is added to ngx_ssl_sendfile(): SSL_sendfile() resets the error
state the same way SSL_write() does, though it does not seem to be
reachable in http.

Based on a patch by Maxim Dounin.

Signed-off-by: Sergey Kandaurov <pluknet@nginx.com>
Origin: <https://freenginx.org/hg/nginx/rev/ff5becaf5444>

6 weeks agoSSL: clarified clean shutdown condition
Maxim Dounin [Mon, 14 Sep 2026 13:34:20 +0000 (13:34 +0000)]
SSL: clarified clean shutdown condition

OpenSSL up to 3.0, when a TCP connection is closed by the peer, returns
SSL_ERROR_SYSCALL without an error queue and with errno set to 0.  Since
OpenSSL 3.0 with SSL_OP_IGNORE_UNEXPECTED_EOF, which nginx sets, this is
reported as SSL_ERROR_ZERO_RETURN instead.

Closing a connection without the close_notify alert is incorrect, yet
common enough in the real world to be handled as a non-error condition.
Truncation attacks are expected to be prevented at the protocol level;
notably, they are not possible for HTTP/1.x requests at all, and only
possible for HTTP/1.x responses if neither Content-Length nor chunked
transfer encoding is used.

Previously, "ERR_peek_error() == 0" was used to detect this, which is
too broad: it also matches TCP-level errors, such as ECONNRESET, which
are better reported as errors, the way the plain TCP code does it in
ngx_unix_recv().

Now only a clean TCP close is treated as a clean connection close.  Most
notably, connection resets now result in "SSL_read() failed" errors.

This change is a modified version of a patch by Maxim Dounin.  The
modifications include resolved conflicts and the refined commit log.

Signed-off-by: Sergey Kandaurov <pluknet@nginx.com>
Origin: <https://freenginx.org/hg/nginx/rev/4c0b66b5046f>

8 weeks agoVersion bump
Sergey Kandaurov [Wed, 16 Sep 2026 12:11:52 +0000 (16:11 +0400)]
Version bump

8 weeks agoDav: destination validation for COPY and MOVE with "alias".
Maxim Dounin [Fri, 11 Sep 2026 15:18:36 +0000 (08:18 -0700)]
Dav: destination validation for COPY and MOVE with "alias".

If COPY or MOVE methods are enabled, the DAV module assumes that it is
configured for the whole server, and does not try validate that the
destination URI is within the particular location.  This, however, does
not work well if it is in fact configured in a non-root location, and
this location uses the "alias" directive, such as in the following
configuration:

    location /prefix/ {
        dav_methods COPY;
        alias /foo/;
    }

In particular, if the destination URI is shorter than the aliased
location prefix, calling ngx_http_map_uri_to_path() with such
destination URI used to result in segmentation faults (9739e755b).  And
if the destination URI is longer than the aliased location prefix, but
does not match it, calling ngx_http_map_uri_to_path() resulted in
unexpected path values, including ones above the "alias" directory
specified.

The fix is to check destination URI prefix if "alias" is used, similarly
to what we do with "try_files".  Additionally, the
ngx_http_map_uri_to_path() function was updated with additional sanity
checking to prevent similar issues.

This change is a modified version of a patch by Maxim Dounin.  The
modifications include skipping the prefix check if the URI was
rewritten, which preserves the "alias" diagnostics of
ngx_http_map_uri_to_path().

Signed-off-by: Vadim Zhestikov <v.zhestikov@f5.com>
Origin: <https://freenginx.org/hg/nginx/rev/aae28b083279>

8 weeks agonginx-1.31.6-RELEASE release-1.31.6
Sergey Kandaurov [Tue, 15 Sep 2026 11:28:07 +0000 (11:28 +0000)]
nginx-1.31.6-RELEASE

8 weeks agoQUIC: ignore the QUIC extension received in TLS handshake
Sergey Kandaurov [Thu, 10 Sep 2026 14:38:31 +0000 (18:38 +0400)]
QUIC: ignore the QUIC extension received in TLS handshake

Instead of failing the handshake, it is now accepted and ignored like
any other unknown extension.  Unlike stated in RFC 9001, Section 8.2,
this represents less strict behaviour following RFC 8446, Section 4.2.

8 weeks agoQUIC: registering the compat extension in all SSL contexts
Sergey Kandaurov [Tue, 8 Sep 2026 19:56:38 +0000 (19:56 +0000)]
QUIC: registering the compat extension in all SSL contexts

With the OpenSSL compatibility layer, the transport parameters custom
TLS extension used to be registered only in SSL contexts of virtual
servers reachable over QUIC.

The ClientHello callback introduced in 0373fe5d9 (1.29.2) is called
by OpenSSL between collecting and parsing extensions, so the custom
extensions may not match the expected number if the SSL context was
replaced with SSL_set_SSL_CTX().

The fix is to register the extension in all SSL contexts, including
those that cannot be reached over QUIC, so that the array bounds are
preserved; the compatibility layer as a whole is initialized only
if the configuration has QUIC listeners.  The keylog callback,
meaningful for QUIC connections, is kept on QUIC addresses.

Reported by Banny Liao.

2 months agoGeo: check binary base CRC32 before relocation
Sergey Kandaurov [Mon, 7 Sep 2026 15:47:51 +0000 (19:47 +0400)]
Geo: check binary base CRC32 before relocation

This provides safe pointer handling in the event of a corrupted file.

2 months agoControl API: fixed socket inheritance on binary upgrade
Sergey Kandaurov [Thu, 10 Sep 2026 21:07:12 +0000 (21:07 +0000)]
Control API: fixed socket inheritance on binary upgrade

The environment may be replaced while parsing configuration, as it
happens with the perl module, which calls ngx_set_environment() when
creating an interpreter.  As a result, the control socket was not
inherited on binary upgrade.

The variable is now read before ngx_init_cycle(), similarly to
inherited listening sockets.

2 months agoHandle nested location lookup error
Roman Arutyunyan [Wed, 9 Sep 2026 14:23:22 +0000 (18:23 +0400)]
Handle nested location lookup error

Previously, when looking up a nested location after a prefix location
match, the nested regex or predicate match error could be ignored if
more regex or predicate locations were configured at the current level.
Now such error leads to request finalization.

2 months agoHandle predicate location variable error
Roman Arutyunyan [Wed, 9 Sep 2026 13:32:34 +0000 (17:32 +0400)]
Handle predicate location variable error

Previously, the error was ignored and the predicate was treated as
false.  Now the error leads to the request finalization.

2 months agoRemoved non-existing support link in the man page
Sergey Kandaurov [Fri, 4 Sep 2026 12:34:57 +0000 (16:34 +0400)]
Removed non-existing support link in the man page

2 months agoAdded -l option to the man page
Sergey Kandaurov [Fri, 4 Sep 2026 12:10:24 +0000 (16:10 +0400)]
Added -l option to the man page

Fixes 4bc459a15.

2 months agoVersion bump
Sergey Kandaurov [Mon, 7 Sep 2026 16:00:22 +0000 (20:00 +0400)]
Version bump

2 months agonginx-1.31.5-RELEASE release-1.31.5
Roman Arutyunyan [Fri, 28 Aug 2026 11:52:47 +0000 (15:52 +0400)]
nginx-1.31.5-RELEASE

2 months agoUpdated OpenSSL and PCRE used for win32 builds
Roman Arutyunyan [Tue, 1 Sep 2026 17:51:10 +0000 (21:51 +0400)]
Updated OpenSSL and PCRE used for win32 builds

2 months agoControl API: in memory config dump.
Ava Hahn [Thu, 5 Feb 2026 22:25:19 +0000 (22:25 +0000)]
Control API: in memory config dump.

The /control/config endpoint returns the currently parsed and running
configuration on GET request.

Example:

$ curl 127.0.0.1:1234/1/control/config | jq
[
  {
    "name": "/path/to/nginx.conf",
    "content": "..."
  },
  {
    "name": "/path/to/included.conf",
    "content": "..."
  }
]

Co-authored-by: Pavel Pautov <p.pautov@f5.com>
2 months agoControl API: reload support.
Ava Hahn [Tue, 30 Dec 2025 19:35:18 +0000 (19:35 +0000)]
Control API: reload support.

A new /control/config endpoint provides configuration reload function
with feedback returned to the user on the outcome.

Example:

$ curl 127.0.0.1:1234/1/control/config -X PATCH -v | jq
< HTTP/1.1 200 OK
< ...
<
{
  "logs": []
}

$ curl 127.0.0.1:1234/1/control/config -X PATCH -v | jq
< HTTP/1.1 422 Unprocessable Entity
< ...
<
{
  "logs": [
  "...: invalid number of arguments in \"listen\" directive"
  ]
}

Co-authored-by: Pavel Pautov <p.pautov@f5.com>
2 months agoControl API.
Ava Hahn [Wed, 25 Mar 2026 01:08:25 +0000 (01:08 +0000)]
Control API.

A new nginx option -l specifies control socket listen address.
The socket is providing an HTTP/1 REST API for retrieving information
about running nginx instance.

Example:

$ nginx -l 127.0.0.1:1234

$ curl 127.0.0.1:1234/1/control/processes | jq
[
  {
    "pid": 41536,
    "name": "worker process",
    "exiting": false
  }
]

Co-authored-by: Roman Arutyunyan <arut@nginx.com>
Co-authored-by: Pavel Pautov <p.pautov@f5.com>
Co-authored-by: Dmitry Plotnikov <d.plotnikov@f5.com>
Co-authored-by: Sergey Kandaurov <pluknet@nginx.com>
Co-authored-by: Ivan Ovchinnikov <i.ovchinnikov@f5.com>
2 months agoJSON: fixed overflow detection in length calculation
Dmitry Plotnikov [Tue, 18 Aug 2026 01:40:08 +0000 (01:40 +0000)]
JSON: fixed overflow detection in length calculation

2 months agoPredicate locations
Roman Arutyunyan [Sun, 29 Mar 2026 06:47:49 +0000 (10:47 +0400)]
Predicate locations

A predicate location name starts with '$' and is interpreted as a
string evaluated at runtime, and its value is used to route the
request into the location.  A predicate location matches if the
string evaluates to a non-empty value not equal to "0".  At each
nesting level, the first matching predicate location in the
configuration order is chosen.  Predicate locations are matched
after prefix and regex locations.  They are not matched if an exact
or a regex location matched, or if the longest matching prefix location
has the "^~" modifier.  Predicate locations can be nested inside
other location types and can contain nested locations of their own.

Example:

map $arg_foo $pred {
    bar  1;
    qux  1;
}

location $pred {
    root html;
}

2 months agoEvent pipe: do not free buffers still used by the downstream
Ivan Ovchinnikov [Fri, 21 Aug 2026 20:48:15 +0000 (20:48 +0000)]
Event pipe: do not free buffers still used by the downstream

When a body filter returned an error, ngx_event_pipe_drain_chains()
returned all buffers to p->free_raw_bufs, including those in p->busy,
which are still owned by the downstream. If upstream EOF was detected
in the same ngx_event_pipe() pass, ngx_event_pipe_read_upstream() then
freed them while still referenced. With HTTP/2 only the stream's fake
connection is marked on error, so ngx_http_v2_send_output_queue() kept
sending DATA frames pointing at the freed buffers, a use-after-free.

Fixed by keeping the p->busy chains intact, the buffers are freed with
the request pool.  This also stops the pipe from reusing them for new
upstream reads, which previously could overwrite response body data
still queued for the client.  Additionally, the pipe no longer treats
a downstream it has given up on as merely blocked, so the loop is
still guaranteed to terminate.

Co-authored-by: Roman Arutyunyan <arut@nginx.com>
2 months agoSlice filter: overflow protection in slice range requests
Vadim Zhestikov [Tue, 11 Aug 2026 21:06:19 +0000 (14:06 -0700)]
Slice filter: overflow protection in slice range requests

When the byte range is passed in the client Range header, the range
start is accepted up to NGX_MAX_OFF_T_VALUE, while
ngx_http_slice_range_variable() adds the slice size to it when
formatting the slice end.  With start values close to the maximum
this overflowed.

Now such range starts are ignored, similarly to other ranges not
handled by ngx_http_slice_get_start().

2 months agoQUIC: rejected CRYPTO frames received in 1-RTT packets
Vadim Zhestikov [Wed, 12 Aug 2026 19:41:54 +0000 (12:41 -0700)]
QUIC: rejected CRYPTO frames received in 1-RTT packets

If a CRYPTO frame was received after the handshake, ngx_quic_handshake()
ran the handshake completion for the second time.  With the check added
in 6f8c520f4, this is limited to short header packets.

Since a client has nothing to send in a CRYPTO frame once the handshake
is complete, such frames are now rejected with the "unexpected_message"
connection error, as does TLS 1.3 for handshake messages received out of
order, and QUIC requires for KeyUpdate.

2 months agoMemcached: respect the end marker in the maximum supported length
Vadim Zhestikov [Tue, 11 Aug 2026 18:06:28 +0000 (11:06 -0700)]
Memcached: respect the end marker in the maximum supported length

The length in the "VALUE" line was accepted up to NGX_MAX_OFF_T_VALUE,
while ngx_http_memcached_filter_init() adds the size of the end marker
to it.  With lengths close to the maximum this overflowed u->length.

Now such lengths are rejected, similarly to other invalid lengths.

2 months agoCore: delete accept timer on worker shutdown
Roman Arutyunyan [Thu, 20 Aug 2026 12:53:42 +0000 (16:53 +0400)]
Core: delete accept timer on worker shutdown

Previously, when the worker file descriptor table was full, a listen
connection might be disabled and a timeout might be set for re-enabling
it.  If during this period the worker received the NGX_CMD_QUIT signal,
the accept connection would be recycled, but the timer would remain set.
On timer expiration, an attempt to accept a new connection would result
in "accept4() failed (9: Bad file descriptor)" alert because c->fd was
reset to -1.

Fix is to delete accept timer when closing listen connections.

2 months agoCore: make channel file descriptor errors non-fatal
Roman Arutyunyan [Tue, 18 Aug 2026 16:58:42 +0000 (20:58 +0400)]
Core: make channel file descriptor errors non-fatal

If a worker process' file descriptor table is full, recvmsg() is not
able to read out the channel fd sent from the master.  This results in
different behavior on different platforms.

On Linux, recvmsg() succeeds, returns the payload and drops the fd.
On BSD systems, the first recvmsg() call fails with EMSGSIZE/EMFILE,
but the next call succeeds and returns the payload without the fd.
On Solaris, recvmsg() fails with EMFILE and drops both the payload
and the fd.

Previously, all of these paths resulted in fatal errors.  The worker
channel was closed and the worker was no longer capable of receiving
messages from the master.  In particular, the NGX_CMD_QUIT command
could not be delivered anymore.  As a result, the worker never exited
after nginx reload and kept running and accepting new connections
forever until killed by a signal.

Fix is to consider those errors non-fatal.  An additional check is
added to the NGX_CMD_CLOSE_CHANNEL handler to make sure the worker
has received a file descriptor for this entry before. Also, the
MSG_CTRUNC check is removed since a proper ancillary data size
validation is now implemented.

2 months agoAdded the json parser module
Roman Semenov [Wed, 12 Aug 2026 16:52:08 +0000 (09:52 -0700)]
Added the json parser module

Added the http_json_module with a json_set directive that
extracts values from JSON stored in nginx variables and exposes them
as new nginx variables.  Parsed results are cached per request, so
multiple json_set directives using the same source expression trigger
only one parse.  The directive is available in the http main context.

Example usage:

    http {
        json_set $user_name $arg_data user.name;
        json_set $user_age  $arg_data user.age;
        json_set $tag0      $arg_data tags[0];

        server {
            listen 8080;

            location / {
                return 200 "name=$user_name age=$user_age "
                           "tag0=$tag0\n";
            }
        }

        # quoted keys for names containing '.', '[', ']', or that
        # are empty; the whole argument is single-quoted so that the
        # inner '"' reach the path parser intact
        json_set $host      $arg_data '["a.b.com"]';
        json_set $nested    $arg_data 'obj["a.b"].c[2]';
        json_set $quoted    $arg_data 'obj["a\\"b"]';
    }

Co-authored-by: Dmitry Volyntsev <d.volyntsev@f5.com>
2 months agoCore: allowed top-level scalars in the JSON parser
Roman Semenov [Wed, 12 Aug 2026 16:42:28 +0000 (09:42 -0700)]
Core: allowed top-level scalars in the JSON parser

RFC 8259 permits any JSON value as a complete document, not just
objects and arrays.  The start state now accepts strings, numbers,
and the true/false/null literals as well.  A bare top-level number,
having no closing delimiter, is emitted when input ends.

2 months agoCore: added json parser
Roman Semenov [Wed, 12 Aug 2026 16:40:34 +0000 (09:40 -0700)]
Core: added json parser

An event-driven JSON parser implementing the grammar of RFC 8259.
The full grammar is recognized: objects, arrays, strings with \uXXXX
escapes (including UTF-16 surrogate pairs), numbers, and the
true/false/null literals.  Tokens are reported to a caller-supplied
handler, with nesting bounded by a configurable maximum depth.

Based on previous work by Maxim Dounin.

Co-authored-by: Dmitry Volyntsev <d.volyntsev@f5.com>
2 months agoCore: added JSON unescape functionality
Roman Semenov [Wed, 12 Aug 2026 16:39:11 +0000 (09:39 -0700)]
Core: added JSON unescape functionality

Decodes JSON string escape sequences in place as defined by
RFC 8259, Section 7: the two-character escapes and \uXXXX,
with non-BMP code points encoded as UTF-16 surrogate pairs
and emitted as UTF-8.

2 months agoAdded client_body_early_read directive
Roman Arutyunyan [Wed, 8 Apr 2026 17:07:15 +0000 (21:07 +0400)]
Added client_body_early_read directive

The directive accepts predicates.  When enabled, request body is read
immediately after the headers and before choosing a location.
Body read settings from the server block are used in this case.

Example:

http {

    map $http_content_type $is_json {
        application/json 1;
    }

    server {
        listen 8000;

        client_body_early_read $is_json;
        client_max_body_size 256;
        client_body_buffer_size 256;

        return 200 $request_body;
    }
}

2 months agoUwsgi: support for multibyte parameter name lengths.
Vadim Zhestikov [Wed, 19 Aug 2026 19:41:08 +0000 (12:41 -0700)]
Uwsgi: support for multibyte parameter name lengths.

The name length of a configured parameter was truncated to one byte
before the per-parameter length field was written, so that a
uwsgi_param name of 256 bytes or longer was encoded with a wrong
length while the name itself was copied in full.  The resulting request
was malformed, and upstream servers responded by closing the connection.

While long names are barely used in practice, it is easy to support
them.  The length is now properly encoded up to the allowed length.

2 months agoFastCGI: support for multibyte parameter name lengths.
Vadim Zhestikov [Wed, 19 Aug 2026 19:41:08 +0000 (12:41 -0700)]
FastCGI: support for multibyte parameter name lengths.

The name length of a configured parameter was truncated to one byte
before the per-parameter length field was written, so that a
fastcgi_param name of 128 bytes or longer was encoded with a wrong
length while the name itself was copied in full.  The resulting request
was malformed, and upstream servers responded by closing the connection.

While long names are barely used in practice, it is easy to support
them.  The length is now properly encoded up to the allowed length.

2 months agoVersion bump
Vadim Zhestikov [Thu, 20 Aug 2026 02:17:38 +0000 (19:17 -0700)]
Version bump

3 months agonginx-1.31.4-RELEASE release-1.31.4
Sergey Kandaurov [Tue, 11 Aug 2026 19:49:38 +0000 (23:49 +0400)]
nginx-1.31.4-RELEASE

3 months agoMail: PROXY protocol v2 support to backends
Sergey Kandaurov [Mon, 10 Aug 2026 16:53:52 +0000 (20:53 +0400)]
Mail: PROXY protocol v2 support to backends

Version 1 remains the default.  This may be changed with the
"proxy_protocol v2;" directive.

3 months agoStream: PROXY protocol v2 support to backends
Sergey Kandaurov [Mon, 10 Aug 2026 16:53:44 +0000 (20:53 +0400)]
Stream: PROXY protocol v2 support to backends

Version 1 remains the default.  This may be changed with the
"proxy_protocol v2;" directive.

3 months agoCore: PROXY protocol v2 write support
Sergey Kandaurov [Mon, 10 Aug 2026 14:10:44 +0000 (18:10 +0400)]
Core: PROXY protocol v2 write support

Add ngx_proxy_protocol_v2_write() that writes the fixed 16-byte
PPv2 header and address block, and appends a list of TLVs.

An address block is written using IPv4/IPv6 mixed-family promotion:
the highest family present on either side (IPv6 > IPv4) is used for
the header, and the other address is promoted into it.  Both v4-mapped
addresses are demoted to IPv4.

When PROXY protocol v2 is configured and the downstream connection
is SSL, standard PROXY protocol v2 TLVs are populated:

    PP2_TYPE_ALPN              from SSL_get0_alpn_selected()
    PP2_TYPE_AUTHORITY         from SSL_get_servername()
    PP2_SUBTYPE_SSL_VERSION    from SSL_get_version()
    PP2_SUBTYPE_SSL_CIPHER     from SSL_get_cipher_name()
    PP2_SUBTYPE_SSL_CN         from client cert subject CN
    PP2_SUBTYPE_SSL_SIG_ALG    from server certificate
    PP2_SUBTYPE_SSL_KEY_ALG    from server certificate

The CRC32c TLV is written last and covers the entire header in place.

Co-authored-by: Vadim Zhestikov <v.zhestikov@f5.com>