8491 Commits

Author SHA1 Message Date
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
Zhidao HONG
9bf758ea4d Proxy: added HTTP/2 proxy module.
The module allows to use HTTP/2 protocol for proxying.
HTTP/2 proxying is enabled by specifying "proxy_http_version 2".

Example:

    server {
        listen 8000;

        location / {
            proxy_http_version 2;
            proxy_pass https://127.0.0.1:8443;
        }
    }

    server {
        listen 8443 ssl;
        http2 on;

        ssl_certificate certs/example.com.crt;
        ssl_certificate_key certs/example.com.key;

        location / {
            return 200 foo;
        }
    }
2025-12-08 07:49:16 +04:00
Roman Arutyunyan
90a4fc7935 Proxy: refactored for HTTP/2 support. 2025-12-08 07:49:16 +04:00
Zhidao HONG
b8492d9c25 Upstream: add support for connection level ALPN protocol negotiation.
This commit is prepared for HTTP/2 and HTTP/3 support.

The ALPN protocol is now set per-connection in
ngx_http_upstream_ssl_init_connection(), allowing proper protocol negotiation
for each individual upstream connection regardless of SSL context sharing.
2025-12-08 07:49:16 +04:00
Sergey Kandaurov
f405ef11fd Disabled bare LF in chunked transfer encoding.
Chunked transfer encoding, since originally introduced in HTTP/1.1
in RFC 2068, is specified to use CRLF as the only line terminator.

Although tolerant applications may recognize a single LF, formally
this covers the start line and fields, and doesn't apply to chunks.
Strict chunked parsing is reaffirmed as intentional in RFC errata
ID 7633, notably "because it does not have to retain backwards
compatibility with 1.0 parsers".

A general RFC 2616 recommendation to tolerate deviations whenever
interpreted unambiguously doesn't apply here, because chunked body
is used to determine HTTP message framing; a relaxed parsing may
cause various security problems due to a broken delimitation.
For instance, this is possible when receiving chunked body from
intermediates that blindly parse chunk-ext or a trailer section
until CRLF, and pass it further without re-coding.
2025-12-06 17:41:32 +04:00
QirunGao
0427f5335f SSL: avoid warning when ECH is not configured and not supported. 2025-12-04 21:09:32 +04:00
Alessandro Fael Garcia
367113670e Update GitHub templates and markdown files.
- Issue templates are replaced with forms.  Forms allow to explicitly ask
  for certain info before an issue is opened, they can be programmatically
  queried via GH actions to get the data in fields.

- Added language around GH discussions vs the forum in the issue forms.

- Added GH discussions templates.  These templates delineate which types
  of discussions belong on GitHub vs the community forum.

- Created SUPPORT.md to delineate which types of topics belong on GitHub
  vs different support channels (community forum/docs/commercial support).

- Updated CONTRIBUTING.md:
  - Removed text that belongs in SUPPORT.md.
  - Added F5 CLA clarifying text.

- Added badges to README.md.  Most of these are there to make information
  even clearer, moreso for users reading README.md from sources outside
  GitHub.
2025-12-04 19:08:14 +04:00
sftcd
ab4f5b2d32 Add basic ECH shared-mode via OpenSSL. 2025-12-01 16:33:40 +04:00
Sergey Kandaurov
bcb41c9193 Proxy: fixed segfault in URI change.
If request URI was shorter than location prefix, as after replacement
with try_files, location length was used to copy the remaining URI part
leading to buffer overread.

The fix is to replace full request URI in this case.  In the following
configuration, request "/123" is changed to "/" when sent to backend.

    location /1234 {
        try_files /123 =404;
        proxy_pass http://127.0.0.1:8080/;
    }

