Commit graph

8553 commits

Author SHA1 Message Date
BalkanMadman
c6deada2d8
Merge e5ce0102dc into 067d766f21 2026-04-06 11:39:30 -04:00
Zoey
067d766f21 Fix $request_port and $is_request_port in subrequests
Some checks are pending
buildbot / buildbot (push) Waiting to run
Closes #1247.
2026-04-06 14:53:54 +04:00
Maxim Dounin
365694160a Added max_headers directive.
The directive limits the number of request headers accepted from clients.
While the total amount of headers is believed to be sufficiently limited
by the existing buffer size limits (client_header_buffer_size and
large_client_header_buffers), the additional limit on the number of headers
might be beneficial to better protect backend servers.

Requested by Maksim Yevmenkin.

Signed-off-by: Elijah Zupancic <e.zupancic@f5.com>
Origin: <199dc0d6b0>
2026-04-06 14:08:36 +04:00
David Korczynski
06c30ec29d Upstream: fix integer underflow in charset parsing
The issue described below was only reproducible prior to
7924a4ec6c

When parsing the `charset` parameter in the `Content-Type` header within
`ngx_http_upstream_copy_content_type`, an input such as `charset="`
resulted in an integer underflow.

In this scenario, both `p` and `last` point to the position immediately
following the opening quote. The logic to strip a trailing quote checked
`*(last - 1)` without verifying that `last > p`. This caused `last` to
be decremented to point to the opening quote itself, making `last < p`.

The subsequent length calculation `r->headers_out.charset.len = last - p`
resulted in -1, which wrapped to `SIZE_MAX` as `len` is a `size_t`. This
invalid length was later passed to `ngx_cpymem` in `ngx_http_header_filter`,
leading to an out-of-bounds memory access (detected as
`negative-size-param` by AddressSanitizer).

The fix ensures `last > p` before attempting to strip a trailing quote,
correctly resulting in a zero-length charset for malformed input.

The oss-fuzz payload that triggers this issue holds multiple 103 status
lines, and it's a sequence of 2 of those Content-Type headers that
trigger the ASAN report.

Co-authored-by: CodeMender <codemender-patching@google.com>
Fixes: https://issues.oss-fuzz.com/issues/486561029

Signed-off-by: David Korczynski <david@adalogics.com>
2026-04-06 14:07:18 +04:00
Eugene Grebenschikov
2ff1a969f3 Removed CLOCK_MONOTONIC_FAST support.
Some checks failed
buildbot / buildbot (push) Has been cancelled
CLOCK_MONOTONIC_FAST, like CLOCK_MONOTONIC_COARSE, has low accuracy. It
shows noticeable timing variation for short intervals, which is visible
in metrics like $upstream_response_time for fast upstream responses.
This change complements the work started in commit f29d7ade5.
In addition to the reasons described in f29d7ade5, the performance of
CLOCK_MONOTONIC is good enough on modern hardware when using a TSC
timecounter. This is especially true when it is accessed through a
shared page, as implemented in FreeBSD 10.0 (see git commits
869fd80fd449 and aea810386d8e for details).

Co-authored-by: Sergey Kandaurov <pluknet@nginx.com>
2026-04-03 11:57:21 -07:00
Sergey Kandaurov
7924a4ec6c Upstream: fixed processing multiple 103 (early hints) responses.
Some checks are pending
buildbot / buildbot (push) Waiting to run
The second 103 response in a row was treated as the final response header.
2026-04-02 20:54:32 +04:00
xuruidong
9fd94af4dd Update CONTRIBUTING.md
Some checks failed
buildbot / buildbot (push) Has been cancelled
2026-03-31 15:36:50 +01:00
Sergey Kandaurov
0d025b4a94 SSL: compatibility with OpenSSL 4.0.
Some checks are pending
buildbot / buildbot (push) Waiting to run
X509_get_issuer_name() and X509_get_subject_name() were changed to return
a const value.  Since it is passed to functions with a non const argument
in older versions, the const modifier is conditionally compiled as needed.

