414 Commits

Author SHA1 Message Date
ece6bf4363 http_protocol: make request processing more robust for incomplete data
- Length restrictions may error on a too long request path, leaving
  the uri unset.



git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1910533 13f79535-47bb-0310-9956-ffa450edef68
2023-06-21 12:08:06 +00:00
f3004c8956 *) http_protocol: if there is a request and an error bucket in the input
brigade, always process the request bucket first. This gives the proper
     context in which to evaluate the error bucket in.
     Some error access r->method, for example, in their response body.



git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1910530 13f79535-47bb-0310-9956-ffa450edef68
2023-06-21 09:49:13 +00:00
2192bd4200 fail on bad header
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1906539 13f79535-47bb-0310-9956-ffa450edef68
2023-01-10 13:18:26 +00:00
ea2c3409f6 handle large writes in ap_rputs
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1901500 13f79535-47bb-0310-9956-ffa450edef68
2022-06-01 12:33:53 +00:00
fbb84e00fa Merge PR 311:
*) core/mod_http: use REQUEST meta buckets and a new HTTP/1.x specific
     input filter to separate the handling for HTTP requests from the
     handling of HTTP/1.x request parsing and checks.
     A new HTTP1_REQUEST_IN filter installs itself on http/1.1 connections
     before a request is being read. It generates either a REQUEST meta
     bucket on success or an ERROR bucket with the proposed response status.
     The core connection processing, relying on ap_read_request(), now expects
     a REQUEST or ERROR bucket from the input filters and is agnostic to
     specific HTTP versions and how they bring requests into the server.



git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1899799 13f79535-47bb-0310-9956-ffa450edef68
2022-04-13 07:40:17 +00:00
0296d7dfea *) core/mod_http: use RESPONSE meta buckets and a new HTTP/1.x specific
filter to send responses through the output filter chain.
     Specifically: the HTTP_HEADER output filter and ap_send_interim_response()
     create a RESPONSE bucket and no longer are concerned with HTTP/1.x
     serialization.
     A new HTTP1_RESPONSE_OUT transcode filter writes the proper HTTP/1.x
     bytes when dealing with a RESPONSE bucket. That filter installs itself
     on the pre_read_request hook when the connection has protocol 'http/1.1'.



git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1899648 13f79535-47bb-0310-9956-ffa450edef68
2022-04-07 10:41:46 +00:00
4442201e61 *) core/mod_http/mod_http2:
- adds new meta bucket types REQUEST, RESPONSE and HEADERS to the API.
     - adds a new method for setting standard response headers Date and Server
     - adds helper methods for formatting parts of HTTP/1.x, like headers and 
       end chunks for use in non-core parts of the server, e.g. mod_proxy
     - splits the HTTP_IN filter into a "generic HTTP" and "specific HTTP/1.x" 
       filter. The latter one named HTTP1_BODY_IN.
     - Uses HTTP1_BODY_IN only for requests with HTTP version <= 1.1
     - Removes the chunked input simulation from mod_http2
     - adds body_indeterminate flag to request_rec that indicates that a request 
       body may be present and needs to be read/discarded. This replaces logic 
       that thinks without Content-Length and Transfer-Encoding, no request 
       body can exist.



git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1899547 13f79535-47bb-0310-9956-ffa450edef68
2022-04-04 08:24:09 +00:00
0cb6384286 core: Simpler connection close logic if discarding the request body fails.
If ap_discard_request_body() sets AP_CONN_CLOSE by itself it simplifies and
allows to consolidate end_output_stream() and error_output_stream().



git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1898683 13f79535-47bb-0310-9956-ffa450edef68
2022-03-07 13:19:37 +00:00
3ec0ffb9e1 http: Enforce that fully qualified uri-paths not to be forward-proxied
have an http(s) scheme, and that the ones to be forward proxied have a
      hostname, per HTTP specifications.

The early checks avoid failing the request later on and thus save cycles
for those invalid cases.



