summaryrefslogtreecommitdiffhomepage
path: root/src/http/modules (follow)
AgeCommit message (Collapse)AuthorFilesLines
2026-02-23Mp4: validate sync sample values in stss atom.CodeByMoriarty1-13/+25
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-17SCGI: fixed passing CONTENT_LENGTH in unbuffered mode.Sergey Kandaurov1-4/+2
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-12Improved $cookie_ evaluation.Vadim Zhestikov1-2/+2
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-11Proxy: fixed HTTP/2 upstream with caching enabled.Roman Arutyunyan1-2/+5
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-01-29Proxy: fixed sending HTTP/2 buffered request body on next upstream.Sergey Kandaurov1-0/+2
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-21Range filter: reasonable limit on multiple ranges.Sergey Kandaurov1-1/+16
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-15Uwsgi: ensure HTTP_HOST is set to the requested target host.Andrew Clayton1-1/+11
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-15SCGI: ensure HTTP_HOST is set to the requested target host.Andrew Clayton1-1/+11
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-15FastCGI: ensure HTTP_HOST is set to the requested target host.Andrew Clayton1-1/+11
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
2025-12-08Proxy: cache support for HTTP/2.Zhidao HONG1-25/+52
2025-12-08Proxy: buffering support for HTTP/2.Zhidao HONG1-0/+142
2025-12-08Proxy: extracted control frame and skip functions for HTTP/2.Zhidao HONG1-192/+150
2025-12-08Proxy: extracted ngx_http_proxy_v2_process_frames() function.Zhidao HONG1-72/+93
2025-12-08Proxy: added HTTP/2 proxy module.Zhidao HONG3-2/+4027
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-08Proxy: refactored for HTTP/2 support.Roman Arutyunyan2-107/+182
2025-12-06Disabled bare LF in chunked transfer encoding.Sergey Kandaurov1-1/+1
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-01Add basic ECH shared-mode via OpenSSL.sftcd2-0/+22
2025-11-26Proxy: fixed segfault in URI change.Sergey Kandaurov1-3/+4
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-10SSL: ngx_ssl_set_client_hello_callback() error handling.Sergey Kandaurov1-1/+3
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-10-28Fixed compilation warnings on Windows after c93a0c48af87.Roman Arutyunyan1-2/+2
2025-10-27OCSP: fixed invalid type for the 'ssl_ocsp' directive.Roman Semenov1-1/+1
2025-10-25Headers filter: inheritance control for add_header and add_trailer.Roman Arutyunyan1-4/+70
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-24Geo: the "volatile" parameter.Dmitry Plotnikov1-0/+12
Similar to map's volatile parameter, creates a non-cacheable geo variable.
2025-10-24SSL: $ssl_sigalg, $ssl_client_sigalg.Sergey Kandaurov1-0/+6
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-23CONNECT method support for HTTP/1.1.Roman Arutyunyan1-1/+3
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-08SSL: disabled using certificate compression with OCSP stapling.Sergey Kandaurov1-1/+7
OCSP response in TLSv1.3 is sent in the Certificate message. This is incompatible with pre-compression of the configured certificates.
2025-09-25SNI: using the ClientHello callback.Sergey Kandaurov1-1/+5
The change introduces an SNI based virtual server selection during early ClientHello processing. The callback is available since OpenSSL 1.1.1; for older OpenSSL versions, the previous behaviour is kept. Using the ClientHello callback sets a reasonable processing order for the "server_name" TLS extension. Notably, session resumption decision now happens after applying server configuration chosen by SNI, useful with enabled verification of client certificates, which brings consistency with BoringSSL behaviour. The change supersedes and reverts a fix made in 46b9f5d38 for TLSv1.3 resumed sessions. In addition, since the callback is invoked prior to the protocol version negotiation, this makes it possible to set "ssl_protocols" on a per-virtual server basis. To keep the $ssl_server_name variable working with TLSv1.2 resumed sessions, as previously fixed in fd97b2a80, a limited server name callback is preserved in order to acknowledge the extension. Note that to allow third-party modules to properly chain the call to ngx_ssl_client_hello_callback(), the servername callback function is passed through exdata.
2025-09-18Fixed inaccurate index directive error report.willmafh1-1/+1
2025-08-11Auth basic: fixed file descriptor leak on memory allocation error.Sergey Kandaurov1-1/+2
Found by Coverity (CID 1662016).
2025-08-03SSL: support for compressed server certificates with OpenSSL.Sergey Kandaurov2-0/+19
The ssl_certificate_compression directive allows to send compressed server certificates. In OpenSSL, they are pre-compressed on startup. To simplify configuration, the SSL_OP_NO_TX_CERTIFICATE_COMPRESSION option is automatically cleared if certificates were pre-compressed. SSL_CTX_compress_certs() may return an error in legitimate cases, e.g., when none of compression algorithms is available or if the resulting compressed size is larger than the original one, thus it is silently ignored. Certificate compression is supported in Chrome with brotli only, in Safari with zlib only, and in Firefox with all listed algorithms. It is supported since Ubuntu 24.10, which has OpenSSL with enabled zlib and zstd support. The actual list of algorithms supported in OpenSSL depends on how the library was configured; it can be brotli, zlib, zstd as listed in RFC 8879.
2025-06-23Upstream: fixed reinit request with gRPC and Early Hints.Sergey Kandaurov2-3/+22
The gRPC module context has connection specific state, which can be lost after request reinitialization when it comes to processing early hints. The fix is to do only a portion of u->reinit_request() implementation required after processing early hints, now inlined in modules. Now NGX_HTTP_UPSTREAM_EARLY_HINTS is returned from u->process_header() for early hints. When reading a cached response, this code is mapped to NGX_HTTP_UPSTREAM_INVALID_HEADER to indicate invalid header format.
2025-06-21Use NULL instead of 0 for null pointer constant.Andrew Clayton2-2/+2
There were a few random places where 0 was being used as a null pointer constant. We have a NULL macro for this very purpose, use it. There is also some interest in actually deprecating the use of 0 as a null pointer constant in C. This was found with -Wzero-as-null-pointer-constant which was enabled for C in GCC 15 (not enabled with Wall or Wextra... yet). Link: <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117059>
2025-06-21Use NGX_CONF_OK in some function return checks.Andrew Clayton10-10/+10
The functions ngx_http_merge_types() & ngx_conf_merge_path_value() return either NGX_CONF_OK aka NULL aka ((void *)0) (probably) or NGX_CONF_ERROR aka ((void *)-1). They don't return an integer constant which is what NGX_OK aka (0) is. Lets use the right thing in the function return check. This was found with -Wzero-as-null-pointer-constant which was enabled for C in GCC 15 (not enabled with Wall or Wextra... yet). Link: <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117059>
2025-06-19Upstream: early hints support.Roman Arutyunyan2-7/+28
The change implements processing upstream early hints response in ngx_http_proxy_module and ngx_http_grpc_module. A new directive "early_hints" enables sending early hints to the client. By default, sending early hints is disabled. Example: map $http_sec_fetch_mode $early_hints { navigate $http2$http3; } early_hints $early_hints; proxy_pass http://example.com;
2025-04-10Upstream: fixed passwords support for dynamic certificates.Sergey Kandaurov3-33/+27
Passwords were not preserved in optimized SSL contexts, the bug had appeared in d791b4aab (1.23.1), as in the following configuration: server { proxy_ssl_password_file password; proxy_ssl_certificate $ssl_server_name.crt; proxy_ssl_certificate_key $ssl_server_name.key; location /original/ { proxy_pass https://u1/; } location /optimized/ { proxy_pass https://u2/; } } The fix is to always preserve passwords, by copying to the configuration pool, if dynamic certificates are used. This is done as part of merging "ssl_passwords" configuration. To minimize the number of copies, a preserved version is then used for inheritance. A notable exception is inheritance of preserved empty passwords to the context with statically configured certificates: server { proxy_ssl_certificate $ssl_server_name.crt; proxy_ssl_certificate_key $ssl_server_name.key; location / { proxy_pass ...; proxy_ssl_certificate example.com.crt; proxy_ssl_certificate_key example.com.key; } } In this case, an unmodified version (NULL) of empty passwords is set, to allow reading them from the password prompt on nginx startup. As an additional optimization, a preserved instance of inherited configured passwords is set to the previous level, to inherit it to other contexts: server { proxy_ssl_password_file password; location /1/ { proxy_pass https://u1/; proxy_ssl_certificate $ssl_server_name.crt; proxy_ssl_certificate_key $ssl_server_name.key; } location /2/ { proxy_pass https://u2/; proxy_ssl_certificate $ssl_server_name.crt; proxy_ssl_certificate_key $ssl_server_name.key; } }
2025-04-09Charset filter: improved validation of charset_map with utf-8.Sergey Kandaurov1-0/+6
It was possible to write outside of the buffer used to keep UTF-8 decoded values when parsing conversion table configuration. Since this happened before UTF-8 decoding, the fix is to check in advance if character codes are of more than 3-byte sequence. Note that this is already enforced by a later check for ngx_utf8_decode() decoded values for 0xffff, which corresponds to the maximum value encoded as a valid 3-byte sequence, so the fix does not affect the valid values. Found with AddressSanitizer. Fixes GitHub issue #529.
2025-03-10Slice filter: improved memory allocation error handling.Sergey Kandaurov1-2/+2
As uncovered by recent addition in slice.t, a partially initialized context, coupled with HTTP 206 response from stub backend, might be accessed in the next slice subrequest. Found by bad memory allocator simulation.
2025-01-17Upstream: caching certificates and certificate keys with variables.Sergey Kandaurov3-0/+318
Caching is enabled with proxy_ssl_certificate_cache and friends. Co-authored-by: Aleksei Bavshin <a.bavshin@nginx.com>
2025-01-17SSL: caching certificates and certificate keys with variables.Sergey Kandaurov2-0/+108
A new directive "ssl_certificate_cache max=N [valid=time] [inactive=time]" enables caching of SSL certificate chain and secret key objects specified by "ssl_certificate" and "ssl_certificate_key" directives with variables. Co-authored-by: Aleksei Bavshin <a.bavshin@nginx.com>
2025-01-16Slice filter: log the expected range in case of range error.Daniel Vasquez Lopez1-2/+2
2025-01-09Gzip: compatibility with recent zlib-ng 2.2.x versions.Sergey Kandaurov1-3/+5
It now uses 5/4 times more memory for the pending buffer. Further, a single allocation is now used, which takes additional 56 bytes for deflate_allocs in 64-bit mode aligned to 16, to store sub-allocation pointers, and the total allocation size now padded up to 128 bytes, which takes theoretically 200 additional bytes in total. This fits though into "4 * (64 + sizeof(void*))" additional space for ZALLOC used in zlib-ng 2.1.x versions. The comment was updated to reflect this.
2024-11-25Upstream: disallow empty path in proxy_store and friends.Sergey Kandaurov4-0/+20
Renaming a temporary file to an empty path ("") returns NGX_ENOPATH with a subsequent ngx_create_full_path() to create the full path. This function skips initial bytes as part of path separator lookup, which causes out of bounds access on short strings. The fix is to avoid renaming a temporary file to an obviously invalid path, as well as explicitly forbid such syntax for literal values. Although Coverity reports about potential type underflow, it is not actually possible because the terminating '\0' is always included. Notably, the run-time check is sufficient enough for Win32 as well. Other short invalid values result either in NGX_ENOENT or NGX_EEXIST and "MoveFile() .. failed" critical log messages, which involves a separate error handling. Prodded by Coverity (CID 1605485).
2024-11-22SSL: a new macro to set default protocol versions.Sergey Kandaurov4-36/+4
This simplifies merging protocol values after ea15896 and ebd18ec. Further, as outlined in ebd18ec18, for libraries preceeding TLSv1.2+ support, only meaningful versions TLSv1 and TLSv1.1 are set by default. While here, fixed indentation.
2024-11-21Mp4: prevent chunk index underflow.Roman Arutyunyan1-0/+6
When cropping stsc atom, it's assumed that chunk index is never 0. Based on this assumption, start_chunk and end_chunk are calculated by subtracting 1 from it. If chunk index is zero, start_chunk or end_chunk may underflow, which will later trigger "start/end time is out mp4 stco chunks" error. The change adds an explicit check for zero chunk index to avoid underflow and report a proper error. Zero chunk index is explicitly banned in ISO/IEC 14496-12, 8.7.4 Sample To Chunk Box. It's also implicitly banned in QuickTime File Format specification. Description of chunk offset table references "Chunk 1" as the first table element.
2024-11-21Mp4: unordered stsc chunks error for the final chunk.Roman Arutyunyan1-0/+7
Currently an error is triggered if any of the chunk runs in stsc are unordered. This however does not include the final chunk run, which ends with trak->chunks + 1. The previous chunk index can be larger leading to a 32-bit overflow. This could allow to skip the validity check "if (start_sample > n)". This could later lead to a large trak->start_chunk/trak->end_chunk, which would be caught later in ngx_http_mp4_update_stco_atom() or ngx_http_mp4_update_co64_atom(). While there are no implications of the validity check being avoided, the change still adds a check to ensure the final chunk run is ordered, to produce a meaningful error and avoid a potential integer overflow.
2024-11-21Mp4: fixed handling an empty run of chunks in stsc atom.Roman Arutyunyan1-1/+4
A specially crafted mp4 file with an empty run of chunks in the stsc atom and a large value for samples per chunk for that run, combined with a specially crafted request, allowed to store that large value in prev_samples and later in trak->end_chunk_samples while in ngx_http_mp4_crop_stsc_data(). Later in ngx_http_mp4_update_stsz_atom() this could result in buffer overread while calculating trak->end_chunk_samples_size. Now the value of samples per chunk specified for an empty run is ignored.
2024-11-12Uwsgi: added create_loc_conf comments.Sergey Kandaurov1-0/+22
2024-11-12SCGI: added create_loc_conf comments.Sergey Kandaurov1-0/+15
2024-11-12FastCGI: fixed create_loc_conf comments after 05b1a8f1e.Sergey Kandaurov1-1/+1
2024-11-11SSL: fixed MSVC compilation after ebd18ec1812b.蕭澧邦4-8/+24
MSVC generates a compilation error in case #if/#endif is used in a macro parameter.