Commit Graph
8621 Commits
Author SHA1 Message Date
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 HomutovandRuslan Ermilov 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
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
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.
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.
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. 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] https://github.com/torvalds/linux/commit/93b8952d223af03c51fba0c6258173d2ffbd2cb7
[2] https://github.com/torvalds/linux/commit/dc567045f1590f6460d3e9a6ea6ad5e600b58b84
[3] https://github.com/torvalds/linux/commit/abd29c9314595b1ee5ec6c61d7c49a497ffb30a3
[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.
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
Sergey Kandaurov 4037746c80 QUIC: limited size of generated Stateless Reset packets.
Made sure to send packets smaller than the triggering packet,
following RFC 9000, Section 10.3.3.

Reported-by: cyberspace61
2026-02-26 18:05:07 +04:00
Sergey Kandaurov 2c7252dcad QUIC: adjusted minimum packet size to send Stateless Reset.
Now to be valid, it also assumes the Connection ID we require from a client.
2026-02-26 18:05:07 +04:00
Roman Arutyunyan edb4d2ffa7 Resolver: fixed off-by-one read in ngx_resolver_copy().
It is believed to be harmless, see a similar change 077a890a76.

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

The fix validates each stss entry in ngx_http_mp4_seek_key_frame()
and returns an error if a zero sync sample is encountered.  The
function signature is changed to return ngx_int_t so it can signal
errors to the caller.
2026-02-23 14:10:53 +04:00
Sergey Kandaurov ec714d52bd SCGI: fixed passing CONTENT_LENGTH in unbuffered mode.
Passing requests to SCGI uses a recalculated size of a request body
as per changes made in d60b8d10f (1.3.9) to support CONTENT_LENGTH
with chunked body requests.  This, however, is not compatible with
unbuffered mode introduced later in 7ec559df5 (1.7.11), where such
an approach may not always represent complete request body.

The fix is to use r->headers_in.content_length_n representing either
original Content-Length, if any, or a recalculated value from request
body filters, such as chunked body filter.

Reported by Mufeed VH.
2026-02-17 17:45:29 +04:00
Vadim Zhestikov bf0508fabf Improved $cookie_ evaluation.
In case "Cookie" header is sent by client, multiple cookie pairs were
incorrectly split by a semicolon and comma.

Now they are split by a semicolon only.

For example, next variables will be found for "Cookie: a=b, c=d; e=f":
- $cookie_a: "b, c=d"
- $cookie_e: "f"

Closes #1042 on GitHub.
2026-02-12 10:52:20 -08:00
Roman Arutyunyan f8e1bc5b98 Proxy: fixed HTTP/2 upstream with caching enabled.
Previously, when proxy_cache and keepalive were both enabled with an
HTTP/2 upstream, the second request for a cached resource could fail with
"upstream sent frame for unknown stream" error followed by "cache file
contains invalid header".

This happened because ctx->id was set to 1 in the case when no upstream
connection exists (e.g. cache hit), making the stream id check fail when
the cached response contained frames from a different stream.

The fix is to set ctx->id to 0 when there is no upstream connection,
indicating that no real stream exists, and skip the stream id validation
in this case.  Also, ctx->id = 1 is now set only for new connections,
not in the shared done label.

Closes: https://github.com/nginx/nginx/issues/1101
2026-02-11 18:57:43 +04:00
Roman Arutyunyan d662a5cc46 Version bump. 2026-02-11 18:56:27 +04:00
Roman Arutyunyan 1f57d8dc9d nginx-1.29.5-RELEASE release-1.29.5 2026-02-04 19:12:20 +04:00
Roman Arutyunyan d7a249470b Upstream: reinit upstream after reading bad response.
Previously, when connecting to a backend, if the read event handler was
called before the write event handler, and the received response triggered
a next upstream condition, then ngx_http_upstream_reinit() was not called
to clean up the old upstream context.  This had multiple implications.

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

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

SSL initialization for backend connections happens only in the write event
handler since SSL handshake starts with sending Client Hello.  Previously,
if a backend sent a quick plain text response, it could be parsed by the
read event handler prior to starting SSL handshake on the connection.
The change adds protection against parsing such responses on SSL-enabled
connections.
2026-02-04 19:09:20 +04:00
Roman Arutyunyan 86e5930e76 Updated OpenSSL and PCRE used for win32 builds. 2026-02-03 20:45:13 +04:00
Sergey Kandaurov 3afd85e4b5 Output chain: clear the last_buf flag unless inherited.
For instance, the last_buf flag is used in the http proxy module when
creating HTTP/2 requests to indicate the output is closed.  The flag
is inherited in ngx_output_chain() to a destination buffer when reading
the buffered request body.  Then it is used in the proxy output filter
to mark the last HTTP/2 DATA frame with END_STREAM.

The problem happens when reusing the destination buffer, such as to
re-read the buffered request body on next upstream, because this buffer
may contain a dirty last_buf value, which breaks sending HTTP/2 request
body in multiple output filter calls.

The flush and last_in_chain flags are cleared for consistency.
2026-01-29 14:52:41 +04:00
Sergey Kandaurov cd12dc4f12 Proxy: fixed sending HTTP/2 buffered request body on next upstream.
If a buffered request body wasn't fully sent, such as on early upstream
response or limited by flow control, unsent buffers could remain in the
input or busy chains when switching to the next upstream server.  This
resulted either in the invalid request sent or a stalled connection.

The fix is to reset chains similar to ngx_http_upstream_reinit().
2026-01-29 14:52:41 +04:00
Luboš Uhliarik 349c72e858 Clarify binding behavior of -t option.
Configuration testing includes binding to configured listen addresses
when opening referenced files.
2026-01-26 13:57:41 +04:00
Sergey Kandaurov 926c800a7a Misc: revised GitHub documentation in generated ZIP archive.
Now all GitHub .md files will reside in the docs directory.
While expicitly listing all files might be better for clarity,
this eliminates the need to touch "zip" target every such time.
This includes a recently added SUPPORT.md in 367113670.
2026-01-26 11:58:48 +04:00
Sergey Kandaurov cb9252ae65 Range filter: reasonable limit on multiple ranges.
A total response length with multiple ranges can be larger than the
source response size due to multipart boundary headers.  This change
extends max ranges limit imposed in c2c3e3105 (1.1.2) by accounting
boundary headers.  Notably, this covers suspicious requests with a
lot of small ranges that have an increased processing overhead and
are susceptible to range based amplification attacks.

The limit disables ranges as long as a total response length comes
close to the source size, additionally penalizing small size ranges
on a large source size where a processing overhead prevails, while
leaving a room for more ranges on a small source size, such that it
should not affect well-behaving applications.  The limit can be
altered with the "max_ranges" directive.

Closes #988 on GitHub.
2026-01-21 20:39:00 +04:00
Sergey Kandaurov 7fa941a55e Year 2026. 2026-01-16 16:13:35 +04:00
Andrew Clayton 8ea6eb5108 Uwsgi: ensure HTTP_HOST is set to the requested target host.
Previously, the HTTP_HOST environment variable was constructed from the
Host request header field, which doesn't work well with HTTP/2 and
HTTP/3 where Host may be supplanted by the ":authority" pseudo-header
field per RFC 9110, section 7.2. Also, it might give an incorrect
HTTP_HOST value from HTTP/1.x requests given in the absolute form, in
which case the Host header must be ignored by the server, per RFC 9112,
section 3.2.2.

The fix is to redefine the HTTP_HOST default from a protocol-specific
value given in the $host variable. This will now use the Host request
header field, ":authority" pseudo-header field, or request line target
URI depending on request HTTP version.

Also the CGI specification (RFC 3875, 4.1.18) notes

  The server SHOULD set meta-variables specific to the protocol and
  scheme for the request. Interpretation of protocol-specific
  variables depends on the protocol version in SERVER_PROTOCOL.
2026-01-15 23:04:38 +00:00
Andrew Clayton d8d092a49d SCGI: ensure HTTP_HOST is set to the requested target host.
Previously, the HTTP_HOST environment variable was constructed from the
Host request header field, which doesn't work well with HTTP/2 and
HTTP/3 where Host may be supplanted by the ":authority" pseudo-header
field per RFC 9110, section 7.2. Also, it might give an incorrect
HTTP_HOST value from HTTP/1.x requests given in the absolute form, in
which case the Host header must be ignored by the server, per RFC 9112,
section 3.2.2.

The fix is to redefine the HTTP_HOST default from a protocol-specific
value given in the $host variable. This will now use the Host request
header field, ":authority" pseudo-header field, or request line target
URI depending on request HTTP version.

Also the CGI specification (RFC 3875, 4.1.18) notes

  The server SHOULD set meta-variables specific to the protocol and
  scheme for the request. Interpretation of protocol-specific
  variables depends on the protocol version in SERVER_PROTOCOL.
2026-01-15 23:04:38 +00:00
Andrew Clayton 71b18973b2 FastCGI: ensure HTTP_HOST is set to the requested target host.
Previously, the HTTP_HOST environment variable was constructed from the
Host request header field, which doesn't work well with HTTP/2 and
HTTP/3 where Host may be supplanted by the ":authority" pseudo-header
field per RFC 9110, section 7.2. Also, it might give an incorrect
HTTP_HOST value from HTTP/1.x requests given in the absolute form, in
which case the Host header must be ignored by the server, per RFC 9112,
section 3.2.2.

The fix is to redefine the HTTP_HOST default from a protocol-specific
value given in the $host variable. This will now use the Host request
header field, ":authority" pseudo-header field, or request line target
URI depending on request HTTP version.

Also the CGI specification (RFC 3875, 4.1.18) notes

  The server SHOULD set meta-variables specific to the protocol and
  scheme for the request. Interpretation of protocol-specific
  variables depends on the protocol version in SERVER_PROTOCOL.

Closes: https://github.com/nginx/nginx/issues/256
Closes: https://github.com/nginx/nginx/issues/455
Closes: https://github.com/nginx/nginx/issues/912
2026-01-15 23:04:38 +00:00
Aleksei Bavshin 6a67f71a4a Win32: fixed C4319 warning with MSVC 2022 x86.
The warning started to appear in Visual Studio 2022 version 17.14.21,
which corresponds to the C/C++ compiler version 19.44.35221.

The appropriate fix is to avoid mixing uint64_t and ngx_uint_t in an
expression with bitwise operations.  We can do that here because both
the original shm->size value and the result of the expression are 32-bit
platform words.
2025-12-24 11:41:43 -07:00
Roman Arutyunyan 0609736a92 SSL: logging level of the "ech_required" TLS alert.
The alert is send by a client after its ECH configuration was rejected by
a server.
2025-12-17 13:49:06 +04:00
Aleksei Bavshin 7c2524a692 Fixed duplicate ids in the bug report template. 2025-12-16 14:22:33 -07:00
Aleksei Bavshin 5c2947d844 Version bump. 2025-12-16 14:22:33 -07:00
Sergey Kandaurov c70457482c nginx-1.29.4-RELEASE release-1.29.4 2025-12-09 22:28:10 +04:00
Jan Svojanovsky 66fde99b1d QUIC: fixed possible segfault on handshake failures.
When using OpenSSL 3.5, the crypto_release_rcd QUIC callback can be
called late, after the QUIC connection was already closed on handshake
failure, resulting in a segmentation fault.  For instance, it happened
if a client Finished message didn't align with a record boundary.
2025-12-09 21:25:10 +04:00
Zhidao HONG 61690b5dc0 Proxy: cache support for HTTP/2. 2025-12-08 07:49:16 +04:00
Zhidao HONG 17fd964f99 Proxy: buffering support for HTTP/2. 2025-12-08 07:49:16 +04:00
Zhidao HONG fdd8e97558 Proxy: extracted control frame and skip functions for HTTP/2. 2025-12-08 07:49:16 +04:00
Zhidao HONG 2a0342a17d Proxy: extracted ngx_http_proxy_v2_process_frames() function. 2025-12-08 07:49:16 +04:00