git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1895921 13f79535-47bb-0310-9956-ffa450edef68
2021-12-13 18:55:18 +00:00
1d45d5527f Revert spurious commit r1895340.
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1895341 13f79535-47bb-0310-9956-ffa450edef68
2021-11-25 20:47:14 +00:00
5da71e7634 Trigger ci.
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1895340 13f79535-47bb-0310-9956-ffa450edef68
2021-11-25 20:45:54 +00:00
6945bb23ba core: Follow up to r1893030: Use special address for invalid r->method.
read_request_line() failure was cought by ap_parse_request() with r->method
being NULL, so have a .rodata pointer to "-" instead.


git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1893044 13f79535-47bb-0310-9956-ffa450edef68
2021-09-07 14:42:15 +00:00
74c097f0e1 core: Initialize the request fields on read failure to avoid NULLs.
* server/protocol.c(read_request_line):
  Set r->method_number to M_INVALID and r->{method,uri,unparsed_uri} to "-"
  when read fails, ap_parse_request_line() will never be called.



git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1893030 13f79535-47bb-0310-9956-ffa450edef68
2021-09-07 13:09:07 +00:00
e8dce10f62 Revert r1893026, will re-commit with minimal changes to ease backport.
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1893028 13f79535-47bb-0310-9956-ffa450edef68
2021-09-07 13:05:22 +00:00
d4f195853b core: Initialize the request fields on read failure to avoid NULLs.
* server/protocol.c(read_request_line):
  Set r->method_number to M_INVALID and r->{method,uri,unparsed_uri} to "-"
  when read fails, ap_parse_request_line() will never be called.



git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1893026 13f79535-47bb-0310-9956-ffa450edef68
2021-09-07 13:00:06 +00:00
9fdd6a91fb core: Set r->request_time before any logging, mod_unique_id needs it.
* server/protocol.c(read_request_line):
  Move r->request_time initialization before first APLOG_TRACE5,
  ap_log_rerror() may run the generate_log_id hooks and call mod_unique_id
  with no timestamp initialized (zero).
  


git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1893001 13f79535-47bb-0310-9956-ffa450edef68
2021-09-07 01:09:23 +00:00
6715670bf8 server/protocol.c: remove old hooks links that had been moved to server/ssl.c
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1888729 13f79535-47bb-0310-9956-ffa450edef68
2021-04-13 12:26:20 +00:00
587d170151 *) core: provide ap_ssl_* functions in new http_ssl.h header file.
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1888083 13f79535-47bb-0310-9956-ffa450edef68
2021-03-26 11:27:34 +00:00
38af3ed363 Make sure that conn->keepalive is NOT reset after being set in ap_read_request().
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1887999 13f79535-47bb-0310-9956-ffa450edef68
2021-03-24 09:37:15 +00:00
6951408220 Changed ap_ssl_answer_challenge() and its hook to provide PEM data for
certificate and key instead of file names.

Added support for this in mod_ssl and verified with a local mod_md 
version that uses it.



git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1887151 13f79535-47bb-0310-9956-ffa450edef68
2021-03-03 15:52:18 +00:00
5dc01860db Adding more ap_ssl_* functions and hooks to the core server.
- ap_ssl_add_cert_files() to enable other modules like mod_md to provide
       certificate and keys for an SSL module like mod_ssl.
     - ap_ssl_add_fallback_cert_files() to enable other modules like mod_md to
       provide a fallback certificate in case no 'proper' certificate is
       available for an SSL module like mod_ssl.
     - ap_ssl_answer_challenge() to enable other modules like mod_md to
       provide a certificate as used in the RFC 8555 'tls-alpn-01' challenge
       for the ACME protocol for an SSL module like mod_ssl.
    - Hooks for 'ssl_add_cert_files', 'ssl_add_fallback_cert_files' and
      'ssl_answer_challenge' where modules like mod_md can provide providers
      to the above mentioned functions.