ASN1_INTEGER was made opaque.  ASN1_STRING accessors are used to preserve
the behaviour.  ASN1_STRING_get0_data() compat shim is provided for OpenSSL
< 1.1.0 where it does not exist.
2026-03-31 12:32:19 +04:00
Sergey Kandaurov
390767e6ec Version bump. 2026-03-31 12:32:19 +04:00
Eugene Grebenschikov
0de6e878ba Fixed the "include" directive inside the "geo" block.
Some checks failed
buildbot / buildbot (push) Has been cancelled
The "include" directive should be able to include multiple files if
given a filename mask.

Completes remaining changes introduced in da4ffd8.

Closes: https://github.com/nginx/nginx/issues/1165
2026-03-24 11:20:16 -07:00
Roman Arutyunyan
5ac6f49371 nginx-1.29.7-RELEASE 2026-03-24 19:38:34 +04:00
Sergey Kandaurov
18711f7754 Stream: fixed client certificate validation with OCSP.
Check for OCSP status was missed in 581cf2267, resulting
in a broken validation.

Reported by Mufeed VH of Winfunc Research.
2026-03-24 19:28:20 +04:00
Sergey Kandaurov
9bc13718fe Mail: fixed clearing s->passwd in auth http requests.
Some checks are pending
buildbot / buildbot (push) Waiting to run
Previously, it was not properly cleared retaining length as part of
authenticating with CRAM-MD5 and APOP methods that expect to receive
password in auth response.  This resulted in null pointer dereference
and worker process crash in subsequent auth attempts with CRAM-MD5.

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

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

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

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

Also, the change fixes possible buffer overread and overwrite that could
happen while processing empty stco and co64 atoms, as reported by
Pavel Kohout (Aisle Research) and Tim Becker.
2026-03-24 18:12:29 +04:00
Roman Arutyunyan
d787755d50 Upstream keepalive: fixed parameter parsing. 2026-03-24 15:38:16 +04:00
Roman Semenov
6bb27a6312 Proxy: enabled HTTP/1.1 by default for upstream connections.
Updates the proxy module to use HTTP/1.1 as the default protocol when
communicating with upstream servers. This change unlocks features
such as persistent connections and chunked transfer encoding. Configurations
that require HTTP/1.0 can still override the protocol explicitly.
2026-03-24 14:28:52 +04:00
Roman Semenov
4fbe4b6274 Upstream: enabled keepalive by default for explicit upstreams.
Keepalive is now automatically enabled in the "local" mode for upstreams
defined in configuration files. Cached keepalive connections are no longer
shared between different locations referencing the same explicit upstream
unless keepalive is explicitly configured without the "local" parameter.

To disable keepalive entirely, use keepalive 0; inside the upstream block.
To allow sharing cached connections between locations, configure
keepalive <max_cached>; without the "local" parameter.
2026-03-24 14:28:52 +04:00
Roman Semenov
c5d36eac33 Upstream keepalive: distinguish cached connections by location.
The new "local" parameter prevents sharing cached keepalive connections
between location blocks. Connections are now reused only within the same
location.
2026-03-24 14:28:52 +04:00
Dmitry Plotnikov
c6c77e8875 Added COMPAT section to ngx_log_t.
Some checks are pending
buildbot / buildbot (push) Waiting to run
2026-03-23 09:38:11 -07:00
Sergey Kandaurov
920dc099c1 The "multipath" parameter of the "listen" directive.
Some checks failed
buildbot / buildbot (push) Has been cancelled
When configured, it enables Multipath TCP support on a listen socket.
As of now it works on Linux starting with Linux 5.6 and glibc 2.32,
where it is enabled with an IPPROTO_MPTCP socket(2) protocol.

To avoid EADDRINUSE errors in bind() and listen() when transitioning
between sockets with different protocols, SO_REUSEPORT is set on both
sockets.  See f7f1607bf for potential implications.

Based on previous work by Maxime Dourov and Anthony Doeraene.
2026-03-19 01:13:51 +04:00
David Carlier
a29476464c gRPC: reset buffer chains on upstream reinit.
Some checks failed
buildbot / buildbot (push) Has been cancelled
Previously, ctx->out was not cleared in ngx_http_grpc_reinit_request(),
which could cause queued HTTP/2 control frames (SETTINGS ACK, PING ACK,
WINDOW_UPDATE) to be sent on next upstream.

