summaryrefslogtreecommitdiffhomepage
path: root/src/http (follow)
AgeCommit message (Collapse)AuthorFilesLines
2026-04-06Upstream: reset early_hints_length on upstream reinit.David Carlier1-0/+1
When a request was retried to a new upstream after receiving 103 Early Hints from the previous one, the accumulated early_hints_length was not reset, causing valid early hints from the next upstream to be incorrectly rejected as "too big".
2026-04-06Fix $request_port and $is_request_port in subrequestsZoey1-0/+2
Closes #1247.
2026-04-06Added max_headers directive.Maxim Dounin6-0/+40
The directive limits the number of request headers accepted from clients. While the total amount of headers is believed to be sufficiently limited by the existing buffer size limits (client_header_buffer_size and large_client_header_buffers), the additional limit on the number of headers might be beneficial to better protect backend servers. Requested by Maksim Yevmenkin. Signed-off-by: Elijah Zupancic <e.zupancic@f5.com> Origin: <https://freenginx.org/hg/nginx/rev/199dc0d6b05be814b5c811876c20af58cd361fea>
2026-04-06Upstream: fix integer underflow in charset parsingDavid Korczynski1-1/+1
The issue described below was only reproducible prior to https://github.com/nginx/nginx/commit/7924a4ec6cb35291ea60a5f2a70ac0a034d94ff7 When parsing the `charset` parameter in the `Content-Type` header within `ngx_http_upstream_copy_content_type`, an input such as `charset="` resulted in an integer underflow. In this scenario, both `p` and `last` point to the position immediately following the opening quote. The logic to strip a trailing quote checked `*(last - 1)` without verifying that `last > p`. This caused `last` to be decremented to point to the opening quote itself, making `last < p`. The subsequent length calculation `r->headers_out.charset.len = last - p` resulted in -1, which wrapped to `SIZE_MAX` as `len` is a `size_t`. This invalid length was later passed to `ngx_cpymem` in `ngx_http_header_filter`, leading to an out-of-bounds memory access (detected as `negative-size-param` by AddressSanitizer). The fix ensures `last > p` before attempting to strip a trailing quote, correctly resulting in a zero-length charset for malformed input. The oss-fuzz payload that triggers this issue holds multiple 103 status lines, and it's a sequence of 2 of those Content-Type headers that trigger the ASAN report. Co-authored-by: CodeMender <codemender-patching@google.com> Fixes: https://issues.oss-fuzz.com/issues/486561029 Signed-off-by: David Korczynski <david@adalogics.com>
2026-04-02Upstream: fixed processing multiple 103 (early hints) responses.Sergey Kandaurov1-5/+3
The second 103 response in a row was treated as the final response header.
2026-03-24Fixed the "include" directive inside the "geo" block.Eugene Grebenschikov1-1/+6
The "include" directive should be able to include multiple files if given a filename mask. Completes remaining changes introduced in da4ffd8. Closes: https://github.com/nginx/nginx/issues/1165
2026-03-24Dav: destination length validation for COPY and MOVE.Roman Arutyunyan1-13/+26
Previously, when alias was used in a location with Dav COPY or MOVE enabled, and the destination URI was shorter than the alias, integer underflow could happen in ngx_http_map_uri_to_path(), which could result in heap buffer overwrite, followed by a possible segfault. With some implementations of memcpy(), the segfault could be avoided and the overwrite could result in a change of the source or destination file names to be outside of the location root. Reported by Calif.io in collaboration with Claude and Anthropic Research.
2026-03-24Mp4: fixed possible integer overflow on 32-bit platforms.Roman Arutyunyan1-7/+7
Previously, a 32-bit overflow could happen while validating atom entries count. This allowed processing of an invalid atom with entrires beyond its boundaries with reads and writes outside of the allocated mp4 buffer. Reported by Prabhav Srinath (sprabhav7).
2026-03-24Mp4: avoid zero size buffers in output.Roman Arutyunyan1-6/+9
Previously, data validation checks did not cover the cases when the output contained empty buffers. Such buffers are considered illegal and produce "zero size buf in output" alerts. The change rejects the mp4 files which produce such alerts. Also, the change fixes possible buffer overread and overwrite that could happen while processing empty stco and co64 atoms, as reported by Pavel Kohout (Aisle Research) and Tim Becker.
2026-03-24Upstream keepalive: fixed parameter parsing.Roman Arutyunyan1-1/+1
2026-03-24Proxy: enabled HTTP/1.1 by default for upstream connections.Roman Semenov1-33/+3
Updates the proxy module to use HTTP/1.1 as the default protocol when communicating with upstream servers. This change unlocks features such as persistent connections and chunked transfer encoding. Configurations that require HTTP/1.0 can still override the protocol explicitly.
2026-03-24Upstream: enabled keepalive by default for explicit upstreams.Roman Semenov1-63/+67
Keepalive is now automatically enabled in the "local" mode for upstreams defined in configuration files. Cached keepalive connections are no longer shared between different locations referencing the same explicit upstream unless keepalive is explicitly configured without the "local" parameter. To disable keepalive entirely, use keepalive 0; inside the upstream block. To allow sharing cached connections between locations, configure keepalive <max_cached>; without the "local" parameter.
2026-03-24Upstream keepalive: distinguish cached connections by location.Roman Semenov1-1/+22
The new "local" parameter prevents sharing cached keepalive connections between location blocks. Connections are now reused only within the same location.
2026-03-19The "multipath" parameter of the "listen" directive.Sergey Kandaurov3-0/+21
When configured, it enables Multipath TCP support on a listen socket. As of now it works on Linux starting with Linux 5.6 and glibc 2.32, where it is enabled with an IPPROTO_MPTCP socket(2) protocol. To avoid EADDRINUSE errors in bind() and listen() when transitioning between sockets with different protocols, SO_REUSEPORT is set on both sockets. See f7f1607bf for potential implications. Based on previous work by Maxime Dourov and Anthony Doeraene.
2026-03-16gRPC: reset buffer chains on upstream reinit.David Carlier1-0/+3
Previously, ctx->out was not cleared in ngx_http_grpc_reinit_request(), which could cause queued HTTP/2 control frames (SETTINGS ACK, PING ACK, WINDOW_UPDATE) to be sent on next upstream. Additionally, ctx->in and ctx->busy needs to be cleared to avoid similar problems with buffered request body fixed in cd12dc4f1.
2026-03-16Proxy: reset pending control frames on HTTP/2 upstream reinit.David Carlier1-0/+1
Previously, ctx->out was not cleared in ngx_http_proxy_v2_reinit_request(), which could cause stale HTTP/2 control frames (SETTINGS ACK, PING ACK, WINDOW_UPDATE) queued for the old upstream connection to be sent to a new upstream connection during a retry.
2026-03-11Proxy authentication definitions.Roman Arutyunyan4-2/+17
2026-03-09Sticky: fixed expiration of learned sessions after reload.Aleksei Bavshin1-2/+57
Previously, the expiration timer for learned session was not started until a new session is created. This could lead to the sessions being active past the expiration time.
2026-03-09Sticky: samesite=<strict|lax|none> cookie flags.Vladimir Kokshenev1-1/+89
Adds new options for the "sticky cookie" directive to set samesite=<strict|lax|none> cookie flags.
2026-03-09Sticky: added the "header" parameter in the learn mode.Vladimir Homutov4-15/+84
With this parameter set, sessions are learned after receiving upstream headers.
2026-03-09Sticky: added the "max-age" attribute to cookie.Vladimir Homutov1-4/+6
RFC 6265 defines "Max-Age" cookie attribute in section 5.2.2. If the "expires" option is passed to the "sticky" directive, "max-age" attribute will appear in cookies set by the module with corresponding value in seconds. For the special "max" value of the "expires" option, corresponding "max-age" attribute value will be set to 315360000 seconds (10 years, similar to how its done in headers_filter module for the "Cache-Control" header).
2026-03-09Sticky: added variables support to cookie domain.Vladimir Homutov1-18/+38
2026-03-09Sticky: added "httponly" and "secure" attributes.Vladimir Homutov1-0/+39
The attributes are described in RFC6265, sections 4.1.2.5 and 4.1.2.6 respectively.
2026-03-09Sticky: added "draining" peer state.Vladimir Homutov3-7/+36
While peer is draining, only sticky requests are served and the peer is never selected to process new requests. Co-authored-by: Ruslan Ermilov <ru@nginx.com>
2026-03-09Upstream: introduced a new macro for down value.Aleksei Bavshin2-1/+3
2026-03-09Sticky: added the "learn" mode.Vladimir Homutov1-92/+767
In this mode, nginx "learns" which client uses which proxied server by analyzing headers of client requests and proxied server responses. For example, a proxied server may start sessions by issuing the "Set-Cookie" header field to set cookie 'sid' and returning clients will bring the cookie with the same name. The following configuration may be used to handle this case: upstream u1 { server 127.0.0.1:8080; server 127.0.0.1:8081; sticky learn timeout=10m zone=sess:1m create=$upstream_cookie_sid lookup=$cookie_sid; } Co-authored-by: Ruslan Ermilov <ru@nginx.com> Co-authored-by: Maxim Dounin <mdounin@mdounin.ru>
2026-03-09Upstream: added sticky sessions support for upstreams.Vladimir Homutov10-8/+1005
Sticky sessions allow to route the same client to the same upstream server. - upstream structures are extended to keep session-related information - existing balancing modules are updated to provide an id of the selected server (SID) in pc->sid, and to select the server, given it's SID. - other balancing modules are allowed to set the pc->hint value to choose the desired peer. The sticky module will not change the hint if it's already set. - the feature is enabled by default and can be disabled with the "--without-http_upstream_sticky" switch of the configure script. The following configuration can be used to enable sticky sessions for supported balancing modules: upstream u1 { server 127.0.0.1:8080; server 127.0.0.1:8081; sticky cookie server_id expires=1h domain=.example.com path=/; } Co-authored-by: Ruslan Ermilov <ru@nginx.com> Co-authored-by: Roman Arutyunyan <arut@nginx.com> Co-authored-by: Maxim Dounin <mdounin@mdounin.ru>
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 Zhestikov4-6/+30
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-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-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-08Upstream: add support for connection level ALPN protocol negotiation.Zhidao HONG2-0/+18
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-06Disabled bare LF in chunked transfer encoding.Sergey Kandaurov2-29/+24
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-26Changed interface of ngx_http_validate_host().Sergey Kandaurov5-57/+31
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-26Improved host header validation.Sergey Kandaurov1-32/+133
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