Commit graph

8608 commits

Author SHA1 Message Date
Denis I
c4e98a85bb
Merge 489c02273f into d44205284f 2026-05-23 04:36:30 +00:00
Sergey Kandaurov
d44205284f nginx-1.31.1-RELEASE
Some checks failed
buildbot / buildbot (push) Has been cancelled
2026-05-22 19:02:07 +04:00
Roman Arutyunyan
ca4f92a274 Rewrite: fix buffer overflow with overlapping captures
When the rewrite replacement string had no variables, but had
overlapping captures, the length of the allocated buffer could be
smaller than the replacement string.  This could happen either
when the "redirect" parameter is specified, or when arguments are
present in the replacement string.

The following configurations resulted in heap buffer overflow when
using URI "/++++++++++++++++++++++++++++++":

    location / {
        rewrite ^/((.*))$ http://127.0.0.1:8080/$1$2 redirect;
        return 200 foo;
    }

    location / {
        rewrite ^/((.*))$ http://127.0.0.1:8080/?$1$2;
        return 200 foo;
    }

Reported by Mufeed VH of Winfunc Research.
2026-05-22 18:55:09 +04:00
Roman Arutyunyan
475732a3f9 Rewrite: harden escape flags control
Some checks are pending
buildbot / buildbot (push) Waiting to run
Following 2046b45aa0, this change introduces better control of memory
allocation flags for escaped values.  Notably:

- The e->is_args flag is now explicitly reset on rewrite start.
  If the flag was set prior to rewrite start, then buffer overflow
  could happen before 2046b45aa0.

- The le->is_args flag value is now copied from e->is_args when
  calculating complex value length for "if" and "set" directives.
  If e->is_args was set, but le->is_args was not, then buffer overflow
  could happen before 2046b45aa0.
2026-05-21 18:00:00 +04:00
Roman Arutyunyan
eff1108854 Mail: style
Some checks failed
buildbot / buildbot (push) Has been cancelled
2026-05-15 16:25:01 +04:00
Roman Arutyunyan
a4d5da3e40 Mail: fix session cleanup on error path
Previously, when ngx_handle_read_event() or ngx_handle_write_event()
returned an error while handling an SMTP, POP3 or IMAP session, the
released session memory could be accessed after handling the error.
2026-05-15 16:25:01 +04:00
Roman Arutyunyan
58a7bc3406 HTTP/2: limit Content-Type and Location response header length
Previously, when these fields were larger than ~2M, the number of bytes
allocated for the field length was insufficient for such a large number.
The deficit is 1 byte up until ~4M, 2 bytes for sizes above, and grows
bigger with even larger fields.

Currently, nginx does not have modules which allow to exploit this
overflow with reasonably large Content-Type and Location.  The reason is
other response fields make up for this deficit.  For example, the Date
header value contains the characters compressed well by Huffman
encoding, which frees up spare bytes in the header buffer.

Reported by Leo Lin.
2026-05-15 16:23:39 +04:00
Roman Arutyunyan
18a70a4d58 Mp4: avoid adding or comparing to null pointer
It is considered undefined behavior.

Reported by Geonwoo.kim (awo@kakao.com).
2026-05-15 16:20:30 +04:00
Andrew Clayton
7d76d67241 GH: fix set-creation-date.yaml workflow
Some checks are pending
buildbot / buildbot (push) Waiting to run
Fix the name of the 'Created At' field.

Fixes: 319b4ea63 ("GH: set new issues creation date")
2026-05-13 20:19:15 +01:00
Andrew Clayton
80ee028b80 Version bump 2026-05-13 20:19:15 +01:00
Sergey Kandaurov
e8053c867f nginx-1.31.0-RELEASE
Some checks are pending
buildbot / buildbot (push) Waiting to run
2026-05-13 21:19:47 +04:00
Roman Arutyunyan
c24fb259d1 Proxy: fix large body with proxy_set_body and HTTP/2
Previously, if proxy_set_body was used with HTTP/2, and body size exceeded
16M, then an overflow happened in the 24-bit DATA frame size, which resulted
in sending unframed bytes, potentially allowing for an injection.