git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1887085 13f79535-47bb-0310-9956-ffa450edef68
2021-03-02 14:21:18 +00:00
89859aab37 *) core: Adding SSL related inquiry functions to the server API.
These function are always available, even when no module providing
     SSL is loaded. They provide their own "shadowing" implementation for
     the optional functions of similar name that mod_ssl and impersonators
     of mod_ssl provide.
     This enables loading of several SSL providing modules when all but
     one of them registers itself into the new hooks. Two old-style SSL
     modules will not work, as they replace the others optional functions
     with their own.
     Modules using the old-style optional functions will continue to work
     as core supplies its own versions of those.
     The following has been added so far:
     - ap_ssl_conn_is_ssl() to query if a connection is using SSL.
     - ap_ssl_var_lookup() to query SSL related variables for a 
       server/connection/request.
     - Hooks for 'ssl_conn_is_ssl' and 'ssl_var_lookup' where modules
       providing SSL can install their own value supplying functions.



git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1886840 13f79535-47bb-0310-9956-ffa450edef68
2021-02-23 15:08:24 +00:00
c7972307ee Follow up to r1877955: don't reuse the connection for mixed C-L / T-E requests
Disable keepalive on the connection if we received both Content-Length and
chunked Transfer-Encoding in the request, to avoid confusion with front
intermediaries and potential further request/response splitting.

This is what we do already for mod_proxy backend connections in the same case.

While at it, replace draft httpbis links with final RFC7230's.


git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1879373 13f79535-47bb-0310-9956-ffa450edef68
2020-06-30 16:05:56 +00:00
588164dbd0 Follow up to r1877955: always validate the Content-Length
even if it is to be ignored because of RFC7230 section 3.3.3 requirements.


git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1879369 13f79535-47bb-0310-9956-ffa450edef68
2020-06-30 14:18:22 +00:00
dc55d74fe0 Validate request-target per RFC 7230 section 5.3.
RFC 7230 requires that the request-line URI be absolute, besides
"CONNECT authority-form" and "OPTIONS asterisk-form".

Enforce it in ap_parse_request_line().



git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1879078 13f79535-47bb-0310-9956-ffa450edef68
2020-06-22 10:35:50 +00:00
b68bcc9312 Add a space to be consistent with surrounding code and to synch with 2.4.x
[skip ci]

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1879007 13f79535-47bb-0310-9956-ffa450edef68
2020-06-19 19:39:47 +00:00
943a278020 * Revert r1878939, r1878938, r1878936, the changes to
modules/http2/h2_request.c and CHANGES of r1878926 and r1878708 as a result of
  https://lists.apache.org/thread.html/red499ac4750b88e5943c25abb86434c59dfff4d4f386ffc53742755d%40%3Cdev.httpd.apache.org%3E
  and
  https://lists.apache.org/thread.html/ra79eee019e2357703b0ea81153458a29817b58ce92e3605949eee1fe%40%3Cdev.httpd.apache.org%3E


git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1878985 13f79535-47bb-0310-9956-ffa450edef68
2020-06-19 11:45:16 +00:00
97bc128df2 * Have the HTTP 0.9 / 1.1 processing code reject requests for
HTTP >= 2.0 with a HTTP Version Not Support status code.


git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1878708 13f79535-47bb-0310-9956-ffa450edef68
2020-06-10 11:24:13 +00:00
2efe92b51d core, protocol: reject invalid Content-Length ASAP.
Don't let invalid invalid Content-Length header go beyond ap_read_request()
and protocol validation. The check in ap_http_filter() is still useful if
some modules mangles the header, but it's too late for the usual case.


git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1877955 13f79535-47bb-0310-9956-ffa450edef68
2020-05-20 14:13:09 +00:00
ac762c1ae1 core: follow up to r1876664: allow ErrorDocument to read body when applicable
Unless ap_read_request() failed to read the request line or header, or
Transfer-Encoding is invalid, we can still provide the request body to custom
error handlers (ErrorDocument) that ask it (e.g. internal redirects to CGI).

So this commit splits early failure path (previously die_early label) in two,
die_unusable_input and die_before_hooks, where the latter preserves input
filters (including HTTP_IN).

Also, the code to apply the connection timeout and r->per_dir_config from the
server is now in a new apply_server_config() helper since it's used multiple
times. Note that apr_socket_timeout_set() is a noop if the new timeout is the
same as the one already in place, so there is no need to cache the old timeout
nor use apr_socket_timeout_get(). Likewise, r->server is initially set to
c->base_server so apply_server_config() is overall a noop when no change is
needed.


