summaryrefslogtreecommitdiffhomepage
path: root/src (follow)
AgeCommit message (Collapse)AuthorFilesLines
2026-02-04Upstream: reinit upstream after reading bad response.Roman Arutyunyan2-1/+5
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-04Upstream: detect premature plain text response from SSL backend.Roman Arutyunyan1-0/+9
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-04Win32: fixed C4319 warning with MSVC 2022 x86.Aleksei Bavshin1-1/+1
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.
2026-02-04Version bump.Roman Arutyunyan1-2/+2
2025-12-23Proxy: 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-12-23HTTP/2: extended guard for NULL buffer and zero length.Sergey Kandaurov1-6/+5
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-12-23OCSP: fixed invalid type for the 'ssl_ocsp' directive.Roman Semenov2-2/+2
2025-12-23SSL: fixed "key values mismatch" with object cache inheritance.Sergey Kandaurov2-12/+63
In rare cases, it was possible to get into this error state on reload with improperly updated file timestamps for certificate and key pairs. The fix is to retry on X509_R_KEY_VALUES_MISMATCH, similar to 5d5d9adcc. Additionally, loading SSL certificate is updated to avoid certificates discarded on retry to appear in ssl->certs and in extra chain.
2025-12-23Mail: xtext encoding (RFC 3461) in XCLIENT LOGIN.Sergey Kandaurov3-4/+43
The XCLIENT command uses xtext encoding for attribute values, as specified in https://www.postfix.org/XCLIENT_README.html. Reported by Igor Morgenstern of Aisle Research.
2025-12-23Upstream: overflow detection in Cache-Control delta-seconds.Sergey Kandaurov1-34/+47
Overflowing calculations are now aligned to the greatest positive integer as specified in RFC 9111, Section 1.2.2.
2025-12-23Fixed inaccurate index directive error report.willmafh1-1/+1
2025-12-23Mail: reset stale auth credentials with "smtp_auth none;".Sergey Kandaurov2-1/+7
They might be reused in a session if an SMTP client proceeded unauthenticated after previous invalid authentication attempts. This could confuse an authentication server when passing stale credentials along with "Auth-Method: none". The condition to send the "Auth-Salt" header is similarly refined.
2025-12-23Mail: improved error handling in plain/login/cram-md5 auth methods.Sergey Kandaurov1-16/+22
Previously, login and password storage could be left in inconsistent state in a session after decoding errors.
2025-12-23Auth basic: fixed file descriptor leak on memory allocation error.Sergey Kandaurov1-1/+2
Found by Coverity (CID 1662016).
2025-12-23HTTP/2: fixed handling of the ":authority" header.Sergey Kandaurov1-15/+105
Previously, it misused the Host header processing resulting in 400 (Bad Request) errors for a valid request that contains both ":authority" and Host headers with the same value, treating it after 37984f0be as if client sent more than one Host header. Such an overly strict handling violates RFC 9113. The fix is to process ":authority" as a distinct header, similarly to processing an authority component in the HTTP/1.x request line. This allows to disambiguate and compare Host and ":authority" values after all headers were processed. With this change, the ngx_http_process_request_header() function can no longer be used here, certain parts were inlined similar to the HTTP/3 module. To provide compatibility for misconfigurations that use $http_host to return the value of the ":authority" header, the Host header, if missing, is now reconstructed from ":authority".
2025-12-23HTTP/2: factored out constructing the Host header.Sergey Kandaurov1-39/+48
No functional changes.
2025-12-23HTTP/3: fixed handling of :authority and Host with port.Roman Arutyunyan1-5/+8
RFC 9114, Section 4.3.1. specifies a restriction for :authority and Host coexistence in an HTTP/3 request: : If both fields are present, they MUST contain the same value. Previously, this restriction was correctly enforced only for portless values. When Host contained a port, the request failed as if :authority and Host were different, regardless of :authority presence. This happens because the value of r->headers_in.server used for :authority has port stripped. The fix is to use r->host_start / r->host_end instead.
2025-12-23HTTP/3: fixed potential type overflow in string literal parser.Sergey Kandaurov1-0/+6
This might happen for Huffman encoded string literals as the result of length expansion. Notably, the maximum length of string literals is already limited with the "large_client_header_buffers" directive, so this was only possible with nonsensically large configured limits.
2025-12-23Events: compatibility with NetBSD 10.0 in kqueue.Sergey Kandaurov1-2/+2
The kevent udata field was changed from intptr_t to "void *", similar to other BSDs and Darwin. The NGX_KQUEUE_UDATA_T macro is adjusted to reflect that change, fixing -Werror=int-conversion errors.
2025-12-23Configure: set NGX_KQUEUE_UDATA_T at compile time.Sergey Kandaurov1-0/+9
The NGX_KQUEUE_UDATA_T macro is used to compensate the incompatible kqueue() API in NetBSD, it doesn't really belong to feature tests. The change limits the macro visibility to the kqueue event module. Moving from autotests also simplifies testing a particular NetBSD version as seen in a subsequent change.
2025-12-23Events: fixed -Wzero-as-null-pointer-constant warnings in kqueue.Sergey Kandaurov1-2/+2
The kevent udata field is special in that we maintain compatibility with NetBSD versions that predate using the "void *" type. The fix is to cast to intermediate uintptr_t that is casted back to "void *" where appropriate.
2025-12-23SSL: fixed testing OPENSSL_VERSION_NUMBER for OpenSSL 3.0+.Sergey Kandaurov2-2/+2
Prior to OpenSSL 3.0, OPENSSL_VERSION_NUMBER used the following format: MNNFFPPS: major minor fix patch status Where the status nibble (S) has 0+ for development and f for release. The format was changed in OpenSSL 3.0.0, where it is always zero: MNN00PP0: major minor patch
2025-12-23SSL: SSL_group_to_name() compatibility macro.Sergey Kandaurov2-12/+5
No functional changes.
2025-12-23Use NULL instead of 0 for null pointer constant.Andrew Clayton6-6/+6
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-12-23Use NGX_CONF_OK in some function return checks.Andrew Clayton11-11/+11
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-12-23QUIC: do not block ACKs by congestion control.Sergey Kandaurov1-7/+17
Previously, it was not possible to send acknowledgments if the congestion window was limited or temporarily exceeded, such as after sending a large response or MTU probe. If ACKs were not received from the peer for some reason to update the in-flight bytes counter below the congestion window, this might result in a stalled connection. The fix is to send ACKs regardless of congestion control. This meets RFC 9002, Section 7: : Similar to TCP, packets containing only ACK frames do not count : toward bytes in flight and are not congestion controlled. This is a simplified implementation to send ACK frames from the head of the queue. This was made possible after 6f5f17358. Reported in trac ticket #2621 and subsequently by Vladimir Homutov: https://mailman.nginx.org/pipermail/nginx-devel/2025-April/ZKBAWRJVQXSZ2ISG3YJAF3EWMDRDHCMO.html
2025-12-23SSL: fixed build with OPENSSL_NO_DH.Sergey Kandaurov2-0/+6
2025-12-23SSL: fixed build with OPENSSL_NO_DEPRECATED.Sergey Kandaurov1-0/+11
2025-12-23Core: improved NGX_ALIGNMENT detection on some x86_64 platforms.Aleksei Bavshin1-1/+1
Previously, the default pool alignment used sizeof(unsigned long), with the expectation that this would match to a platform word size. Certain 64-bit platforms prove this assumption wrong by keeping the 32-bit long type, which is fully compliant with the C standard. This introduces a possibility of suboptimal misaligned access to the data allocated with ngx_palloc() on the affected platforms, which is addressed here by changing the default NGX_ALIGNMENT to a pointer size. As we override the detection in auto/os/conf for all the machine types except x86, and Unix-like 64-bit systems prefer the 64-bit long, the impact of the change should be limited to Win64 x64.
2025-12-23Version bump.Sergey Kandaurov1-2/+2
2025-04-23HTTP/3: fixed NGX_HTTP_V3_VARLEN_INT_LEN value.Roman Arutyunyan1-1/+1
After fixing ngx_http_v3_encode_varlen_int() in 400eb1b628, NGX_HTTP_V3_VARLEN_INT_LEN retained the old value of 4, which is insufficient for the values over 1073741823 (1G - 1). The NGX_HTTP_V3_VARLEN_INT_LEN macro is used in ngx_http_v3_uni.c to format stream and frame types. Old buffer size is enough for formatting this data. Also, the macro is used in ngx_http_v3_filter_module.c to format output chunks and trailers. Considering output_buffers and proxy_buffer_size are below 1G in all realistic scenarios, the old buffer size is enough here as well.
2025-04-23Fixed -Wunterminated-string-initialization with gcc15.Roman Arutyunyan2-8/+11
2025-04-23Stable branch.Sergey Kandaurov1-2/+2
2025-04-15QUIC: dynamic packet threshold.Roman Arutyunyan1-9/+39
RFC 9002, Section 6.1.1 defines packet reordering threshold as 3. Testing shows that such low value leads to spurious packet losses followed by congestion window collapse. The change implements dynamic packet threshold detection based on in-flight packet range. Packet threshold is defined as half the number of in-flight packets, with mininum value of 3. Also, renamed ngx_quic_lost_threshold() to ngx_quic_time_threshold() for better compliance with RFC 9002 terms.
2025-04-15QUIC: optimized connection frame threshold.Roman Arutyunyan3-1/+6
Previosly the threshold was hardcoded at 10000. This value is too low for high BDP networks. For example, if all frames are STREAM frames, and MTU is 1500, the upper limit for congestion window would be roughly 15M (10000 * 1500). With 100ms RTT it's just a 1.2Gbps network (15M * 10 * 8). In reality, the limit is even lower because of other frame types. Also, the number of frames that could be used simultaneously depends on the total amount of data buffered in all server streams, and client flow control. The change sets frame threshold based on max concurrent streams and stream buffer size, the product of which is the maximum number of in-flight stream data in all server streams at any moment. The value is divided by 2000 to account for a typical MTU 1500 and the fact that not all frames are STREAM frames.
2025-04-15QUIC: CUBIC congestion control.Roman Arutyunyan4-12/+185
2025-04-15QUIC: ignore congestion control when sending MTU probes.Roman Arutyunyan1-0/+1
If connection is network-limited, MTU probes have little chance of being sent since congestion window is almost always full. As a result, PMTUD may not be able to reach the real MTU and the connection may operate with a reduced MTU. The solution is to ignore the congestion window. This may lead to a temporary increase in in-flight count beyond congestion window.
2025-04-15QUIC: do not shrink congestion window after losing an MTU probe.Roman Arutyunyan3-0/+10
As per RFC 9000, Section 14.4: Loss of a QUIC packet that is carried in a PMTU probe is therefore not a reliable indication of congestion and SHOULD NOT trigger a congestion control reaction.
2025-04-15QUIC: do not increase underutilized congestion window.Roman Arutyunyan4-1/+37
As per RFC 9002, Section 7.8, congestion window should not be increased when it's underutilized.
2025-04-15QUIC: all-levels commit and revert functions.Roman Arutyunyan1-43/+53
Previously, these functions operated on a per-level basis. This however resulted in excessive logging of in_flight and will also led to extra work detecting underutilized congestion window in the followup patches.
2025-04-15QUIC: ngx_msec_t overflow protection.Roman Arutyunyan1-8/+14
On some systems the value of ngx_current_msec is derived from monotonic clock, for which the following is defined by POSIX: For this clock, the value returned by clock_gettime() represents the amount of time (in seconds and nanoseconds) since an unspecified point in the past. As as result, overflow protection is needed when comparing two ngx_msec_t. The change adds such protection to the ngx_quic_detect_lost() function.
2025-04-15QUIC: prevent spurious congestion control recovery mode.Roman Arutyunyan3-14/+44
Since recovery_start field was initialized with ngx_current_msec, all congestion events that happened within the same millisecond or cycle iteration, were treated as in recovery mode. Also, when handling persistent congestion, initializing recovery_start with ngx_current_msec resulted in treating all sent packets as in recovery mode, which violates RFC 9002, see example in Appendix B.8. While here, also fixed recovery_start wrap protection. Previously it used 2 * max_idle_timeout time frame for all sent frames, which is not a reliable protection since max_idle_timeout is unrelated to congestion control. Now recovery_start <= now condition is enforced. Note that recovery_start wrap is highly unlikely and can only occur on a 32-bit system if there are no congestion events for 24 days.
2025-04-15QUIC: use path MTU in congestion window computations.Roman Arutyunyan3-8/+8
As per RFC 9002, Section B.2, max_datagram_size used in congestion window computations should be based on path MTU.
2025-04-15HTTP/3: graceful shutdown on keepalive timeout expiration.Roman Arutyunyan1-1/+1
Previously, the expiration caused QUIC connection finalization even if there are application-terminated streams finishing sending data. Such finalization terminated these streams. An easy way to trigger this is to request a large file from HTTP/3 over a small MTU. In this case keepalive timeout expiration may abruptly terminate the request stream.
2025-04-15QUIC: graph-friendly congestion control logging.Roman Arutyunyan1-19/+25
Improved logging for simpler data extraction for plotting congestion window graphs. In particular, added current milliseconds number from ngx_current_msec. While here, simplified logging text and removed irrelevant data.
2025-04-10SSL: external groups support in $ssl_curve and $ssl_curves.Sergey Kandaurov1-5/+30
Starting with OpenSSL 3.0, groups may be added externally with pluggable KEM providers. Using SSL_get_negotiated_group(), which makes lookup in a static table with known groups, doesn't allow to list such groups by names leaving them in hex. Adding X25519MLKEM768 to the default group list in OpenSSL 3.5 made this problem more visible. SSL_get0_group_name() and, apparently, SSL_group_to_name() allow to resolve such provider-implemented groups, which is also "generally preferred" over SSL_get_negotiated_group() as documented in OpenSSL git commit 93d4f6133f. This change makes external groups listing by name using SSL_group_to_name() available since OpenSSL 3.0. To preserve "prime256v1" naming for the group 0x0017, and to avoid breaking BoringSSL and older OpenSSL versions support, it is used supplementary for a group that appears to be unknown. See https://github.com/openssl/openssl/issues/27137 for related discussion.
2025-04-10Upstream: fixed passwords support for dynamic certificates.Sergey Kandaurov6-43/+144
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-02-26SSL: removed stale comments.Sergey Kandaurov2-4/+0
It appears to be a relic from prototype locking removed in b0b7b5a35.