Also, DATA frame size could exceed NGX_HTTP_V2_DEFAULT_FRAME_SIZE (16K) and
available send window.

Reported by Mufeed VH of Winfunc Research.
2026-05-13 21:19:47 +04:00
Roman Arutyunyan
2046b45aa0 Rewrite: fixed escaping and possible buffer overrun
The following code resulted in incorrect escaping of $1 and possible
segfault:

    location / {
        rewrite ^(.*) /new?c=1;
        set $myvar $1;
        return 200 $myvar;
    }

If there were arguments in a rewrite's replacement string, the is_args flag
was set and incorrectly never cleared.  This resulted in escaping applied
to any captures evaluated afterwards in set or if.  Additionally buffer was
allocated by ngx_http_script_complex_value_code() without escaping expected,
thus this also resulted in buffer overrun and possible segfault.

A similar issue was fixed in 74d939974d.

Reported by Leo Lin.
2026-05-13 21:19:47 +04:00
Sergey Kandaurov
5f86648ef8 Upstream: fixed parsing of split status lines
If the first response line was split across reads and it didn't appear
a status line, the portion already processed was lost.  The change
introduces a new field for proper backtracking on status line fallback.
2026-05-13 21:19:47 +04:00
Sergey Kandaurov
f79c286b34 Upstream: reset parsing state after invalid status line
Previously, it was possible to start parsing headers with a wrong
parsing state after status line was not recognized, as a fallback
used in the scgi and uwsgi modules.

Reported by Leo Lin.
2026-05-13 21:19:47 +04:00
David Carlier
696a7f1b91 Charset: fix buffer over-read in recode_from_utf8().
When a multi-byte UTF-8 character was split across 3+ single-byte
buffers, the saved bytes continuation path had two related bugs:

ngx_utf8_decode() was called with the last saved-array index instead
of the byte count, causing it to report "incomplete" even when the
sequence was already complete.

The subsequent ngx_memcpy() used that same index as the copy length,
reading past the input buffer boundary.
2026-05-13 21:19:47 +04:00
Roman Arutyunyan
f37ec3e5d4 QUIC: avoid assigning unvalidated address to new streams
Previously, when a client migrated to a new address, new QUIC streams
received this address before validation.  This allowed an attacker to
create QUIC streams with a spoofed address.

Reported by Rodrigo Laneth.
2026-05-13 21:19:47 +04:00
Roman Arutyunyan
71841dcedf OCSP: resolve cleanup on connection close
Previously, when a client SSL connection was terminated (typically due to a
timeout) while resolving an OCSP responder, the OCSP context was freed, but
the resolve context was not.  This resulted in use-after-free on resolve
completion.

Reported by Leo Lin.
2026-05-13 21:19:47 +04:00
Andrew Clayton
319b4ea63f GH: set new issues creation date
Some checks are pending
buildbot / buildbot (push) Waiting to run
When a new issue is created, set its 'Created at' date in the
corresponding project.
2026-05-12 19:42:40 +01:00
Sergey Kandaurov
a43c76b4e3 Reject HTTP CONNECT method with no port after colon
Some checks are pending
buildbot / buildbot (push) Waiting to run
2026-05-11 19:40:47 +04:00
Roman Arutyunyan
631bfa194d Support 407 code in "satisfy any" and "auth_delay"
Some checks are pending
buildbot / buildbot (push) Waiting to run
Notably, "auth_delay" now delays the response for both 401 and 407.
Also, in the "satisfy any" mode, the next access/auth attempt is made
for 401, 403 and 407.
2026-05-08 09:42:58 +04:00
Roman Arutyunyan
4e9289e51a Proxy authentication for CONNECT requests
Notably, ngx_http_auth_basic_module uses Proxy-Authorization input
header, Proxy-Authenticate output header and HTTP code 407 instead
of Authorization, WWW-Authenticate and 401 respectively.
2026-05-08 09:42:58 +04:00
Roman Arutyunyan
8599df49d6 HTTP tunnel module
The module handles CONNECT requests and establishes a tunnel to a
backend.