git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1876784 13f79535-47bb-0310-9956-ffa450edef68
2020-04-21 10:29:07 +00:00
22b3d7cec4 core, h2: common ap_parse_request_line() and ap_check_request_header() code.
Extract parsing/validation code from read_request_line() and ap_read_request()
into ap_parse_request_line() and ap_check_request_header() helpers such that
mod_http2 can validate its HTTP/1 request with the same/configured policy.


git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1876674 13f79535-47bb-0310-9956-ffa450edef68
2020-04-17 16:47:42 +00:00
b157ae396c core, h2: send EOR for early HTTP request failure.
The core output filters depend on EOR being sent at some point for correct
accounting of setaside limits and lifetime.

Rework ap_read_request() early failure (including in post_read_request() hooks)
so that it always sends the EOR after ap_die().

Apply the same scheme in h2_request_create_rec() which is the HTTP/2 to HTTP/1
counterpart.


git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1876664 13f79535-47bb-0310-9956-ffa450edef68
2020-04-17 13:07:46 +00:00
85760859ca Fix spelling errors found by codespell. [skip ci]
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1873985 13f79535-47bb-0310-9956-ffa450edef68
2020-02-13 18:15:57 +00:00
c1ac12fa3b factor out TE=chunked checking
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1873748 13f79535-47bb-0310-9956-ffa450edef68
2020-02-07 17:14:05 +00:00
3ddb50dbb5 PR63669: handle APR_BADARG return from ap_rgetline
Submitted By: Giovanni Bechis <giovanni paclan.it>



git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1873394 13f79535-47bb-0310-9956-ffa450edef68
2020-01-31 02:15:57 +00:00
cdc97c4368 Revert r1869222, wrong files committed.
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1869223 13f79535-47bb-0310-9956-ffa450edef68
2019-10-31 16:10:08 +00:00
e2d7af8692 mod_proxy_http: follow up to r1869216.
Let's call stream_reqbody() for all rb_methods, no RB_SPOOL_CL special case.

This both simplifies code and allows to keep EOS into the input_brigade until
it's sent, and thus detect whether we already fetched the whole body if/when
proxy_http_handler() re-enters for different balancer members.


git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1869222 13f79535-47bb-0310-9956-ffa450edef68
2019-10-31 16:08:33 +00:00
b936beed5c mod_proxy_http: Fix 100-continue deadlock for spooled request bodies. PR 63855.
Send "100 Continue", if needed, before fetching/blocking on the request body in
spool_reqbody_cl(), otherwise mod_proxy and the client can wait for each other,
leading to a request timeout (408).

While at it, make so that ap_send_interim_response() uses the default status
line if none is set in r->status_line.


git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1868576 13f79535-47bb-0310-9956-ffa450edef68
2019-10-18 07:50:59 +00:00
12558f2ec1 Fix a typo in a message.
Reported and fixed by Christian Bartolomäus (bartolin gmx.de)
PR 63806

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1868016 13f79535-47bb-0310-9956-ffa450edef68
2019-10-05 13:42:00 +00:00
052e0151ca Fix a signed/unsigned comparison that can never match.
(+ add a missing space to improve formating)

Spotted by gcc 9.1 and -Wextra

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1864865 13f79535-47bb-0310-9956-ffa450edef68
2019-08-10 08:59:13 +00:00
d11a3b2eab Fix a shadow (and useless) variable.
Fix a cppcheck warning and a style issue.

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1844352 13f79535-47bb-0310-9956-ffa450edef68
2018-10-19 15:57:06 +00:00
68b0e99b65 * server/protocol.c (ap_rvputs): Call va_end before returning in the
error case, as required by C89/POSIX stdarg.h - Coverity warns for
  this.


git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1842919 13f79535-47bb-0310-9956-ffa450edef68
2018-10-05 14:05:20 +00:00
7e7ee80d85 add ids
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1838079 13f79535-47bb-0310-9956-ffa450edef68
2018-08-15 11:40:11 +00:00
19e9326dbf Add StrictHostCheck
.. to allow ucnonfigured hostnames to be rejected. 

