Commit graph

8634 commits

Author SHA1 Message Date
Jakub Onderka
e6af893fc7
Merge 4431657c5a into 42f8df65b6 2026-06-26 16:02:49 +02:00
Feng Wu
42f8df65b6 Add missing bounds check in ngx_{http,stream}_compile_complex_value()
Some checks failed
buildbot / buildbot (push) Has been cancelled
Complex value compilation scans strings for $1..$9 capture references.
Check that a byte after '$' is present before testing it, matching
ngx_str_t length semantics and avoiding reliance on NUL termination.

Apply the same check to both HTTP and stream implementations.
2026-06-25 09:15:44 -07:00
Feng Wu
2d71bdcf8b HTTP/2: fixed overlapping memcpy in CONTINUATION frames
Some checks are pending
buildbot / buildbot (push) Waiting to run
When processing CONTINUATION frames, ngx_http_v2_handle_continuation()
used ngx_memcpy() to shift header block fragment data past the frame
header.  If the fragment is larger than the frame header (9 bytes),
the source and destination regions overlap, which is undefined
behavior for memcpy.  The same function already uses ngx_memmove()
for another overlapping shift.
2026-06-24 17:57:50 +01:00
Miao Wang
be84ac8bda Configure: set cache line size for loongarch64
Some checks are pending
buildbot / buildbot (push) Waiting to run
Section 8.2 table 54, registers 0x11 - 0x14 (2^6 = 64 bytes)
<https://loongson.github.io/LoongArch-Documentation/Loongson-3A5000-usermanual-EN.html#instruction-set-features-implemented-in-3a5000>

There is no intent to cover 32-bit LoongArch which acceptably falls
through to the default.
2026-06-23 15:24:27 +01:00
Andrew Clayton
e01f4fe3a9 Version bump 2026-06-23 15:22:11 +01:00
Sergey Kandaurov
2fd01ed47a nginx-1.31.2-RELEASE
Some checks failed
buildbot / buildbot (push) Has been cancelled
2026-06-17 07:40:35 -07:00
Sergey Kandaurov
319a0bff15 Charset: fixed another rare buffer overread in recode_from_utf8()
With prerequisites similar to 696a7f1b9, it was possible to gain 1-byte
overread on invalid UTF-8 sequences.  The reason is ngx_utf8_decode()
stops advancing the pointer position on the first encountered invalid
byte.  The fix is to adjust the advanced pointer up to the whole saved
sequence in this case.  Note that this may result in different output
compared to complete invalid UTF-8 sequences, which we can disregard
at this point.

Reported by Han Yan of Xiaomi and p4p3r of CYBERONE.
2026-06-17 07:40:35 -07:00
Roman Arutyunyan
26d824ec3a Upstream: limit header length for HTTP/2 and gRPC
The change applies the HTTP/2 header length limits to avoid buffer
overflow.  See 58a7bc3406 for details.

Reported by Mufeed VH of Winfunc Research.
2026-06-17 07:40:35 -07:00
Roman Arutyunyan
9e293766e7 HTTP/3: avoid recreation of standard client uni streams
Creating a control/encoder/decoder stream while another such stream
already exists, is not allowed.  Also, closing such a stream results
in connection closure with NGX_HTTP_V3_ERR_CLOSED_CRITICAL_STREAM.
However, since stream creation and connection closure are asynchronous,
there could be a window where two control/encoder/decoder streams
could coexist within a single cycle iteration.  This could result
in reusing parsing context, such as encoder insert buffer.

The change adds a mask for all standard client uni streams ever created.
This allows to check if a stream of this type was created before.
While here, mandatory stream validation now also uses this mask.
2026-06-17 07:40:35 -07:00
Roman Arutyunyan
ceccdbd2ee HTTP/3: allocate insert buffer from connection pool
Previously, it was allocated from the encoder stream pool.  This could
lead to use-after-free if the stream was closed and another encoder
stream was opened.