Example config:

http {

    map $request_port $allow_port {
        80             1;
        443            1;
    }

    map $host $allow_host {
        hostnames;

        example.com    1;
        *.example.org  1;
    }

    server {
        listen 8000;

        resolver dns.example.com;

        if ($allow_port != 1) {
            return 403;
        }

        if ($allow_host != 1) {
            return 403;
        }

        tunnel_pass;
    }
}

Request:

    $ curl -x 127.0.0.1:8000 https://example.com
2026-05-08 09:42:58 +04:00
Andrew Clayton
8de740f89d GH: update the stale PR/issue workflow
To avoid future churn give the workflow a generic name, don't operate on
pull-requests, and extend the issues stale date to 365 days and update
its message.
2026-05-07 15:27:02 +01:00
Roman Arutyunyan
1a2adac356 Proxy: fix keepalive for HTTP/2 with explicit or no body
Previously, when an HTTP/2 request had no body or an explicit body
was set by proxy_set_body, the request consisted of only one buffer,
which had no b->last_buf flag set.  This prevented ctx->output_closed
from being set after processing this buffer.  Consequently,
u->keepalive might not be set to store the connection in the
keepalive cache.
2026-05-07 13:18:39 +04:00
Sai Krishna Kumar Reddy Yadamakanti
f0a084645b Dav: improved path validation for COPY and MOVE operations
The COPY and MOVE handler did not validate whether source and
destination paths referred to the same resource or a parent-child
collection relationship, which could corrupt or destroy files.

Now 403 is returned if paths match or one is a prefix of the other.

Reported by Mufeed VH of Winfunc Research.
2026-05-06 19:35:17 +05:30
Vladimir Homutov
3b5da468b3 Stream: least_time balancer module
Some checks failed
buildbot / buildbot (push) Has been cancelled
Example configuration:

upstream u {
    least_time connect | first_byte | last_byte [inflight];
    server a;
    server b;
}

Co-authored-by: Roman Arutyunyan <arut@nginx.com>
2026-05-04 21:19:40 +05:30
Vladimir Homutov
5760d6148e Upstream: least_time balancer module
The module implements load-balancing algorithm based on least average
response header/last_byte time and least number of active connections.

The optional "inflight" mode enables accounting of incomplete
requests/sessions.  This allows to mitigate cases when an upstream
server hangs and does not close connections.

Example configuration:

upstream u {
    least_time header | last_byte [inflight];
    server a;
    server b;
}

Co-authored-by: Roman Arutyunyan <arut@nginx.com>
2026-05-04 21:19:40 +05:30
Vladimir Homutov
45554176ca Upstream: locked version of ngx_*_upstream_free_round_robin_peer().
This allows optimizing ngx_http_upstream_free_least_time_peer() by
not releasing and re-taking the same lock.
2026-05-04 21:19:40 +05:30
Andrew Clayton
35510ddc94 Configure: fix gcc version detection in some corner cases
If the "gcc version ... " string appeared within "Configured with:", it
was picked up rather than the real gcc version string. This might then
break the configure scripts due to a malformed NGX_COMPILER macro.

The simple fix is to look for "gcc version ... " at the start of the
line, rather than anywhere within.

Suggested-by: Aleksei Bavshin <a.bavshin@nginx.com>
Closes: https://github.com/nginx/nginx/issues/1278
2026-05-01 22:43:35 +01:00
Sergey Kandaurov
6eb7dcdd98 Request body: restored buffered empty body special case
This restores a long-standing optimization when the entire request
body is empty and r->request_body_in_file_only is set, used to avoid
writing an empty file as initially introduced in 4c7f51136 (0.4.4).
The previous condition never worked with chunked body filter, where
rb->bufs holds at least the final chunk; in length body filter, it is
used to indicate the last received buffer since 2a7092138 (1.21.2).