The checks happen during NVH mapping and checks that the
mapped VH itself has the host as a name or alias.



git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1838055 13f79535-47bb-0310-9956-ffa450edef68
2018-08-14 21:47:22 +00:00
f673148e9b http: Enforce consistently no response body with both 204 and 304 statuses.
Provide AP_STATUS_IS_HEADER_ONLY() helper/macro to check for 204 or 304 and
use it where some special treatment is needed when no body is expected.

Some of those places handled 204 only.


git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1837056 13f79535-47bb-0310-9956-ffa450edef68
2018-07-30 13:08:23 +00:00
3558bdf4b7 mod_proxy_http: forward 100-continue.
Handle end-to-end 100-continue, according to RFC 7231, such that the client
request body is not read/forwarded (according to its "Expect:" header) until
the backend wants to receive it (with interim 100 continue response), or never
forwarded if the backend provides a (non-interim) response and doesn't need
the client body at all.

This is achieved by filling the header_brigade in ap_proxy_http_prefetch()
and letting ap_proxy_http_request() determine whether it should forward that
brigade only (with the "Expect: 100-continue" specified by the client or added
according to "ping=" configuration), or forward the whole body for the usual
case (as before).

When 100-continue expectation is in place, the body is actually forwarded by
ap_proxy_http_process_response() when/if a "100 continue" response is sent by
the backend, otherwise the body is discarded; a future enhancement could make
so that in a balancer configuration, the body could be forwarded to another
balancer member depending on the status/error from the backend.

So stream_reqbody_cl() and stream_reqbody_chunked() functions are adapted to be
called by either ap_proxy_http_request() or ap_proxy_http_process_response(),
while spool_reqbody_cl() still spools the body in ap_proxy_http_prefetch() thus
before the backend is connected/reused to avoid inactivity on the connection
for the prefetch time (the prefetched body is also forwarded according to the
100-continue expectation, though).

Also, since the brigades and other runtime objects now need to be shared by the
ap_proxy_http_*() functions chain, a proxy_http_req_t struct/context is created
from the start and passed to them as (the single) argument. This is also a good
candidate for a future async baton, if we wanted to let the MPM event wait for
connection data for us at any stage and be called back ;)

Finally, ap_send_interim_response() is modified to correcly handle 100 continue
responses once, and take care of clearing r->expecting_100 only for them.

PR 60330.



git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1836588 13f79535-47bb-0310-9956-ffa450edef68
2018-07-24 21:55:29 +00:00
2a52d4eed5 PR62368: Print the unparsed URI in AH03454
... to include r->args and get otherwise get as close to possible to
what came in over the wire.

Submitted By: Hank Ibell <hwibell gmail.com>
Committed By: covener




git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1831772 13f79535-47bb-0310-9956-ffa450edef68
2018-05-17 12:21:15 +00:00
fab86dcf0e Axe ap_rgetline_core(), not used anymore.
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1829790 13f79535-47bb-0310-9956-ffa450edef68
2018-04-22 15:58:18 +00:00
3cd0ddc3fa Follow up to r1829659, ap_[f]getline() EBCDIC awareness.
Rename ap_fgetline_impl() to ap_fgetline_core(), and do missing EBCDIC
translation in ap_fgetline().

Also restore EBCDIC translation for ap_getline(), as noted by Ruediger this
was changed (unexpectedly) in r1829659.



git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1829789 13f79535-47bb-0310-9956-ffa450edef68
2018-04-22 15:48:31 +00:00
5738365023 http: add ap_fgetline() and AP_GETLINE_NONBLOCK flag.
It allows to read a line directly from an input filter, in blocking mode
or not. Since no request_rec is needed, a pool may be given.

Existing ap_[r]getline() function are now based off ap_fgetline() by calling:
    ap_fgetline(s, n, read, r->proto_input_filters, flags, bb, r->pool);

Will follow up with a new ap_get_mime_headers_*() flavor which can be used by
any filter that needs non-blocking and not necessarily has a request_rec (e.g.
ap_http_filter() to read proxied response trailers).



git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1829659 13f79535-47bb-0310-9956-ffa450edef68
2018-04-20 14:30:19 +00:00