Commit graph

8713 commits

Author SHA1 Message Date
Roman Arutyunyan
005f9f5d4d Handle predicate location variable error
Some checks are pending
buildbot / buildbot (push) Waiting to run
Previously, the error was ignored and the predicate was treated as
false.  Now the error leads to the request finalization.
2026-09-09 19:37:03 +04:00
Sergey Kandaurov
5c812c034e Removed non-existing support link in the man page
Some checks failed
buildbot / buildbot (push) Has been cancelled
2026-09-07 20:08:48 +04:00
Sergey Kandaurov
76a8d9f041 Added -l option to the man page
Fixes 4bc459a15.
2026-09-07 20:08:48 +04:00
Sergey Kandaurov
69dcf98c1c Version bump 2026-09-07 20:08:48 +04:00
Roman Arutyunyan
231a60ee3e nginx-1.31.5-RELEASE
Some checks failed
buildbot / buildbot (push) Has been cancelled
2026-09-02 15:17:13 +04:00
Roman Arutyunyan
0356f3d2c9 Updated OpenSSL and PCRE used for win32 builds
Some checks are pending
buildbot / buildbot (push) Waiting to run
2026-09-01 22:22:29 +04:00
Ava Hahn
1c1c17c104 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>
2026-09-01 10:34:56 -07:00
Ava Hahn
74133fba7c 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>
2026-09-01 10:34:56 -07:00
Ava Hahn
4bc459a15c 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>
2026-09-01 10:34:56 -07:00
Dmitry Plotnikov
032e181dad JSON: fixed overflow detection in length calculation
Some checks are pending
buildbot / buildbot (push) Waiting to run
2026-08-31 14:22:50 -07:00
Roman Arutyunyan
5f54125dde Predicate locations
Some checks failed
buildbot / buildbot (push) Has been cancelled
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;
}
2026-08-26 15:14:20 +04:00
Ivan Ovchinnikov
8fa349cef4 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>
2026-08-25 19:16:57 -07:00
Vadim Zhestikov
028c0fab84 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().
2026-08-25 14:36:54 -07:00
Vadim Zhestikov
9c30a4debc 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.
2026-08-25 14:36:09 -07:00
Vadim Zhestikov
9b76c21b01 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.
2026-08-25 14:35:31 -07:00
Roman Arutyunyan
76364bdd29 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.
2026-08-25 21:33:21 +04:00
Roman Arutyunyan
ee03ec42c4 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.
2026-08-25 21:33:21 +04:00
Roman Semenov
a1f4a61769 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>
2026-08-24 11:08:31 -07:00
Roman Semenov
55db1978e2 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.
2026-08-24 11:08:31 -07:00
Roman Semenov
746609903e 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>
2026-08-24 11:08:31 -07:00
Roman Semenov
bc1cb5686b 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.
2026-08-24 11:08:31 -07:00
Roman Arutyunyan
3f6f7824d4 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;
    }
}
2026-08-21 17:00:43 +04:00
Vadim Zhestikov
bc7c3424c3 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.
2026-08-19 19:24:25 -07:00
Vadim Zhestikov
6ae731d074 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.
2026-08-19 19:24:25 -07:00
Vadim Zhestikov
e3cffe3044 Version bump 2026-08-19 19:24:25 -07:00
Sergey Kandaurov
39ffdd8ece nginx-1.31.4-RELEASE 2026-08-12 00:07:37 +04:00
Sergey Kandaurov
8d9666701d Mail: PROXY protocol v2 support to backends
Version 1 remains the default.  This may be changed with the
"proxy_protocol v2;" directive.
2026-08-11 23:39:53 +04:00
Sergey Kandaurov
11d11b5f0d Stream: PROXY protocol v2 support to backends
Version 1 remains the default.  This may be changed with the
"proxy_protocol v2;" directive.
2026-08-11 23:39:53 +04:00
Sergey Kandaurov
cfb1d17326 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>
2026-08-11 23:39:53 +04:00
Sergey Kandaurov
49181eb14a Core: PROXY protocol v2 macros 2026-08-11 23:39:53 +04:00
Vadim Zhestikov
05549db082 Core: CRC32c (Castagnoli93) implementation
This change implements the Castagnoli polynomial code 0x11EDC6F41,
as described in RFC4960, Appendix B.  It will be used to calculate
PROXY protocol v2 CRC32c checksums.
2026-08-11 23:39:53 +04:00
Dmitry Plotnikov
7ac8bdf5bf Upstream: reserved padding in state structures 2026-08-11 11:09:34 -07:00
Vadim Zhestikov
0826449c59 Upstream: fixed MSVC compilation after dea68dbf12. 2026-08-10 19:18:08 -07:00
Henry Yuan
836704c6e8 Core: added data model and JSON serialization libraries.
Co-authored-by: Valentin Bartenev <vbart@nginx.com>
Co-authored-by: Ruslan Ermilov <ru@nginx.com>
Co-authored-by: Vladimir Homutov <vl@nginx.com>
Co-authored-by: Evgeny Shirykalov <e.shirykalov@f5.com>
Co-authored-by: Dmitry Plotnikov <d.plotnikov@f5.com>
2026-08-10 11:23:36 -07:00
felix h
3c65267a0c Upstream: reject zero WINDOW_UPDATE increments
The HTTP/2 proxy and gRPC upstream clients accepted WINDOW_UPDATE
frames with a zero flow-control window increment.  RFC 9113 requires
such frames to be handled as PROTOCOL_ERROR at stream or connection
scope.