Additionally, ctx->in and ctx->busy needs to be cleared to avoid similar
problems with buffered request body fixed in cd12dc4f1.
2026-03-16 11:38:06 +04:00
David Carlier
bcd1a01d3b Proxy: reset pending control frames on HTTP/2 upstream reinit.
Previously, ctx->out was not cleared in ngx_http_proxy_v2_reinit_request(),
which could cause stale HTTP/2 control frames (SETTINGS ACK, PING ACK,
WINDOW_UPDATE) queued for the old upstream connection to be sent to a new
upstream connection during a retry.
2026-03-16 11:37:33 +04:00
Roman Arutyunyan
e23e7dd83a Proxy authentication definitions.
Some checks failed
buildbot / buildbot (push) Has been cancelled
2026-03-11 19:33:12 +04:00
Roman Arutyunyan
60d0329a20 Version bump. 2026-03-11 19:32:17 +04:00
Sergey Kandaurov
cb85fbbfba nginx-1.29.6-RELEASE
Some checks failed
buildbot / buildbot (push) Has been cancelled
2026-03-10 19:29:07 +04:00
Sergey Kandaurov
c20777a1e9 Fixed typos. 2026-03-10 19:29:07 +04:00
Sergey Kandaurov
55689299d9 Updated zlib used for win32 builds. 2026-03-10 19:29:07 +04:00
Aleksei Bavshin
52cda2849c Sticky: fixed expiration of learned sessions after reload.
Some checks failed
buildbot / buildbot (push) Has been cancelled
Previously, the expiration timer for learned session was not started
until a new session is created.  This could lead to the sessions being
active past the expiration time.
2026-03-09 11:08:30 -06:00
Vladimir Kokshenev
0380586e69 Sticky: samesite=<strict|lax|none> cookie flags.
Adds new options for the "sticky cookie" directive to set
samesite=<strict|lax|none> cookie flags.
2026-03-09 11:08:30 -06:00
Vladimir Homutov
8021cb02de Sticky: added the "header" parameter in the learn mode.
With this parameter set, sessions are learned after receiving upstream headers.
2026-03-09 11:08:30 -06:00
Vladimir Homutov
7acbe17776 Sticky: added the "max-age" attribute to cookie.
RFC 6265 defines "Max-Age" cookie attribute in section 5.2.2.

If the "expires" option is passed to the "sticky" directive, "max-age"
attribute will appear in cookies set by the module with corresponding
value in seconds.

For the special "max" value of the "expires" option, corresponding "max-age"
attribute value will be set to 315360000 seconds (10 years, similar to
how its done in headers_filter module for the "Cache-Control" header).
2026-03-09 11:08:30 -06:00
Vladimir Homutov
c988a6e2c1 Sticky: added variables support to cookie domain. 2026-03-09 11:08:30 -06:00
Vladimir Homutov
6c13f0468b Sticky: added "httponly" and "secure" attributes.
The attributes are described in RFC6265, sections 4.1.2.5 and 4.1.2.6
respectively.
2026-03-09 11:08:30 -06:00
Vladimir Homutov
d12dd2405d Sticky: added "draining" peer state.
While peer is draining, only sticky requests are served and the peer is never
selected to process new requests.

Co-authored-by: Ruslan Ermilov <ru@nginx.com>
2026-03-09 11:08:30 -06:00
Aleksei Bavshin
c5036ad30c Upstream: introduced a new macro for down value. 2026-03-09 11:08:30 -06:00
Vladimir Homutov
af7137c88a Sticky: added the "learn" mode.
In this mode, nginx "learns" which client uses which proxied server by
analyzing headers of client requests and proxied server responses.

For example, a proxied server may start sessions by issuing the "Set-Cookie"
header field to set cookie 'sid' and returning clients will bring the cookie
with the same name.

The following configuration may be used to handle this case:

upstream u1 {
    server 127.0.0.1:8080;
    server 127.0.0.1:8081;

    sticky learn timeout=10m zone=sess:1m
           create=$upstream_cookie_sid
           lookup=$cookie_sid;
}

Co-authored-by: Ruslan Ermilov <ru@nginx.com>
Co-authored-by: Maxim Dounin <mdounin@mdounin.ru>
2026-03-09 11:08:30 -06:00
Vladimir Homutov
104734f218 Upstream: added sticky sessions support for upstreams.
Sticky sessions allow to route the same client to the same upstream server.