Closes #983 on GitHub.
2025-11-26 22:46:22 +04:00
Sergey Kandaurov
6446f99107 Changed interface of ngx_http_validate_host().
This allows to process a port subcomponent and save it in r->port
in a unified way, similar to r->headers_in.server.  For HTTP/1.x
request line in the absolute form, r->host_end now includes a port
subcomponent, which is also consistent with HTTP/2 and HTTP/3.
2025-11-26 19:51:40 +04:00
Sergey Kandaurov
511abb19e1 Improved host header validation.
Validation is rewritten to follow RFC 3986 host syntax, based on
ngx_http_parse_request_line().  The following is now rejected:
- the rest of gen-delims "#", "?", "@", "[", "]"
- other unwise delims <">, "<", ">", "\", "^", "`', "{", "|", "}"
- IP literals with a trailing dot, missing closing bracket, or pct-encoded
- a port subcomponent with invalid values
- characters in upper half
2025-11-26 19:51:40 +04:00
Sergey Kandaurov
6ed1188411 HTTP/2: extended guard for NULL buffer and zero length.
In addition to moving memcpy() under the length condition in 15bf6d8cc,
which addressed a reported UB due to string function conventions, this
is repeated for advancing an input buffer, to make the resulting code
more clean and readable.

Additionally, although considered harmless for both string functions and
additive operators, as previously discussed in GitHub PR 866, this fixes
the main source of annoying sanitizer reports in the module.

Prodded by UndefinedBehaviorSanitizer (pointer-overflow).
2025-11-19 18:52:54 +04:00
Sergey Kandaurov
9d04b6630a SSL: fixed build with BoringSSL, broken by 38a701d88. 2025-11-10 23:27:53 +04:00
Sergey Kandaurov
38a701d88b SSL: ngx_ssl_set_client_hello_callback() error handling.
The function interface is changed to follow a common approach
to other functions used to setup SSL_CTX, with an exception of
"ngx_conf_t *cf" since it is not bound to nginx configuration.

This is required to report and propagate SSL_CTX_set_ex_data()
errors, as reminded by Coverity (CID 1668589).
2025-11-10 20:01:28 +04:00
Thierry Bastian
ac99f2808b Configure: MSVC compatibility with PCRE2 10.47. 2025-11-06 15:34:58 +04:00
Sergey Kandaurov
a386df6b23 Version bump. 2025-11-06 15:34:58 +04:00
Andrew Clayton
99312be10c Configure: ensure we get the "built by ..." line in nginx -V.
For certain compilers we embed the compiler version used to build nginx
in the binary, retrievable via 'nginx -V', e.g.

  $ ./objs/nginx -V
  ...
  built by gcc 15.2.1 20250808 (Red Hat 15.2.1-1) (GCC)
  ...

However if the CFLAGS environment variable is set this would be omitted.

This is due to the compiler specific auto/cc files not being run when
the CFLAGS environment variable is set, this is so entities can set
their own compiler flags, and thus the NGX_COMPILER variable isn't set.

Nonetheless it is a useful thing to have so re-work the auto scripts to
move the version gathering out of the individual auto/cc/$NGX_CC_NAME
files and merge them into auto/cc/name.

Link: <https://github.com/nginx/nginx/issues/878>
2025-11-04 16:11:53 +00:00
Roman Arutyunyan
fd0848bdd3 nginx-1.29.3-RELEASE release-1.29.3 2025-10-28 16:05:10 +04:00
Roman Arutyunyan
65c0b2e770 Modules compatibility: increased compat section size. 2025-10-28 16:00:54 +04:00
Roman Arutyunyan
f04e2b7f6e Fixed compilation warnings on Windows after c93a0c48af. 2025-10-28 12:11:21 +04:00
Roman Semenov
ce30a1cb0d OCSP: fixed invalid type for the 'ssl_ocsp' directive. 2025-10-27 15:05:36 +04:00
Roman Arutyunyan
c93a0c48af Headers filter: inheritance control for add_header and add_trailer.
The new directives add_header_inherit and add_trailer_inherit allow
to alter inheritance rules for the values specified in the add_header
and add_trailer directives in a convenient way.

The "merge" parameter enables appending the values from the previous level
to the current level values.

The "off" parameter cancels inheritance of the values from the previous
configuration level, similar to add_header "" (2194e75bb).

The "on" parameter (default) enables the standard inheritance behaviour,
which is to inherit values from the previous level only if there are no
directives on the current level.

The inheritance rules themselves are inherited in a standard way.  Thus,
for example, "add_header_inherit merge;" specified at the top level will
be inherited in all nested levels recursively unless redefined below.
2025-10-25 19:46:20 +04:00
Dmitry Plotnikov
ac72ca60c7 Geo: the "volatile" parameter.
Similar to map's volatile parameter, creates a non-cacheable geo variable.
2025-10-24 15:06:54 -07:00
Sergey Kandaurov
71f8eb52b7 SSL: $ssl_sigalg, $ssl_client_sigalg.
Variables contain the IANA name of the signature scheme[1] used to sign
the TLS handshake.

Variables are only meaningful when using OpenSSL 3.5 and above, with older
versions they are empty.  Moreover, since this data isn't stored in a
serialized session, variables are only available for new sessions.

[1] https://www.iana.org/assignments/tls-parameters/tls-parameters.xhtml

Requested by willmafh.
2025-10-24 18:22:32 +04:00
Roman Arutyunyan
364a94ecec Upstream: reset local address in case of error.
After f10bc5a763 the address was set to NULL only when local address was
not specified at all.  In case complex value evaluated to an empty or
invalid string, local address remained unchanged.  Currenrly this is not
a problem since the value is only set once.  This change is a preparation
for being able to change the local address after initial setting.
2025-10-24 17:49:04 +04:00
Roman Arutyunyan
42ca3a4576 CONNECT method support for HTTP/1.1.
The change allows modules to use the CONNECT method with HTTP/1.1 requests.
To do so, they need to set the "allow_connect" flag in the core server
configuration.
2025-10-23 18:40:05 +04:00
Roman Arutyunyan
c8c7beb96f Added $request_port and $is_request_port variables.
The $request_port variable contains the port passed by the client in the
request line (for HTTP/1.x) or ":authority" pseudo-header (for HTTP/2 and
HTTP/3).  If the request line contains no host, or ":authority" is missing,
then $request_port is taken from the "Host" header, similar to the $host
variable.

The $is_request_port variable contains ":" if $request_port is non-empty,
and is empty otherwise.
2025-10-23 18:40:05 +04:00
Sergey Kandaurov
78d1ab5a2c SSL: support for compressed server certificates with BoringSSL.
BoringSSL/AWS-LC provide two callbacks for each compression algorithm,
which may be used to compress and decompress certificates in runtime.
This change implements compression support with zlib, as enabled with
the ssl_certificate_compression directive.  Compressed certificates
are stored in certificate exdata and reused in subsequent connections.

Notably, AWS-LC saves an X509 pointer in SSL connection, which allows
to use it from SSL_get_certificate() for caching purpose.  In contrast,
BoringSSL reconstructs X509 on-the-fly, though given that it doesn't
support multiple certificates, always replacing previously configured
certificates, we use the last configured one from ssl->certs, instead.
2025-10-08 19:56:41 +04:00
Sergey Kandaurov
25b03d6500 SSL: disabled using certificate compression with OCSP stapling.
OCSP response in TLSv1.3 is sent in the Certificate message.  This
is incompatible with pre-compression of the configured certificates.
2025-10-08 19:56:41 +04:00
Sergey Kandaurov
f5a989cda2 Updated OpenSSL and PCRE used for win32 builds. 2025-10-08 19:56:41 +04:00
Sergey Kandaurov
3494f25c3e Version bump. 2025-10-08 19:56:41 +04:00