Reported by Trung Nguyen (@everping) of CyStack.
2026-06-17 07:40:35 -07:00
Roman Arutyunyan
875750a4f7 HTTP/3: use max table capacity for insert buffer allocation
Previously, current capacity was used for the allocation, which could
be insufficient if table capacity was later increased.
2026-06-17 07:40:35 -07:00
Sergey Kandaurov
ab976ab39a Updated OpenSSL used for win32 builds
Some checks are pending
buildbot / buildbot (push) Waiting to run
2026-06-16 14:47:04 -07:00
Andrew Clayton
da80db978f GH: fix check-whitespace.yaml error return with multiple commits
Some checks failed
buildbot / buildbot (push) Has been cancelled
Commit 126cb16e3 ("GH: fix check-whitespace.yaml error return with
multiple commits") removed the wrong err=0. Put it back and remove the
*right* one!
2026-06-11 06:23:00 +01:00
Nitin Swami
e09c0d32d5 Access log: fix "request_length" format length
The variable handler uses "%O" format specifier.

Reported by Mufeed VH of Winfunc Research.
2026-06-11 09:12:57 +05:30
Sergey Kandaurov
bedf18f95d Secure link: compare hashes in constant time
Some checks are pending
buildbot / buildbot (push) Waiting to run
Reported by kodareef5
2026-06-11 01:40:19 +05:30
Sergey Kandaurov
b23fdb91ee Secure link: style 2026-06-11 01:40:19 +05:30
Andrew Clayton
126cb16e3d GH: fix check-whitespace.yaml error return with multiple commits
We erroneously reset err to 0 for each commit.
2026-06-10 19:23:40 +01:00
Andrew Clayton
fefae70f63 GH: fix summary formatting for check-whitespace.yaml
Wrap the git log --check output in a markdown code block to prevent
undesirable formatting.
2026-06-10 19:23:40 +01:00
Sergey Kandaurov
8bbaf83d48 Updated link to OpenSSL commit 2026-06-10 22:21:10 +04:00
Sergey Kandaurov
455fbf8c45 Style 2026-06-10 22:21:10 +04:00
Sergey Kandaurov
d994f5b822 Split clients: improved calculation of range boundaries
Some checks failed
buildbot / buildbot (push) Has been cancelled
If the last variant was given an explicit percentage to reach 100%, it
did not cover hash values on the range boundary or due to accumulating
rounding error.  Now this corresponds to the configuration with "*".
2026-06-09 19:04:17 +04:00
Andrew Clayton
cab0697310 GH: remove the set-creation-date.yaml workflow
Some checks are pending
buildbot / buildbot (push) Waiting to run
Now that GitHub has introduced various date fields, including 'Created',
in projects, we no longer require this workflow.
2026-06-08 15:49:02 +01:00
Boris Tonofa
ac4bedfafe Xslt: fix handling of vsnprintf() return value 2026-06-08 14:29:08 +04:00
Vadim Zhestikov
1c387799ca SSL: add $ssl_sigalgs variable
Some checks failed
buildbot / buildbot (push) Has been cancelled
The new $ssl_sigalgs variable lists all signature algorithms
advertised by the client in its ClientHello message,
colon-separated, in analogy to $ssl_ciphers and $ssl_curves.

On OpenSSL 4.0+, SSL_get0_sigalg() is used, which returns proper
TLS scheme names (e.g. "rsa_pkcs1_sha256", "ecdsa_secp256r1_sha256")
and falls back to "0xHHHH" hex for unknown schemes.

On OpenSSL 1.0.2+, SSL_get_sigalgs() is used.  Since OBJ_nid2sn()
on the combined psignhash NID is not injective across TLS
SignatureScheme codes (e.g. 0x0403 and 0x081a both yield
"ecdsa-with-SHA256"), raw SignatureScheme codes are reported to
avoid ambiguity and to match the hex fallback format of
SSL_get0_sigalg().

With older versions, as well as BoringSSL, LibreSSL, and AWS-LC,
the variable is empty.
2026-06-04 09:50:50 -07:00
Eugene Grebenschikov
c5f2afd50e Switched $request_id to SipHash-based generation
Some checks failed
buildbot / buildbot (push) Has been cancelled
Replaced RAND_bytes() and random() based $request_id
generation with SipHash-2-4.  The previous implementation
used RAND_bytes() when built with OpenSSL, which is
50-100x slower than needed for a non-security identifier,
and fell back to random() which produces poor 128-bit
random numbers.

The new implementation calls SipHash twice with a secret
key and a monotonic counter, producing 128 bits with good
statistical distribution at a fraction of the cost.
2026-06-02 15:30:30 -07:00
Eugene Grebenschikov
6067896f03 Core: added SipHash-2-4 implementation
Added ngx_siphash() function implementing the SipHash-2-4
algorithm for fast pseudorandom number generation with good
statistical properties.

Co-authored-by: Sergey Kandaurov <pluknet@nginx.com>
2026-06-02 15:30:30 -07:00
Eugene Grebenschikov
25273ede01 Version bump 2026-06-02 15:30:30 -07: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
Jakub Onderka
4431657c5a SSL: ssl_sigalgs option 2026-05-20 19:20:46 +02: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 failed
buildbot / buildbot (push) Has been cancelled
2026-05-11 19:40:47 +04:00
Roman Arutyunyan
631bfa194d Support 407 code in "satisfy any" and "auth_delay"
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