- upstream structures are extended to keep session-related information

- existing balancing modules are updated to provide an id of the selected
  server (SID) in pc->sid, and to select the server, given it's SID.

- other balancing modules are allowed to set the pc->hint value to choose
  the desired peer.  The sticky module will not change the hint if it's
  already set.

- the feature is enabled by default and can be disabled with the
  "--without-http_upstream_sticky" switch of the configure script.

The following configuration can be used to enable sticky sessions for
supported balancing modules:

    upstream u1 {
        server 127.0.0.1:8080;
        server 127.0.0.1:8081;

        sticky cookie server_id expires=1h domain=.example.com path=/;
    }

Co-authored-by: Ruslan Ermilov <ru@nginx.com>
Co-authored-by: Roman Arutyunyan <arut@nginx.com>
Co-authored-by: Maxim Dounin <mdounin@mdounin.ru>
2026-03-09 11:08:30 -06:00
Sergey Kandaurov
dff46cd1ae Mail: fixed type overflow in IMAP literal length parser.
Some checks failed
buildbot / buildbot (push) Has been cancelled
The overflow is safe, because the maximum length of literals
is limited with the "imap_client_buffer" directive.

Reported by Bartłomiej Dmitruk.
2026-03-04 12:08:09 +04:00
Sergey Kandaurov
aa65a60fc7 Mail: stricter IMAP literals validation.
As clarified in RFC 3501, Section 7.5, literals are followed
either by SP, for additional command arguments, or CRLF.
2026-03-04 12:08:09 +04:00
Alessandro Fael Garcia
9e7f0f4c53 Added an option to skip the F5 CLA workflow.
Some checks failed
buildbot / buildbot (push) Has been cancelled
There are some scenarios where the F5 CLA workflow should not run. This commit adds the ability to skip the F5 CLA by using the "skip-cla" label.
2026-02-27 20:07:47 +04:00
user.email
c67bf9415f QUIC: improved error handling in OpenSSL compat layer.
Previously ngx_quic_compat_create_record() could try to encrypt a TLS
record even if encryption context was missing, which resulted in a NULL
pointer dereference.

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

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

The fix is to bind stateless reset token to the worker number.
2026-02-27 19:30:02 +04:00
buulam
717e707488 Updating welcome page with links and more details.
Some checks are pending
buildbot / buildbot (push) Waiting to run
2026-02-26 21:24:00 +04:00
Roman Arutyunyan
c4d3aed8c7 QUIC: fixed bpf compilation with newer Linux kernels.
QUIC bpf program previously used struct bpf_map_def which was
deprecated in [1] (kernel version 5.18) and removed in [2] (kernel 6.1).
New-style BTF map definitions were added in [3] (linux kernel 5.3).

Switching the program to BTF is however not necessary since nginx has
its own relocation procedure which allows referencing the real map
structure by its file descriptor allocated earlier.  In particular,
bpf instruction BPF_LD_IMM64 (0x18/0x0) is substituted with instruction
BPF_LD_MAP_FD (0x18/0x1) and map_fd is stored in the imm field, see [4]
and [5] for details.

To fix compilation, struct bpf_map_def is changed to a known type (int)
and "extern" is added to indicate external linkage and reduce object
file size.

[1] 93b8952d22
[2] dc567045f1
[3] abd29c9314
[4] https://github.com/torvalds/linux/blob/master/include/linux/filter.h
[5] https://datatracker.ietf.org/doc/rfc9669/
2026-02-26 20:43:03 +04:00
Sergey Kandaurov
e6ffe8384e QUIC: Stateless Reset rate limiting.
Some checks are pending
buildbot / buildbot (push) Waiting to run
It uses a bloom filter to limit sending Stateless Reset packets no more
than once per second in average for the given address.  This allows to
address resource asymmetry from precomputed packets, as well as to limit
potential Stateless Reset exchange.
2026-02-26 18:05:07 +04:00
Sergey Kandaurov
2f039e6f72 QUIC: refactored ngx_quic_address_hash().
Now it accepts an optional salt, to be used in a subsequent change.
2026-02-26 18:05:07 +04:00
Sergey Kandaurov
578c91818f QUIC: moved ngx_quic_address_hash(). 2026-02-26 18:05:07 +04:00