The fix is to additionally check if it is the only empty buffer.

Found with UndefinedBehaviorSanitizer (pointer-overflow)
2026-04-30 15:09:24 +04:00
Sergey Kandaurov
484a9863e7 Stream: evaluate proxy_ssl_alpn once
To avoid disagreement with non-cacheable variables.
2026-04-30 15:07:34 +04:00
Henry Yuan
297b096464 Configure: renamed the upstream sticky module option.
The module can now be disabled with the
--without-http_upstream_sticky_module option to match
the naming convention used by other upstream modules.
Deprecated the --without-http_upstream_sticky option.

Closes: https://github.com/nginx/nginx/issues/1273
2026-04-29 09:58:29 -07:00
Denis I
489c02273f
Realip: support for variables in "real_ip_header" directive. 2026-04-26 18:34:38 +02:00
Andrew Clayton
bac04c1b66 Update CONTRIBUTING.md
Some checks failed
buildbot / buildbot (push) Has been cancelled
Adjust the subject and commit message body line length limits to 72
characters to match the commit message linter.
2026-04-24 17:33:41 +01:00
Andrew Clayton
07c7adfc7f GH: add a workflow to check for whitespace issues
This runs git-log(1) --check on *each* commit and will report any
issues, e.g.

  --- afe5753fa ("Changes made in upstream")
  src/http/ngx_http_upstream.c:415: trailing whitespace.
  +
  src/http/ngx_http_upstream.c:417: trailing whitespace.
  +      ngx_http_upstream_backend_ssl_protocol, 0,

Specific exceptions can be handled via gitattributes(5).
2026-04-24 17:33:41 +01:00
Andrew Clayton
1f27ab1c8f GH: check commit messages for the most common errors
This checks commit messages in a pull-request for the most common
problems we see.
2026-04-24 17:33:41 +01:00
Andrew Clayton
61c5178f04 GH: mark old issues & PRs as stale
Mark issues & pull-requests that have had no activity for a specified
amount of time as stale.
2026-04-24 17:33:41 +01:00
Andrew Clayton
6991e3e1c5 GH: post a new issue welcome comment
Whenever a new issue is created in GitHub, post a "welcome" message as a
comment.
2026-04-24 17:33:41 +01:00
Andrew Clayton
83ae7d30bf GH: update the GitHub pull-request template 2026-04-24 17:33:41 +01:00
Andrew Clayton
b0a4d0fb82 Avoid undefined behaviour in ngx_pstrdup()
Some checks failed
buildbot / buildbot (push) Has been cancelled
In the third call to ngx_pstrdup() for setting cycle->conf_param.data in
ngx_init_cycle() we would pass in a nulled ngx_str_t in the case there
was no -g command line option passed to nginx.

This would result in a

  memcpy(dst, NULL, 0)

which up to and including C23 is Undefined Behaviour.

Currently Clang and GCC (in this particular case) just treat this as a
no-op, so things just happen to work.

However some undefined behaviour sanitizers will throw an error when
this is hit, e.g. Clang and the zig compiler and it's probably best not
to rely on this behaviour.

It's worth noting that the next C standard will make this (and other
NULL related operations) defined behaviour.

Link: <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3322.pdf>
Closes: https://github.com/nginx/nginx/issues/1079
2026-04-20 19:56:40 +01:00
Vadim Zhestikov
98fc3bb78e Stream: support ALPN for proxy_ssl upstream.
Added the proxy_ssl_alpn directive, which sets the list of protocols
to advertise via ALPN during upstream TLS handshakes.  Each argument
is a complex value, so variables are accepted.  In particular,

    proxy_ssl_alpn $ssl_alpn_protocol;

inherits the protocol negotiated in the downstream TLS handshake.

