summaryrefslogtreecommitdiffhomepage
path: root/src/http/modules/ngx_http_proxy_module.c (follow)
AgeCommit message (Collapse)AuthorFilesLines
2025-04-10Upstream: fixed passwords support for dynamic certificates.Sergey Kandaurov1-11/+9
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-01-17Upstream: caching certificates and certificate keys with variables.Sergey Kandaurov1-0/+106
Caching is enabled with proxy_ssl_certificate_cache and friends. Co-authored-by: Aleksei Bavshin <a.bavshin@nginx.com>
2024-11-25Upstream: disallow empty path in proxy_store and friends.Sergey Kandaurov1-0/+5
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 Kandaurov1-9/+1
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-11SSL: fixed MSVC compilation after ebd18ec1812b.蕭澧邦1-2/+6
MSVC generates a compilation error in case #if/#endif is used in a macro parameter.
2024-10-31SSL: disabled TLSv1 and TLSv1.1 by default.Sergey Kandaurov1-0/+2
TLSv1 and TLSv1.1 are formally deprecated and forbidden to negotiate due to insufficient security reasons outlined in RFC 8996. TLSv1 and TLSv1.1 are disabled in BoringSSL e95b0cad9 and LibreSSL 3.8.1 in the way they cannot be enabled in nginx configuration. In OpenSSL 3.0, they are only permitted at security level 0 (disabled by default). The support is dropped in Chrome 84, Firefox 78, and deprecated in Safari. This change disables TLSv1 and TLSv1.1 by default for OpenSSL 1.0.1 and newer, where TLSv1.2 support is available. For older library versions, which do not have alternatives, these protocol versions remain enabled.
2024-09-13Proxy: proxy_pass_trailers directive.Sergey Kandaurov1-12/+221
The directive allows to pass upstream response trailers to client.
2023-11-25Upstream: variables support in proxy_limit_rate and friends.J Carter1-4/+4
2023-03-24SSL: enabled TLSv1.3 by default.Maxim Dounin1-2/+3
2022-06-29Upstream: optimized use of SSL contexts (ticket #1234).Maxim Dounin1-7/+59
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-07Upstream: handling of certificates specified as an empty string.Sergey Kandaurov1-2/+3
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-30Upstream: header handlers can now return parsing errors.Maxim Dounin1-2/+6
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-30Reworked multi headers to use linked lists.Maxim Dounin1-10/+8
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.
2021-10-18Upstream: fixed logging level of upstream invalid header errors.Maxim Dounin1-1/+1
In b87b7092cedb (nginx 1.21.1), logging level of "upstream sent invalid header" errors was accidentally changed to "info". This change restores the "error" level, which is a proper logging level for upstream-side errors.
2021-10-07Proxy: disabled keepalive on extra data in non-buffered mode.Awdhesh Mathpal1-0/+1
The u->keepalive flag is initialized early if the response has no body (or an empty body), and needs to be reset if there are any extra data, similarly to how it is done in ngx_http_proxy_copy_filter(). Missed in 83c4622053b0.
2021-08-16SSL: ciphers now set before loading certificates (ticket #2035).Maxim Dounin1-6/+6
To load old/weak server or client certificates it might be needed to adjust the security level, as introduced in OpenSSL 1.1.0. This change ensures that ciphers are set before loading the certificates, so security level changes via the cipher string apply to certificate loading.
2021-06-28Improved logging of invalid headers.Maxim Dounin1-3/+5
In 71edd9192f24 logging of invalid headers which were rejected with the NGX_HTTP_PARSE_INVALID_HEADER error was restricted to just the "client sent invalid header line" message, without any attempts to log the header itself. This patch returns logging of the header up to the invalid character and the character itself. The r->header_end pointer is now properly set in all cases to make logging possible. The same logging is also introduced when parsing headers from upstream servers.
2021-06-28Disabled spaces in URIs (ticket #196).Maxim Dounin1-2/+2
From now on, requests with spaces in URIs are immediately rejected rather than allowed. Spaces were allowed in 31e9677b15a1 (0.8.41) to handle bad clients. It is believed that now this behaviour causes more harm than good.
2021-05-06Upstream: variables support in certificates.Maxim Dounin1-25/+37
2021-05-06Changed complex value slots to use NGX_CONF_UNSET_PTR.Maxim Dounin1-11/+9
With this change, it is now possible to use ngx_conf_merge_ptr_value() to merge complex values. This change follows much earlier changes in ngx_conf_merge_ptr_value() and ngx_conf_set_str_array_slot() in 1452:cd586e963db0 (0.6.10) and 1701:40d004d95d88 (0.6.22), and the change in ngx_conf_set_keyval_slot() (7728:485dba3e2a01, 1.19.4). To preserve compatibility with existing 3rd party modules, both NULL and NGX_CONF_UNSET_PTR are accepted for now.
2021-03-05SSL: fixed build by Sun C with old OpenSSL versions.Maxim Dounin1-2/+2
Sun C complains about "statement not reached" if a "return" is followed by additional statements.
2021-03-02Proxy: variables support in "proxy_cookie_flags" flags.Ruslan Ermilov1-26/+63
2021-01-12Upstream: fixed zero size buf alerts on extra data (ticket #2117).Maxim Dounin1-0/+7
After 7675:9afa45068b8f and 7678:bffcc5af1d72 (1.19.1), during non-buffered simple proxying, responses with extra data might result in zero size buffers being generated and "zero size buf" alerts in writer. This bug is similar to the one with FastCGI proxying fixed in 7689:da8d758aabeb. In non-buffered mode, normally the filter function is not called if u->length is already 0, since u->length is checked after each call of the filter function. There is a case when this can happen though: if the response length is 0, and there are pre-read response body data left after reading response headers. As such, a check for u->length is needed at the start of non-buffered filter functions, similar to the one for p->length present in buffered filter functions. Appropriate checks added to the existing non-buffered copy filters in the upstream (used by scgi and uwsgi proxying) and proxy modules.
2020-10-22Upstream: proxy_ssl_conf_command and friends.Maxim Dounin1-0/+36
Similarly to ssl_conf_command, proxy_ssl_conf_command (grpc_ssl_conf_command, uwsgi_ssl_conf_command) can be used to set arbitrary OpenSSL configuration parameters as long as nginx is compiled with OpenSSL 1.0.2 or later, when connecting to upstream servers with SSL. Full list of available configuration commands can be found in the SSL_CONF_cmd manual page (https://www.openssl.org/docs/man1.1.1/man3/SSL_CONF_cmd.html).
2020-10-22Core: ngx_conf_set_keyval_slot() now accepts NGX_CONF_UNSET_PTR.Maxim Dounin1-3/+5
With this change, it is now possible to use ngx_conf_merge_ptr_value() to merge keyval arrays. This change actually follows much earlier changes in ngx_conf_merge_ptr_value() and ngx_conf_set_str_array_slot() in 1452:cd586e963db0 (0.6.10) and 1701:40d004d95d88 (0.6.22). To preserve compatibility with existing 3rd party modules, both NULL and NGX_CONF_UNSET_PTR are accepted for now.
2020-09-29Proxy: error checking for array init, missed in 7716:d6a5e14aa3e4.Maxim Dounin1-1/+3
Found by Coverity (CID 1467637).
2020-09-27Proxy: added the "proxy_cookie_flags" directive.Ruslan Ermilov1-30/+552
2020-09-27Proxy: changed interface of some internal functions.Ruslan Ermilov1-32/+30
This is in preparation for the next change. Also, moved optimization from ngx_http_proxy_rewrite_regex_handler() to ngx_http_proxy_rewrite().
2020-09-27Proxy: strengthen syntax checking for some directives.Ruslan Ermilov1-12/+20
The "false" parameter of the proxy_redirect directive is deprecated. Warning has been emitted since c2230102df6f (0.7.54). The "off" parameter of the proxy_redirect, proxy_cookie_domain, and proxy_cookie_path directives tells nginx not to inherit the configuration from the previous configuration level. Previously, after specifying the directive with the "off" parameter, any other directives were ignored, and syntax checking was disabled. The syntax was enforced to allow either one directive with the "off" parameter, or several directives with other parameters. Also, specifying "proxy_redirect default foo" no longer works like "proxy_redirect default".
2020-07-06Proxy: style.Maxim Dounin1-2/+2
2020-07-06Proxy: detection of data after final chunk.Maxim Dounin1-1/+30
Previously, additional data after final chunk was either ignored (in the same buffer, or during unbuffered proxying) or sent to the client (in the next buffer already if it was already read from the socket). Now additional data are properly detected and ignored in all cases. Additionally, a warning is now logged and keepalive is disabled in the connection.
2020-07-06Proxy: drop extra data sent by upstream.Maxim Dounin1-9/+43
Previous behaviour was to pass everything to the client, but this seems to be suboptimal and causes issues (ticket #1695). Fix is to drop extra data instead, as it naturally happens in most clients.
2019-03-03SSL: fixed potential leak on memory allocation errors.Maxim Dounin1-0/+1
If ngx_pool_cleanup_add() fails, we have to clean just created SSL context manually, thus appropriate call added. Additionally, ngx_pool_cleanup_add() moved closer to ngx_ssl_create() in the ngx_http_ssl_module, to make sure there are no leaks due to intermediate code.
2018-10-03Upstream: proxy_socket_keepalive and friends.Vladimir Homutov1-0/+11
The directives enable the use of the SO_KEEPALIVE option on upstream connections. By default, the value is left unchanged.
2018-07-17Fixed invalid access to location defined as an empty string.Ruslan Ermilov1-1/+1
2018-07-17SSL: save sessions for upstream peers using a callback function.Sergey Kandaurov1-0/+7
In TLSv1.3, NewSessionTicket messages arrive after the handshake and can come at any time. Therefore we use a callback to save the session when we know about it. This approach works for < TLSv1.3 as well. The callback function is set once per location on merge phase. Since SSL_get_session() in BoringSSL returns an unresumable session for TLSv1.3, peer save_session() methods have been updated as well to use a session supplied within the callback. To preserve API, the session is cached in c->ssl->session. It is preferably accessed in save_session() methods by ngx_ssl_get_session() and ngx_ssl_get0_session() wrappers.
2018-05-07Silenced -Wcast-function-type warnings (closes #1546).Sergey Kandaurov1-1/+2
Cast to intermediate "void *" to lose compiler knowledge about the original type and pass the warning. This is not a real fix but rather a workaround. Found by gcc8.
2018-03-19Upstream: fixed comments after 13f8dec720b5.Ruslan Ermilov1-2/+2
The fields "uri", "location", and "url" from ngx_http_upstream_conf_t moved to ngx_http_proxy_loc_conf_t and ngx_http_proxy_vars_t, reflect this change in create_loc_conf comments.
2018-02-28Generic subrequests in memory.Roman Arutyunyan1-30/+0
Previously, only the upstream response body could be accessed with the NGX_HTTP_SUBREQUEST_IN_MEMORY feature. Now any response body from a subrequest can be saved in a memory buffer. It is available as a single buffer in r->out and the buffer size is configured by the subrequest_output_buffer_size directive. Upstream, proxy and fastcgi code used to handle the old-style feature is removed.
2017-11-20Proxy: escape explicit space in URI in default cache key.Roman Arutyunyan1-1/+1
If the flag space_in_uri is set, the URI in HTTP upstream request is escaped to convert space to %20. However this flag is not checked while creating the default cache key. This leads to different cache keys for requests '/foo bar' and '/foo%20bar', while the upstream requests are identical. Additionally, the change fixes background cache updates when the client URI contains unescaped space. Default cache key in a subrequest is always based on escaped URI, while the main request may not escape it. As a result, background cache update subrequest may update a different cache entry.
2017-11-20Proxy: simplified conditions of using unparsed uri.Roman Arutyunyan1-4/+2
Previously, the unparsed uri was explicitly allowed to be used only by the main request. However the valid_unparsed_uri flag is nonzero only in the main request, which makes the main request check pointless.
2017-08-01Variables: macros for null variables.Ruslan Ermilov1-1/+1
No functional changes.
2017-03-15Proxy: split configured header names and values.Piotr Sikora1-106/+59
Previously, each configured header was represented in one of two ways, depending on whether or not its value included any variables. If the value didn't include any variables, then it would be represented as as a single script that contained complete header line with HTTP/1.1 delimiters, i.e.: "Header: value\r\n" But if the value included any variables, then it would be represented as a series of three scripts: first contained header name and the ": " delimiter, second evaluated to header value, and third contained only "\r\n", i.e.: "Header: " "$value" "\r\n" This commit changes that, so that each configured header is represented as a series of two scripts: first contains only header name, and second contains (or evaluates to) only header value, i.e.: "Header" "$value" or "Header" "value" This not only makes things more consistent, but also allows header name and value to be accessed separately. Signed-off-by: Piotr Sikora <piotrsikora@google.com>
2017-05-18Upstream: fixed u->headers_in.headers allocation error handling.Sergey Kandaurov1-0/+1
Previously, an allocation error resulted in uninitialized memory access when evaluating $upstream_http_ variables. On a related note, see r->headers_out.headers cleanup work in 0cdee26605f3.
2017-04-18SSL: added support for TLSv1.3 in ssl_protocols directive.Sergey Kandaurov1-0/+1
Support for the TLSv1.3 protocol will be introduced in OpenSSL 1.1.1.
2017-03-24Upstream: allow recovery from "429 Too Many Requests" response.Piotr Sikora1-0/+1
This change adds "http_429" parameter to "proxy_next_upstream" for retrying rate-limited requests, and to "proxy_cache_use_stale" for serving stale cached responses after being rate-limited. Signed-off-by: Piotr Sikora <piotrsikora@google.com>
2017-02-10Upstream: proxy_cache_background_update and friends.Roman Arutyunyan1-0/+11
The directives enable cache updates in subrequests.
2016-11-02Cache: proxy_cache_max_range_offset and friends.Dmitry Volyntsev1-0/+12
It configures a threshold in bytes, above which client range requests are not cached. In such a case the client's Range header is passed directly to a proxied server.
2016-10-31Upstream: added the ngx_http_upstream_resolved_t.name field.Ruslan Ermilov1-4/+2
This fixes inconsistency in what is stored in the "host" field. Normally it would contain the "host" part of the parsed URL (e.g., proxy_pass with variables), but for the case of an implicit upstream specified with literal address it contained the text representation of the socket address (that is, host including port for IP). Now the "host" field always contains the "host" part of the URL, while the text representation of the socket address is stored in the newly added "name" field. The ngx_http_upstream_create_round_robin_peer() function was modified accordingly in a way to be compatible with the code that does not know about the new "name" field. The "stream" code was similarly modified except for not adding compatibility in ngx_stream_upstream_create_round_robin_peer(). This change is also a prerequisite for the next change.