Commit Graph

4283 Commits (be82f3d2e1e65faa54d335b53458294ef7ec8e8c)

Author SHA1 Message Date
Glenn Strauss 3f0833328c [mod_indexfile] update path with buffer path funcs
use buffer_copy_path_len2() or buffer_append_path_len()
to construct r->physical.path filesystem path
2021-09-08 15:06:07 -04:00
Glenn Strauss 83338cb7dd [tests] IO::Socket::INET->new( Timeout => 1 )
(to be used when supported by the underlying Perl lib)
2021-09-08 15:06:07 -04:00
Glenn Strauss ca2898f678 [tests] t/test_mod_indexfile
also remove some now-redundant tests from request.t
and reduce scripts and directories under tests
(because automake is sloooow and the fewer dirs, the better)
2021-09-08 15:06:07 -04:00
Glenn Strauss 7a21b3856e [core] log_error_multiline()
rename log_error_multiline_buffer() to log_error_multiline()
and take (char *)ptr and (size_t)len instead of (buffer *)b

When debug printing request and response headers,
print each header on separate line for readability
and omit '\r' if "\r\n" ends line
2021-09-08 15:06:07 -04:00
Glenn Strauss 41d4ffad99 [mod_openssl] default disable client renegotiation 2021-09-08 15:06:07 -04:00
Glenn Strauss 70195d069d [mod_cgi] improve CGI offloading
improve CGI offloading when not streaming request body

If not streaming request body, collect request body into single tempfile
and use fd to tempfile as stdin to CGI (in lieu of input pipe()).
For prior behavior, set the following config option, enabled by default:
  server.feature-flags += ("cgi.tempfile-accum" => "disable")

If there is no request body, open /dev/null instead of creating pipe().
2021-09-08 15:06:07 -04:00
Glenn Strauss bed08f1292 [core] base64url pad char is '='; change from '.'
RFC4648 base64url pad char is '='; change from '.' in lighttpd
The base64url encoding was introduced in lighttpd 1.4.38 in 2015,
but at the time, does not appear to have been used in base64url
decoding where padding might be present.

In lighttpd 1.4.50, base64url decoding was possible with %{decb64u:...}
potentially used in mod_redirect and mod_rewrite rules.  However, this
is not believed to be widely used, and even if used, it is strongly
recommended that the URLs contain a base64url-encoded string WITHOUT
padding, since padding of '=' might be %-encoded and require decoding
before base64url-decoding.

Note: this change may affect %{decb64u:...} substitution in
mod_redirect and mod_rewrite, but *ONLY* in case where URL contains
a base64url-encoded string *WITH* padding, and that padding had been
created specifically for use with lighttpd, using '.' as padding char

x-ref:
  RFC4648 https://datatracker.ietf.org/doc/html/rfc4648#section-5
2021-09-08 15:06:07 -04:00
Glenn Strauss 517010f2a6 [mod_echo] test module to echo request as response
test/debugging module to echo request back to client as response

(not part of build Makefile)
2021-09-08 15:06:07 -04:00
Glenn Strauss 6ed2777204 [mod_magnet] ignore 1xx return in response start
ignore 1xx return code from lua in response start phase.

Since response is about to start, send any added/modified headers
along with final response.  (If we did not ignore, then 1xx return
code from lua would incorrectly overwrite the final response status.)
2021-09-08 15:06:07 -04:00
Glenn Strauss 3a8b965438 [mod_magnet] detect MAGNET_RESTART_REQUEST loops
throw error after 9 MAGNET_RESTART_REQUEST loops
2021-09-08 15:06:07 -04:00
Glenn Strauss e7290fad9a [mod_magnet] attrs for remote port and server port
lighty.r.req_attr["request.remote-port"]
lighty.r.req_attr["request.server-port"]
2021-09-08 15:06:07 -04:00
Glenn Strauss f7018e3d39 [core] sock_addr_set_port() 2021-09-08 15:06:07 -04:00
Glenn Strauss d9bac3f423 [mod_magnet] reset config cache for remote addr
reset config cache for changes to
  lighty.r.req_attr["request.remote-addr"]

Changes might affect subsequent modules when those modules patch config,
but does not affect the core config options which have already been
processed.

If lighttpd config needs to be reprocessed after making changes, then
return lighty.RESTART_REQUEST from lua script to tell lighttpd to
restart the request, including reprocessing the core config options.
2021-09-08 15:06:07 -04:00
Glenn Strauss 2d8619db57 [mod_magnet] reset config cache for uri components
reset config cache after modifications to uri components
  lighty.r.req_attr["uri.scheme"]
  lighty.r.req_attr["uri.authority"]
  lighty.r.req_attr["uri.path"]
  lighty.r.req_attr["uri.query"]