Reject these frames as invalid upstream responses.
2026-08-10 15:54:23 +05:30
Roman Arutyunyan
dea68dbf12 Upstream: special handling of the "Host" header in proxy and gRPC
HTTP/2 and gRPC requests are now always sent with the ":authority"
pseudo-header, while the "Host" header is no longer passed.
Where a host value is set explicitly with "proxy_set_header Host"
or "grpc_set_header Host", that value is conveyed in ":authority".
As per RFC 9113, Section 8.3.1, clients and intermediaries MUST
generate an ":authority" pseudo-header to convey authority information.

For HTTP/1.1, HTTP/2 and gRPC, if the explicit value is empty, then
the value of $proxy_host is used instead.  As per RFC 9110, Sections
4.2.1 and 4.2.2, the "http" and "https" URI schemes MUST contain a
non-empty host identifier.  The change enforces this rule by
introducing a default.

Closes: https://github.com/nginx/nginx/issues/1426
2026-08-07 18:54:23 +04:00
Sergey Kandaurov
e419e28c98 Fixed overflow detection in chunked parser
This was broken in f405ef11f (1.29.4).

Reported by Matt Suiche, Tolmo Inc.
2026-08-06 22:19:11 +04:00
Vinay Kumar Tokala
f340e7885a gRPC: narrowed special handling of "trailer only" responses
Previously, the response length was explicitly set to zero if the
initial HEADERS frame was seen with the END_STREAM flag.  This was
meant to properly pass responses in the Trailers-Only format as
introduced in 6559a42013.  This handling was too broad though,
passing incomplete responses that carry a non-zero Content-Length
to the client as if they were complete and empty.

Now such responses are caught by the existing checks later on and
are passed as incomplete, similarly to how this is handled elsewhere.
For instance, on HTTP/2 client connections this now results in proper
signalling, an incomplete stream followed by stream reset.
2026-08-05 09:14:23 +05:30
Aleksei Bavshin
4b90ec7692 Script: improved compatibility of complex value codes
Some checks failed
buildbot / buildbot (push) Has been cancelled
In a8289aa69c, we introduced a new code to finalize the evaluation of
a complex value, deferring the stack update to this new code.  However,
the change inadvertently broke compatibility with several third-party
modules that were reusing ngx_http_script_complex_value_code.

This change relegates omitted ngx_http_script_complex_value_end_code
from crash to a potential read of uninitialized bytes at the end of the
allocated buffer.
2026-07-29 12:29:23 -07:00
Roman Arutyunyan
03baa844a9 QUIC: log RESET_STREAM final size as a decimal number
Previously, it was logged as a hexadecimal number.
2026-07-29 20:14:43 +04:00
Roman Arutyunyan
269cdf7806 QUIC: always validate stream final size
As per RFC 9000, Section 4.5:

Once a final size for a stream is known, it cannot change. If a
RESET_STREAM or STREAM frame is received indicating a change in the
final size for the stream, an endpoint SHOULD respond with an error of
type FINAL_SIZE_ERROR.  A receiver SHOULD treat receipt of data at or
beyond the final size as an error of type FINAL_SIZE_ERROR, even after
a stream is closed.

Previously, the stream final size was validated only after other checks
that could return earlier and skip validation: the receive state check
and, for STREAM frames, the check for data below the current receive
offset.  As a result, a STREAM or RESET_STREAM frame carrying a final
size error was silently ignored once the receiving part of the stream
had reached a state in which the frame would otherwise be discarded, or
when a STREAM frame did not advance the receive offset.  Now the final
size is validated first, so a FINAL_SIZE_ERROR is generated in these
cases as well.
2026-07-29 20:14:43 +04:00
Roman Arutyunyan
e3548e3056 QUIC: apply stream flow control to RESET_STREAM final_size
Previously, stream flow control was not applied to the RESET_STREAM
final_size, which allowed a client to exceed it.  The excess had to be
within the connection flow control limits anyway.

Reported by Tony Wang.
2026-07-29 20:14:43 +04:00
Amin Vakil
01a6ff75ad
GH: restrict the mark_stale job to nginx/nginx
Some checks are pending
buildbot / buildbot (push) Waiting to run
2026-07-28 19:21:19 +03:30
Sergey Kandaurov
33eedb5ae6 Format specifier fixes in error logging
Some checks failed
buildbot / buildbot (push) Has been cancelled
Co-authored-by: Nishat Shabbir <nishat@bugqore.com>
2026-07-25 00:50:53 +04:00
Sourav Bhowmik
0cb3d7fb13 Events: validate descriptor before FD_SET()
The check in ngx_select_init_conf() can be insufficient because it
doesn't cover descriptors for local files, which are not accounted
for in cycle->connection_n.  For instance, to reach this condition
with new connections, no reusable connections must be available for
recycling in ngx_get_connection().

The fix adopts a similar code from the win32 select module.
2026-07-24 20:31:03 +04:00
David Carlier
5e0deb7018 Perl: fixed $r->print() zero copy with mutable scalars
Since d9b7669666, the single-SV zero copy path in $r->print() no
longer required the SV to be read-only.  Reference counting introduced
by that change keeps the SV alive, but not its string buffer: modifying
a mutable scalar after $r->print() overwrites the buffer in place or
reallocates it, while nginx might still have it queued in r->out, since
small responses are postponed by ngx_http_write_filter().  This resulted
in corrupted responses, and in freed memory being sent to the client
when the scalar was grown.

The SV is now required to be read-only again.  Reference counting is
still needed here, as a read-only SV in an eval() might be freed with
the eval's op tree.
2026-07-24 08:42:30 -07:00
Srujan Rai
eaac3d771b Autoindex: use temporary pool for directory entries
Some checks failed
buildbot / buildbot (push) Has been cancelled
Directory listing entries (file names, metadata) were allocated
from the request pool and lived until request teardown.  Use a
temporary pool instead, destroying it immediately after the
response buffer is built.
2026-07-22 16:43:02 +04:00
Sergey Kandaurov
ad8c94a635 Updated security policy report methods
Some checks are pending
buildbot / buildbot (push) Waiting to run
2026-07-22 14:47:33 +04:00
Vadim Zhestikov
95a24d1b9c Image filter: fixed reading past the received data
Some checks failed
buildbot / buildbot (push) Has been cancelled
The size parser and the image decoders used ctx->length, which is the
allocation size (set to image_filter_buffer when the upstream response
omits Content-Length), as the amount of valid data, so a truncated
response without Content-Length could be parsed or decoded past the
received bytes into uninitialized buffer memory.

The length is now adjusted to the actually-read size once the response
body has been read.

Reported by dukesp69 and YLChen-007.
2026-07-17 15:02:43 -07:00
Vadim Zhestikov
fc9749b417 Xslt: xmlCreatePushParserCtxt() error handling
Some checks are pending
buildbot / buildbot (push) Waiting to run
On parser allocation failure, context was left uninitialized
resulting in null pointer dereference.
2026-07-16 12:27:25 -07:00