summaryrefslogtreecommitdiffhomepage
path: root/src/http/modules (follow)
AgeCommit message (Collapse)AuthorFilesLines
2024-05-23Optimized chain link usage (ticket #2614).Roman Arutyunyan5-12/+37
Previously chain links could sometimes be dropped instead of being reused, which could result in increased memory consumption during long requests. A similar chain link issue in ngx_http_gzip_filter_module was fixed in da46bfc484ef (1.11.10). Based on a patch by Sangmin Lee.
2024-02-26Rewrite: fixed "return" directive without response text.Piotr Sikora1-0/+1
Previously, the response text wasn't initialized and the rewrite module was sending response body set to NULL. Found with UndefinedBehaviorSanitizer (pointer-overflow). Signed-off-by: Piotr Sikora <piotr@aviatrix.com>
2024-03-18Fixed undefined behaviour with IPv4-mapped IPv6 addresses.Sergey Kandaurov3-4/+4
Previously, it could result when left-shifting signed integer due to implicit integer promotion, such that the most significant bit appeared on the sign bit. In practice, though, this results in the same left value as with an explicit cast, at least on known compilers, such as GCC and Clang. The reason is that in_addr_t, which is equivalent to uint32_t and same as "unsigned int" in ILP32 and LP64 data type models, has the same type width as the intermediate after integer promotion, so there's no side effects such as sign-extension. This explains why adding an explicit cast does not change object files in practice. Found with UndefinedBehaviorSanitizer (shift). Based on a patch by Piotr Sikora.
2024-03-14Geo: fixed uninitialized memory access.Piotr Sikora1-3/+1
While copying ngx_http_variable_value_t structures to geo binary base in ngx_http_geo_copy_values(), and similarly in the stream module, uninitialized parts of these structures are copied as well. These include the "escape" field and possible holes. Calculating crc32 of this data triggers uninitialized memory access. Found with MemorySanitizer. Signed-off-by: Piotr Sikora <piotr@aviatrix.com>
2024-03-22Overhauled some diagnostic messages akin to 1b05b9bbcebf.Sergey Kandaurov2-2/+2
2023-08-31Upstream: fixed handling of Status headers without reason-phrase.Maxim Dounin3-3/+12
Status header with an empty reason-phrase, such as "Status: 404 ", is valid per CGI specification, but looses the trailing space during parsing. Currently, this results in "HTTP/1.1 404" HTTP status line in the response, which violates HTTP specification due to missing trailing space. With this change, only the status code is used from such short Status header lines, so nginx will generate status line itself, with the space and appropriate reason phrase if available. Reported at: https://mailman.nginx.org/pipermail/nginx/2023-August/EX7G4JUUHJWJE5UOAZMO5UD6OJILCYGX.html
2023-06-08SSL: removed the "ssl" directive.Roman Arutyunyan2-82/+1
It has been deprecated since 7270:46c0c7ef4913 (1.15.0) in favour of the "ssl" parameter of the "listen" directive, which has been available since 2224:109849282793 (0.7.14).
2023-05-16HTTP/2: "http2" directive.Roman Arutyunyan1-8/+16
The directive enables HTTP/2 in the current server. The previous way to enable HTTP/2 via "listen ... http2" is now deprecated. The new approach allows to share HTTP/2 and HTTP/0.9-1.1 on the same port. For SSL connections, HTTP/2 is now selected by ALPN callback based on whether the protocol is enabled in the virtual server chosen by SNI. This however only works since OpenSSL 1.0.2h, where ALPN callback is invoked after SNI callback. For older versions of OpenSSL, HTTP/2 is enabled based on the default virtual server configuration. For plain TCP connections, HTTP/2 is now auto-detected by HTTP/2 preface, if HTTP/2 is enabled in the default virtual server. If preface is not matched, HTTP/0.9-1.1 is assumed.
2023-05-11HTTP/3: removed "http3" parameter of "listen" directive.Roman Arutyunyan1-1/+1
The parameter has been deprecated since c851a2ed5ce8.
2023-03-29Merged with the default branch.Sergey Kandaurov9-21/+33
2023-03-27Gzip: compatibility with recent zlib-ng versions.Maxim Dounin1-6/+12
It now uses custom alloc_aligned() wrapper for all allocations, therefore all allocations are larger than expected by (64 + sizeof(void*)). Further, they are seen as allocations of 1 element. Relevant calculations were adjusted to reflect this, and state allocation is now protected with a flag to avoid misinterpreting other allocations as the zlib deflate_state allocation. Further, it no longer forces window bits to 13 on compression level 1, so the comment was adjusted to reflect this.
2023-03-24SSL: enabled TLSv1.3 by default.Maxim Dounin4-8/+12
2023-03-24HTTP/3: fixed OpenSSL compatibility layer initialization.Sergey Kandaurov1-4/+36
SSL context is not present if the default server has neither certificates nor ssl_reject_handshake enabled. Previously, this led to null pointer dereference before it would be caught with configuration checks. Additionally, non-default servers with distinct SSL contexts need to initialize compatibility layer in order to complete a QUIC handshake.
2023-01-28Fixed "zero size buf" alerts with subrequests.Maxim Dounin4-4/+4
Since 4611:2b6cb7528409 responses from the gzip static, flv, and mp4 modules can be used with subrequests, though empty files were not properly handled. Empty gzipped, flv, and mp4 files thus resulted in "zero size buf in output" alerts. While valid corresponding files are not expected to be empty, such files shouldn't result in alerts. Fix is to set b->sync on such empty subrequest responses, similarly to what ngx_http_send_special() does. Additionally, the static module, the ngx_http_send_response() function, and file cache are modified to do the same instead of not sending the response body at all in such cases, since not sending the response body at all is believed to be at least questionable, and might break various filters which do not expect such behaviour.
2023-01-28Style.Maxim Dounin2-3/+3
2023-02-27HTTP/3: "quic" parameter of "listen" directive.Roman Arutyunyan1-11/+18
Now "listen" directve has a new "quic" parameter which enables QUIC protocol for the address. Further, to enable HTTP/3, a new directive "http3" is introduced. The hq-interop protocol is enabled by "http3_hq" as before. Now application protocol is chosen by ALPN. Previously used "http3" parameter of "listen" is deprecated.
2023-02-22QUIC: OpenSSL compatibility layer.Roman Arutyunyan1-3/+13
The change allows to compile QUIC with OpenSSL which lacks BoringSSL QUIC API. This implementation does not support 0-RTT.
2023-01-24Gzip static: ranges support (ticket #2349).Maxim Dounin1-0/+2
In contrast to on-the-fly gzipping with gzip filter, static gzipped representation as returned by gzip_static is persistent, and therefore the same binary representation is available for future requests, making it possible to use range requests. Further, if a gzipped representation is re-generated with different compression settings, it is expected to result in different ETag and different size reported in the Content-Range header, making it possible to safely use range requests anyway. As such, ranges are now allowed for files returned by gzip_static.
2022-12-15Merged with the default branch.Sergey Kandaurov2-1/+29
2022-11-21SSI: handling of subrequests from other modules (ticket #1263).Ciel Zhao2-1/+29
As the SSI parser always uses the context from the main request for storing variables and blocks, that context should always exist for subrequests using SSI, even though the main request does not necessarily have SSI enabled. However, `ngx_http_get_module_ctx(r->main, ...)` is getting NULL in such cases, resulting in the worker crashing SIGSEGV when accessing its attributes. This patch links the first initialized context to the main request, and upgrades it only when main context is initialized.
2022-10-19Mp4: disabled duplicate atoms.Roman Arutyunyan1-0/+147
Most atoms should not appear more than once in a container. Previously, this was not enforced by the module, which could result in worker process crash, memory corruption and disclosure.
2022-10-17SSL: improved validation of ssl_session_cache and ssl_ocsp_cache.Sergey Kandaurov1-2/+2
Now it properly detects invalid shared zone configuration with omitted size. Previously it used to read outside of the buffer boundary. Found with AddressSanitizer.
2022-10-20Merged with the default branch.Sergey Kandaurov2-2/+149
2022-07-15Range filter: clearing of pre-existing Content-Range headers.Maxim Dounin1-0/+13
Some servers might emit Content-Range header on 200 responses, and this does not seem to contradict RFC 9110: as per RFC 9110, the Content-Range header has no meaning for status codes other than 206 and 416. Previously this resulted in duplicate Content-Range headers in nginx responses handled by the range filter. Fix is to clear pre-existing headers.
2022-06-29Upstream: optimized use of SSL contexts (ticket #1234).Maxim Dounin3-21/+177
To ensure optimal use of memory, SSL contexts for proxying are now inherited from previous levels as long as relevant proxy_ssl_* directives are not redefined. Further, when no proxy_ssl_* directives are redefined in a server block, we now preserve plcf->upstream.ssl in the "http" section configuration to inherit it to all servers. Similar changes made in uwsgi, grpc, and stream proxy.
2022-06-14Perl: removed unused variables, forgotten in ef6a3a99a81a.Sergey Kandaurov1-2/+1
2022-07-26Merged with the default branch.Sergey Kandaurov4-21/+190
2022-06-22Merged with the default branch.Sergey Kandaurov20-178/+308
2022-06-07Mp4: fixed potential overflow in ngx_http_mp4_crop_stts_data().Maxim Dounin1-1/+1
Both "count" and "duration" variables are 32-bit, so their product might potentially overflow. It is used to reduce 64-bit start_time variable, and with very large start_time this can result in incorrect seeking. Found by Coverity (CID 1499904).
2022-06-07Upstream: handling of certificates specified as an empty string.Sergey Kandaurov3-6/+9
Now, if the directive is given an empty string, such configuration cancels loading of certificates, in particular, if they would be otherwise inherited from the previous level. This restores previous behaviour, before variables support in certificates was introduced (3ab8e1e2f0f7).
2022-05-30Headers filter: improved memory allocation error handling.Maxim Dounin1-0/+4
2022-05-30Auth request: multiple WWW-Authenticate headers (ticket #485).Maxim Dounin1-3/+8
When using auth_request with an upstream server which returns 401 (Unauthorized), multiple WWW-Authenticate headers from the upstream server response are now properly copied to the response.
2022-05-30Upstream: header handlers can now return parsing errors.Maxim Dounin5-10/+30
With this change, duplicate Content-Length and Transfer-Encoding headers are now rejected. Further, responses with invalid Content-Length or Transfer-Encoding headers are now rejected, as well as responses with both Content-Length and Transfer-Encoding.
2022-05-30Upstream: all known headers in u->headers_in are linked lists now.Maxim Dounin1-0/+2
2022-05-30All known output headers can be linked lists now.Maxim Dounin10-0/+13
The h->next pointer properly provided as NULL in all cases where known output headers are added. Note that there are 3rd party modules which might not do this, and it might be risky to rely on this for arbitrary headers.
2022-05-30Perl: combining unknown headers during $r->header_in() lookup.Maxim Dounin1-40/+44
2022-05-30Perl: all known input headers are handled identically.Maxim Dounin1-20/+2
As all known input headers are now linked lists, these are now handled identically. In particular, this makes it possible to access properly combined values of headers not specifically handled previously, such as "Via" or "Connection".
2022-05-30Reworked multi headers to use linked lists.Maxim Dounin7-82/+51
Multi headers are now using linked lists instead of arrays. Notably, the following fields were changed: r->headers_in.cookies (renamed to r->headers_in.cookie), r->headers_in.x_forwarded_for, r->headers_out.cache_control, r->headers_out.link, u->headers_in.cache_control u->headers_in.cookies (renamed to u->headers_in.set_cookie). The r->headers_in.cookies and u->headers_in.cookies fields were renamed to r->headers_in.cookie and u->headers_in.set_cookie to match header names. The ngx_http_parse_multi_header_lines() and ngx_http_parse_set_cookie_lines() functions were changed accordingly. With this change, multi headers are now essentially equivalent to normal headers, and following changes will further make them equivalent.
2022-05-30Uwsgi: combining headers with identical names (ticket #1724).Maxim Dounin1-6/+51
The uwsgi specification states that "The uwsgi block vars represent a dictionary/hash". This implies that no duplicate headers are expected. Further, provided headers are expected to follow CGI specification, which also requires to combine headers (RFC 3875, section "4.1.18. Protocol-Specific Meta-Variables"): "If multiple header fields with the same field-name are received then the server MUST rewrite them as a single value having the same semantics".
2022-05-30SCGI: combining headers with identical names (ticket #1724).Maxim Dounin1-5/+45
SCGI specification explicitly forbids headers with duplicate names (section "3. Request Format"): "Duplicate names are not allowed in the headers". Further, provided headers are expected to follow CGI specification, which also requires to combine headers (RFC 3875, section "4.1.18. Protocol-Specific Meta-Variables"): "If multiple header fields with the same field-name are received then the server MUST rewrite them as a single value having the same semantics".
2022-05-30FastCGI: combining headers with identical names (ticket #1724).Maxim Dounin1-11/+55
FastCGI responder is expected to receive CGI/1.1 environment variables in the parameters (see section "6.2 Responder" of the FastCGI specification). Obviously enough, there cannot be multiple environment variables with the same name. Further, CGI specification (RFC 3875, section "4.1.18. Protocol-Specific Meta-Variables") explicitly requires to combine headers: "If multiple header fields with the same field-name are received then the server MUST rewrite them as a single value having the same semantics".
2022-01-26HTTP/3: removed draft versions support in ALPN.Sergey Kandaurov1-15/+0
2021-12-21Moved Huffman coding out of HTTP/2.Ruslan Ermilov1-8/+8
ngx_http_v2_huff_decode.c and ngx_http_v2_huff_encode.c are renamed to ngx_http_huff_decode.c and ngx_http_huff_encode.c.
2021-12-24Merged with the default branch.Ruslan Ermilov2-8/+11
2021-12-04HTTP/3: http3_hq directive and NGX_HTTP_V3_HQ macro.Roman Arutyunyan1-18/+23
Listen quic parameter is no longer supported.
2021-12-06HTTP/3: merged ngx_http_quic_module into ngx_http_v3_module.Roman Arutyunyan3-607/+6
2021-12-02HTTP/3: adjusted ALPN macro names to align with 61abb35bb8cf.Sergey Kandaurov2-5/+5
2021-11-17HTTP/3: fixed compilation with QUIC, but without HTTP/3.Roman Arutyunyan1-0/+2
2021-11-11QUIC: reject streams which we could not create.Roman Arutyunyan1-0/+3
The reasons why a stream may not be created by server currently include hitting worker_connections limit and memory allocation error. Previously in these cases the entire QUIC connection was closed and all its streams were shut down. Now the new stream is rejected and existing streams continue working. To reject an HTTP/3 request stream, RESET_STREAM and STOP_SENDING with H3_REQUEST_REJECTED error code are sent to client. HTTP/3 uni streams and Stream streams are not rejected.
2021-11-01SSL: $ssl_curve (ticket #2135).Sergey Kandaurov1-0/+3
The variable contains a negotiated curve used for the handshake key exchange process. Known curves are listed by their names, unknown ones are shown in hex. Note that for resumed sessions in TLSv1.2 and older protocols, $ssl_curve contains the curve used during the initial handshake, while in TLSv1.3 it contains the curve used during the session resumption (see the SSL_get_negotiated_group manual page for details). The variable is only meaningful when using OpenSSL 3.0 and above. With older versions the variable is empty.