Changes might affect subsequent modules when those modules patch config,
but does not affect the core config options which have already been
processed.

If lighttpd config needs to be reprocessed after making changes, then
return lighty.RESTART_REQUEST from lua script to tell lighttpd to
restart the request, including reprocessing the core config options.
2021-09-08 15:06:07 -04:00
Glenn Strauss 0a5cbc62bd [mod_magnet] rename magnet_cgi_ to magnet_envvar_
rename magnet_cgi_* to magnet_envvar_* to be less confusing
The (array *)r->env is populated with connection-level env (e.g TLS)
but is not populated with CGI/1.1 environment variables.
Values similar to most CGI/1.1 environment variables are already available
from lighty.r.req_attr[] (or lighty.env[]) which are prepared on demand.
2021-09-08 15:06:07 -04:00
Glenn Strauss c0ea7f8e27 [mod_magnet] use blank str for nil (do not panic)
substitute blank string for nil param (instead of lua script panic)
2021-09-08 15:06:07 -04:00
Glenn Strauss 3ddf457560 [mod_magnet] lighty.c.readdir
lighty.c.readdir           dir walk

Note: the "lighty.c.*" namespace is EXPERIMENTAL / UNSTABLE
In the future, these may be removed, altered, or moved to a different
namespace.
2021-09-08 15:06:07 -04:00
Glenn Strauss ed94ae88e8 [mod_magnet] lighty.c.cookie_tokens
lighty.c.cookie_tokens     parse cookie header into table