When all evaluated values are empty or absent, no ALPN extension is
sent, equivalent to the directive not being set at all.

Closes #406 on GitHub.
2026-04-17 14:16:31 -07:00
Roman Arutyunyan
d7dd7e9ae4 HTTP/3: optimize encoder stream memory usage
Previously, the encoder stream allocated each new inserted field in the
connection pool.  This memory was not freed until the end of the connection.
Now a special insert buffer is used for all inserts.
2026-04-16 19:47:46 +04:00
Roman Arutyunyan
4e89ce224f Restrict duplicate TE headers in HTTP/2 and HTTP/3
Following d3a76322cf, this change rejects requests which have multiple
TE headers.

Reported-by: geeknik <geeknik@protonmail.ch>
2026-04-16 19:47:03 +04:00
Sergey Kandaurov
ff8221b4db SSL: logging level of "record layer failure" errors
The SSL_R_RECORD_LAYER_FAILURE ("record layer failure") errors are
reported by OpenSSL 3.2 or newer as the last record layer error for
various low level read errors.  Further, a976e6b9e (1.23.4) caused
to always log them at the "crit" level.  For example, the following
errors are observed on OpenSSL 3.2.0 - 4.0:

SSL_read() failed (SSL: error:0A000119:SSL routines::decryption failed
 or bad record mac error:0A000139:SSL routines::record layer failure)
SSL_read() failed (SSL: error:1C800066:Provider routines::cipher operation
 failed error:0A000119:SSL routines::decryption failed or bad record mac
 error:0A000139:SSL routines::record layer failure)
SSL_read() failed (SSL: error:0A00010B:SSL routines::wrong version number
 error:0A000139:SSL routines::record layer failure)

These errors are now logged at the "info" level.

Closes: https://github.com/nginx/nginx/issues/961
Co-authored-by: Smeet23 <smeetagrawal2003@gmail.com>
2026-04-16 18:39:23 +04:00
Sergey Kandaurov
ea72fa1d92 QUIC: simplified ngx_quic_cbs_recv_rcd()
There's no need in for-loop, a single buffer is fed at a time.
2026-04-16 15:25:55 +04:00
Sergey Kandaurov
4dd7ec9ae4 QUIC: always populate ngx_quic_cbs_recv_rcd() output arguments
Although uninitialized values aren't used in practice due to the
nature of the OpenSSL code flow, this violates the API contract.

Reported by lukefr09 on GitHub.
2026-04-16 15:25:55 +04:00
Aleksei Bavshin
abc72c5a57 SSL: compatibility with renamed error codes in OpenSSL 4.0.
Some checks failed
buildbot / buildbot (push) Has been cancelled
SSL_R_SSL3_SESSION_ID_TOO_LONG is no longer available when building
OpenSSL 4.0 with no-deprecated.  Added the new name as a fallback.
2026-04-14 11:26:42 -06:00
Maxim Dounin
aa09c19992 SSL: logging level of "invalid alert" errors.
The SSL_R_INVALID_ALERT ("invalid alert") errors are reported by OpenSSL
1.1.1 or newer if the client sends a malformed alert.  These errors are
now logged at the "info" level.

Signed-off-by: Aleksei Bavshin <a.bavshin@nginx.com>
Origin: <https://freenginx.org/hg/nginx/rev/d89e0386b695>
2026-04-14 11:26:42 -06:00
Maxim Dounin
06c9d63fc8 SSL: logging level of all "SSL alert number N" errors.
Errors about alerts received from peers are generated by OpenSSL by adding
peer-provided alert description (from 0 to 255) to SSL_AD_REASON_OFFSET.
All such errors, including ones for unknown alerts, are now logged at the
"info" level, as these can be caused by a misbehaving client.

Signed-off-by: Aleksei Bavshin <a.bavshin@nginx.com>
Origin: <https://freenginx.org/hg/nginx/rev/f5423ee155fe>
2026-04-14 11:26:42 -06:00