Note: the "lighty.c.*" namespace is EXPERIMENTAL / UNSTABLE
In the future, these may be removed, altered, or moved to a different
namespace.
2021-09-08 15:06:07 -04:00
Glenn Strauss c82ca970fb [core] refuse excess h2 streams at con start (fixes #3093)
refuse excess h2 streams up to stream id 199 within 1-2 seconds of
establishing connection.  This attempts to more gracefully handle
excessively agressive browsers sending too many new requests *before*
processing the initial SETTINGS frame sent by the server.

lighttpd HTTP/2 support limits SETTINGS_MAX_CONCURRENT_STREAMS to 8
and communicates this in the initial SETTINGS sent by the server.

x-ref:
  "Chrome 92, HTTP/2, fcgi, mutiple puts no response"
  https://redmine.lighttpd.net/issues/3093
  "POST request DATA part for non-existing URI closes HTTP/2 connection prematurely"
  https://redmine.lighttpd.net/issues/3078
2021-09-08 15:06:07 -04:00
Glenn Strauss aa1027ba24 [mod_magnet] lighty.r.* interfaces to request
lighty.r.req_header[]     HTTP request headers
lighty.r.req_attr[]       HTTP request attributes / components
lighty.r.req_env[]        HTTP request environment variables
lighty.r.resp_header[]    HTTP response headers
lighty.r.resp_body.*      HTTP response body accessors
lighty.r.resp_body.len    HTTP response body length
lighty.r.resp_body.add()  HTTP response body add (string or table)
lighty.r.resp_body.set()  HTTP response body set (string or table)

lighty.r.req_header[] allows get/set of request headers
If modifications would affect config processing, script should return
lighty.MAGNET_RESTART to have lighttpd restart the modified request
This differs from the older lighty.env[] table, which (previously) did
not permit modification of request headers.

lighty.r.resp_header[] allows get/set of response headers
(certain connection-level headers such as Connection and
Transfer-Encoding are restricted from modification)
This differs from the older lighty.header[] table, which is
collected and deferred, being applied after the script exits.

lighry.r.resp_body.* adds/sets response body content.
This differs from the older lighty.content[] table, which is
collected and deferred, being applied after the script exits.

e.g.
  r = lighty.r
  resp_header = r.resp_header
  resp_header["Content-Type"] = "text/html"
or
  lighty.r.resp_header["Content-Type"] = "text/html"
older syntax (less clear)
  lighty.header["Content-Type"] = "text/html"
2021-09-08 15:06:07 -04:00
Glenn Strauss 86c87d3c6d [core] use mod name in trace instead of mod_gw 2021-09-08 15:06:07 -04:00
Glenn Strauss a3b76ed5c4 [core] reuse some cold duplicate hdr match code 2021-09-08 15:06:07 -04:00
Glenn Strauss b596680ba4 [mod_magnet] look up env id by strlen, then strcmp 2021-09-08 15:06:07 -04:00
Glenn Strauss 614250b4d8 [mod_magnet] expose enc/dec str funcs to lua
lighty.c.b64urldec         validate and decode base64url
lighty.c.b64urlenc         base64url encode, no padding
lighty.c.b64dec            validate and decode base64
lighty.c.b64enc            base64 encode, no padding
lighty.c.hexdec            validate and decode hex str
lighty.c.hexenc            uc; lc w/ lua s = s:lower()
lighty.c.xmlenc            xml-encode/html-encode: <>&'\"`
lighty.c.urldec            url-decode
lighty.c.urlenc            url-encode
lighty.c.urldec_query      url-decode query-string
lighty.c.urlenc_query      url-encode query-string
lighty.c.urlenc_normalize  url-encode normalization
lighty.c.fspath_simplify   simplify fspath

Note: the "lighty.c.*" namespace is EXPERIMENTAL / UNSTABLE
In the future, these may be removed, altered, or moved to a different
namespace.
2021-09-08 15:06:07 -04:00
Glenn Strauss 76ed1f4462 [mod_magnet] protect and control lighty table mod
protect lighty table against mistaken modification
(lighty table is resused between script invocations)

detect if lighty.content[] is set by script (or if not set)
2021-09-08 15:06:07 -04:00
Glenn Strauss 188248d238 [mod_magnet] lighty.stat now returns userdata obj
lighty.stat now returns a userdata object instead of a populated table.
The userdata object provides methods to access the (stat_cache_entry *)
stored in the userdata object.  (This approach is often much faster than
populating the table of stat entries, as the fields get copied on demand
(upon use) into lua types.)
2021-09-08 15:06:07 -04:00
Glenn Strauss bf05943258 [mod_magnet] allow modification of request headers
allow modification of request headers, with some limitations:
- lighttpd config conditions are not reset;
  lua script must return lighty.RESTART_REQUEST to reprocess request
  (if applicable to the running lighttpd config)
- lighttpd config request header policy is not applied;
  lua script must not set unvalidated, untrusted, or non-normalized vals
- Host may not be unset
- Content-Length may not be modified
- some hop-by-hop (connection) level headers may not be modified
  (e.g. Connection, Transfer-Encoding)
2021-09-08 15:06:07 -04:00
Glenn Strauss b5cdc958a7 [mod_magnet] expose md and hmac funcs to lua
lighty.c.md("algo", "data")
lighty.c.hmac("algo", "secret", "data")

"algo" can be one of: "md5", "sha1", "sha256", "sha512"
(as long as lighttpd compiled w/ crypto lib supporting those algorithms)

lighty.c.digest_eq("digest1", "digest2")
- performs a timing-safe, case-insensitive comparison of two hex digests
- "digest1" and "digest2" are hex strings (of binary digests)
- returns boolean true or false

lighty.c.secret_eq("data1", "data2")
- performs a timing-safe comparison of two strings
  (and attempts to hides differences in string lengths)
- "data1" and "data2" are strings
- returns boolean true or false

lighty.c.time()
- cached time(); seconds since 1 Jan 1970 00:00:00 GMT
  (faster than os.time())

lighty.c.rand()
- generate pseudo-random number

Note: the "lighty.c.*" namespace is EXPERIMENTAL / UNSTABLE
In the future, these may be removed, altered, or moved to a different
namespace.
2021-09-08 15:06:07 -04:00
Glenn Strauss d97eeefa34 [core] li_hmac_sha512() 2021-09-08 15:06:07 -04:00
Glenn Strauss 347479573a [mod_magnet] reuse lighty lua table
reuse lighty lua table; leave on stack
reset response tables lighty.header[] and lighty.content[] each request
2021-09-08 15:06:07 -04:00
Glenn Strauss 77ea7d8a56 [mod_extforward] HAProxy PROXY env PP2_UNIQUE_ID
propagate PP2_TYPE_UNIQUE_ID into request env as PP2_UNIQUE_ID
2021-09-08 15:06:07 -04:00
Glenn Strauss 24d103c5c5 [mod_indexfile] section into subroutines
separate out logic to choose whether or not to try to handle request
from logic to try to find target from list of potential indexfiles
2021-09-08 15:06:07 -04:00
Glenn Strauss 67c0b1498a [multiple] remove base.h include where not used
(substitute request.h if file only accesses request_st,
 and not connection or server structs)
2021-09-08 15:06:07 -04:00
Glenn Strauss a04d69eaaa [mod_uploadprogress] use splay_tree for req list
(avoids persistent memory allocation for list struct)
(reduce possibility of long-term memory fragmentation due to
mod_uploadprogress)
2021-09-08 15:06:06 -04:00
Glenn Strauss 7e000de04e [mod_cgi] use linked list for process list
(avoids persistent memory allocation for list struct)
(reduce possibility of long-term memory fragmentation due to mod_cgi)
2021-09-08 15:06:06 -04:00
Glenn Strauss 7b3a4f13d7 [mod_cgi] reuse chunk buffers
reuse chunk buffers rather than persistent allocated memory
(reduce possibility of long-term memory fragmentation due to mod_cgi)
2021-09-08 15:06:06 -04:00
Glenn Strauss 55d8ed1b25 [core] remove HANDLER_WAIT_FOR_FD
If a system call returns EMFILE, then admin should increase
server.max-fds and check/increase rlimits for num files (ulimit -Hn)

Alternatively, the admin might decrease server.max-connections to limit
the number of connections served in parallel.
2021-09-08 15:06:06 -04:00
Glenn Strauss 50a274312d [core] reduce optim inline of cold funcs 2021-09-08 15:06:06 -04:00
Glenn Strauss 38ecede057 [core] clarify an error message 2021-09-08 15:06:06 -04:00
Juliusz Sosinowicz db54269c06 [mod_wolfssl] wolfSSL_sk_X509_NAME_push change
adjust code for wolfSSL_sk_X509_NAME_push() interface change in
wolfssl v4.8.0

[gstrauss: edited var names, whitespace, comments, commit message]

x-ref:
  "[wolfssl] Correct return check for wolfSSL_sk_X509_NAME_push"
  https://github.com/lighttpd/lighttpd1.4/pull/107

github: closes #107
2021-09-08 15:06:06 -04:00
Glenn Strauss 62a9d5b78f [core] clear request,connection pools every 64 sec (#3084)
x-ref:
  "Memory fragmentation with HTTP/2 enabled"
  https://redmine.lighttpd.net/issues/3084
2021-09-08 15:06:06 -04:00
Glenn Strauss 323e03fb2d [core] remove connection_list_append()
merge connection_list_append() into connection_fdwaitqueue_append()

(not converted to singly-linked-list since fdwaitqueue is not expected
to be used during normal operation (except extreme overload condition),
so use allocated list of pointers (allocated when needed) instead of
adding ptr member to (every) allocated struct connection)

remove connections-glue.c
remove inclusion of connections.h by non-base files
2021-09-08 15:06:06 -04:00
Glenn Strauss dc2d1dfe47 [core] change con joblist to singly-linked-list
avoids separate memory allocation for list of pointers

adds ability to check if con is already in joblist,
so do not re-add con if already in joblist

since con is checked if in joblist before being added to joblist,
there is no longer need for two lists and jobs can be processed
before poll() for to process new events
2021-09-08 15:06:06 -04:00
Glenn Strauss 81a107b4e6 [core] change srv->conns to doubly-linked-list
avoids separate memory allocation for list of pointers
2021-09-08 15:06:06 -04:00
Glenn Strauss 5a58f6963c [core] rename srv->max_conns -> srv->lim_conns
srv->lim_conns tracks remaining conns until limit is reached,
replacing (srv->max_conns - srv->conns.used)

srv->srvconf.max_conns is now updated at startup, so
srv->srvconf.max_conns serves as srv->max_conns
2021-09-08 15:06:06 -04:00
Glenn Strauss 624d66b625 [core] add wolfssl-specific include
x-ref:
  https://github.com/lighttpd/lighttpd1.4/pull/107
2021-09-08 15:06:06 -04:00
Glenn Strauss 7386502572 [build] update ax_prog_cc_for_build.m4
http://www.gnu.org/software/autoconf-archive/ax_prog_cc_for_build.html

x-ref:
  "Cross Compile with ptxdist failed for 1.4.59 (1.4.58 works)"
  https://redmine.lighttpd.net/boards/2/topics/9888
2021-09-08 15:06:06 -04:00
Glenn Strauss 89c97b8cd8 [core] conns_pool separate from conns list (#3084)
keep conns_pool of struct connection separate from conns list
and allocate conns list to srv->srvconf.max_conns size at startup

x-ref:
  "Memory fragmentation with HTTP/2 enabled"
  https://redmine.lighttpd.net/issues/3084
2021-09-08 15:06:06 -04:00
Glenn Strauss a8c9b38118 [core] adjust srv->srvconf.max_conns at startup
adjust srv->srvconf.max_conns at startup, if adjustment needed
2021-09-08 15:06:06 -04:00
Glenn Strauss c69450ec04 [core] free fdwaitqueue list when empty
fdwaitqueue is typically unused except in severe overload conditions,
so free up the list storage as soon as it is empty
2021-09-08 15:06:06 -04:00