Commit Graph

47 Commits

Author SHA1 Message Date
Glenn Strauss acd5e450b5 [security] disable stat_cache if !follow-symlink (fixes #2724)
disable stat_cache if server.follow-symlink = "disable"
if server.stat-cache-engine = "simple".  Caching is still enabled
for server.stat-cache-engine = "fam" since the FAM notification is
almost immediate, however there is still a small race condition.

NOTE: server.follow-symlink = "disable" implementation still has
time-of-check versus time-of-use (ToC-ToU) race conditions and
its use is *not recommended* except to discourage symlinking.
It *does not* prevent symlinking by a determined attacker with
the ability to create files on the server.

server.stat-cache-engine = "disable" can also be used to discourage
symlinking, and also does not eliminate ToC-ToU race conditions.

While more modern systems might use openat() and other *at() routines
to eliminate the ToC-ToU race conditions, this is not currently
implemented in lighttpd.  Besides, for systems needing such
protections against actors able to modify local files, it would be
better to set up multiple lighttpd servers running in separate user
contexts with filesystem permissions preventing access, rather than
giving a single lighttpd server running under a single lighttpd user
access to files across security boundaries, and trying to prevent
access by lighttpd user if a file is a symlink.

Note that there are performance implications to setting either of
  server.follow-symlink = "disable"
  server.stat-cache-engine = "disable"
since stat cache normally reduces filesystem overhead for
frequently-accessed files.

x-ref:
  "security: stat cache *very large* race condition if caching when
follow_symlink disabled"
  https://redmine.lighttpd.net/issues/2724
2016-07-30 02:10:44 -04:00
Glenn Strauss a65c57a548 [core] open fd when appending file to cq (fixes #2655)
http_chunk_append_file() opens fd when appending file to chunkqueue.
Defers calculation of content length until response is finished.

This reduces race conditions pertaining to stat() and then (later)
open(), when the result of the stat() was used for Content-Length
or to generate chunked headers.

Note: this does not change how lighttpd handles files that are modified
in-place by another process after having been opened by lighttpd --
don't do that.  This *does* improve handling of files that are
frequently modified via a temporary file and then atomically renamed
into place.

mod_fastcgi has been modified to use http_chunk_append_file_range() with
X-Sendfile2 and will open the target file multiple times if there are
multiple ranges.

Note: (future todo) not implemented for chunk.[ch] interfaces used by
range requests in mod_staticfile or by mod_ssi.  Those uses could lead
to too many open fds.  For mod_staticfile, limits should be put in place
for max number of ranges accepted by mod_staticfile.  For mod_ssi,
limits would need to be placed on the maximum number of includes, and
the primary SSI file split across lots of SSI directives should either
copy the pieces or perhaps chunk.h could be extended to allow for an
open fd to be shared across multiple chunks.  Doing either of these
would improve the performance of SSI since they would replace many file
opens on the pieces of the SSI file around the SSI directives.

x-ref:
  "Serving a file that is getting updated can cause an empty response or incorrect content-length error"
  https://redmine.lighttpd.net/issues/2655

github:
Closes #49
2016-04-18 04:27:08 -04:00
Glenn Strauss d17d48e01e [stat] mimetype.xattr-name global config option (fixes #2631)
For backwards compatibility with existing lighttpd configs, default is
  mimetype.xattr-name = "Content-Type"

Those who wish to use the freedesktop.org definition of xattr mimetype
can set the following in the global lighttpd config:
  mimetype.xattr-name = "user.mime_type"

From: Glenn Strauss <gstrauss@gluelogic.com>

git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@3131 152afb58-edef-0310-8abb-c4023f1b3aa9
2016-03-26 13:49:43 +00:00
Glenn Strauss 8abd06a7ff consistent inclusion of config.h at top of files (fixes #2073)
From: Glenn Strauss <gstrauss@gluelogic.com>

git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@3113 152afb58-edef-0310-8abb-c4023f1b3aa9
2016-03-19 15:14:35 +00:00
Stefan Bühler 566cf8decb add force_assert for more allocation results
From: Stefan Bühler <stbuehler@web.de>

git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@3072 152afb58-edef-0310-8abb-c4023f1b3aa9
2016-01-30 13:59:07 +00:00
Stefan Bühler 69f890e2c5 [stat-cache] fix handling of collisions, might have returned wrong data (fixes #2669)
- don't remember splay_tree nodes for long (dir_node, file_node) after
  cache lookup; only remember the data they pointed to (sce for file
  entries, fam_node for dir entries)
- unset sce / fam_node when a collision (not matching path) is detected
- check again for collision before splaytree_insert; the entry in
  question is already at the top because it was splayed before. simply
  replace the data on collisions (and release the old data).
- check fam_node for collisions too
- splaytree_size handles NULL nodes too
- enable some force_assert lines (were in #ifdef DEBUG_STAT_CACHE before)

Differential Revision: https://review.lighttpd.net/D1

From: Stefan Bühler <stbuehler@web.de>

git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@3039 152afb58-edef-0310-8abb-c4023f1b3aa9
2015-09-16 00:18:11 +00:00
Stefan Bühler 9257d7df4f [bsd xattr] fix compile break with BSD extended attributes in stat_cache
From: Stefan Bühler <stbuehler@web.de>

git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@3023 152afb58-edef-0310-8abb-c4023f1b3aa9
2015-08-22 23:27:17 +00:00
Stefan Bühler fa8b154628 fix undefined integer shift
From: Stefan Bühler <stbuehler@web.de>

git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@3011 152afb58-edef-0310-8abb-c4023f1b3aa9
2015-08-22 16:00:56 +00:00
Stefan Bühler ad3e93ea96 Use buffer API to read and modify "used" member
- a lot of code tried to handle manually adding terminating zeroes and
  keeping track of the correct "used" count.
  Replaced all "external" usages with simple wrapper functions:
  * buffer_string_is_empty (used <= 1), buffer_is_empty (used == 0);
    prefer buffer_string_is_empty
  * buffer_string_set_length
  * buffer_string_length
  * CONST_BUF_LEN() macro
- removed "static" buffer hacks (buffers pointing to constant/stack
  memory instead of malloc()ed data)
- buffer_append_strftime(): refactor buffer+strftime uses
- li_tohex(): no need for a buffer for binary-to-hex conversion:
  the output data length is easy to predict
- remove "-Winline" from extra warnings: the "inline" keyword just
  supresses the warning about unused but defined (static) functions;
  don't care whether it actually gets inlined or not.

From: Stefan Bühler <stbuehler@web.de>

git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@2979 152afb58-edef-0310-8abb-c4023f1b3aa9
2015-02-08 19:10:44 +00:00
Stefan Bühler 4365bdbebe Remove buffer_prepare_copy() and buffer_prepare_append()
* removed almost all usages of buffer as "memory" (without terminating
  zero)
* refactored cgi variable name encoding

From: Stefan Bühler <stbuehler@web.de>

git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@2977 152afb58-edef-0310-8abb-c4023f1b3aa9
2015-02-08 19:10:39 +00:00
Stefan Bühler 6afad87d2e fix buffer, chunk and http_chunk API
* remove unused structs and functions
    (buffer_array, read_buffer)
  * change return type from int to void for many functions,
    as the return value (indicating error/success) was never checked,
    and the function would only fail on programming errors and not on
    invalid input; changed functions to use force_assert instead of
    returning an error.
  * all "len" parameters now are the real size of the memory to be read.
    the length of strings is given always without the terminating 0.
  * the "buffer" struct still counts the terminating 0 in ->used,
    provide buffer_string_length() to get the length of a string in a
    buffer.
    unset config "strings" have used == 0, which is used in some places
    to distinguish unset values from "" (empty string) values.
  * most buffer usages should now use it as string container.
  * optimise some buffer copying by "moving" data to other buffers
  * use (u)intmax_t for generic int-to-string functions
  * remove unused enum values: UNUSED_CHUNK, ENCODING_UNSET
  * converted BUFFER_APPEND_SLASH to inline function (no macro feature
    needed)
  * refactor: create chunkqueue_steal: moving (partial) chunks into another
    queue
  * http_chunk: added separate function to terminate chunked body instead of
    magic handling in http_chunk_append_mem().
    http_chunk_append_* now handle empty chunks, and never terminate the
    chunked body.

From: Stefan Bühler <stbuehler@web.de>

git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@2975 152afb58-edef-0310-8abb-c4023f1b3aa9
2015-02-08 12:37:10 +00:00
Moritz Wilhelmy 4d55d4ada3 add support for (Free)BSD extended attributes
enable with `./configure --with-attr` and `mimetype.use-xattr =
"enable"` in the config.

set attribute with:

    setextattr user Content-Type text/plain path/to/www/file

From: Moritz Wilhelmy <mw@barfooze.de>

git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@2966 152afb58-edef-0310-8abb-c4023f1b3aa9
2014-05-22 08:30:13 +00:00
Stefan Bühler 07dd0bd0a5 add force_assert() to enforce assertions as simple assert()s are disabled by -DNDEBUG (fixes #2546)
From: Stefan Bühler <stbuehler@web.de>

git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@2948 152afb58-edef-0310-8abb-c4023f1b3aa9
2014-02-16 13:08:20 +00:00
Stefan Bühler d8b363c1d1 [stat-cache] fix FAM cleanup/fdevent handling
From: Stefan Bühler <stbuehler@web.de>

git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@2922 152afb58-edef-0310-8abb-c4023f1b3aa9
2013-11-13 11:43:31 +00:00
Stefan Bühler ae1335503a [stat-cache] FAM: fix use after free (CVE-2013-4560)
From: Stefan Bühler <stbuehler@web.de>

git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@2921 152afb58-edef-0310-8abb-c4023f1b3aa9
2013-11-13 11:43:28 +00:00
Stefan Bühler 6f208cfde1 fix/silence bugs reported by ccc-analyzer (clang)
These should all be non critical:
 * memory leaks on startup in error cases (which lead to
   immediate shutdowns anyway)
 * http_auth/ldap: passing uninitialized "ret" to ldap_err2string
 * sizeof(T) not matching the target pointer in malloc/calloc calls;
   those cases were either:
   * T being the wrong pointer type - shouldn't matter as long as all
     pointers have same size
   * T being larger than the type needed
 * mod_accesslog: direct use after free in cleanup (server shutdown);
   could crash before "clean" shutdown
 * some false positives (mod_compress, mod_expire)
 * assert(srv->config_context->used > 0); - this is always the case,
   as there is always a global config block

From: Stefan Bühler <stbuehler@web.de>

git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@2920 152afb58-edef-0310-8abb-c4023f1b3aa9
2013-11-13 11:43:26 +00:00
Stefan Bühler 38f2d1ddd7 cleanup fdevent code, removed linux-rtsig handler, replaced some fprintf calls
* use log functions
 * convert flags
 * fix handler callback prototype

git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@2752 152afb58-edef-0310-8abb-c4023f1b3aa9
2010-08-06 21:57:15 +00:00
Stefan Bühler 22e8b456a9 Fix header inclusion order, always include "config.h" before any system header
git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@2624 152afb58-edef-0310-8abb-c4023f1b3aa9
2009-10-11 14:31:42 +00:00
Stefan Bühler 4df22f2a32 Fix issues found with clang analyzer
git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@2594 152afb58-edef-0310-8abb-c4023f1b3aa9
2009-07-21 20:35:27 +00:00
Stefan Bühler 57066345e4 Workaround broken operating systems: check for trailing '/' in filenames (fixes #1989)
git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@2510 152afb58-edef-0310-8abb-c4023f1b3aa9
2009-06-07 19:07:31 +00:00
Stefan Bühler 07d9517df6 Removed unneeded buffer_is_empty check in stat cache
git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@2428 152afb58-edef-0310-8abb-c4023f1b3aa9
2009-04-06 10:54:14 +00:00
Stefan Bühler b3027fef1c Allow xattr to overwrite mime type (fixes #1929)
git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@2425 152afb58-edef-0310-8abb-c4023f1b3aa9
2009-04-05 19:36:39 +00:00
Stefan Bühler 7a64f2f888 fix segfault for stat_cache(fam) calls with relative path (without '/', can be triggered by x-sendfile) (#1750)
git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@2299 152afb58-edef-0310-8abb-c4023f1b3aa9
2008-08-27 15:59:50 +00:00
Jan Kneschke e745fd6a12 added more debug output if FAM fails to monitor a dir (for #824)
git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@1940 152afb58-edef-0310-8abb-c4023f1b3aa9
2007-08-17 23:19:17 +00:00
Marcus Rückert 5a583661e3 - only generate the etag_flags once and store them in the connections
object.


git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@1881 152afb58-edef-0310-8abb-c4023f1b3aa9
2007-07-03 18:47:00 +00:00
Jan Kneschke b2a96c959a added static-file.etags, etag.use-inode, etag.use-mtime,
etag.use-size to customize the generation of ETags for 
static files. (fixes #1209) (patch by <Yusufg@gmail.com>)



git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@1874 152afb58-edef-0310-8abb-c4023f1b3aa9
2007-06-15 15:51:16 +00:00
Marcus Rückert 6e332dd7bb - do not use xattr for content-type handling unconditionally
git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@1863 152afb58-edef-0310-8abb-c4023f1b3aa9
2007-05-25 12:56:46 +00:00
Marcus Rückert 8cd1471cb3 - white space cleanup part 2 this time 1.4 ;)
i hope it helps with merging stuff back to 1.5

git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@1371 152afb58-edef-0310-8abb-c4023f1b3aa9
2006-10-04 13:26:23 +00:00
Jan Kneschke 9de3807438 handle follow-symlink in the stat-cache
- added the follow-symlink into the hash-key
- delete all versions if a file/dir is moved or deleted


git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.11-ssl-fixes@1332 152afb58-edef-0310-8abb-c4023f1b3aa9
2006-09-21 14:53:14 +00:00
Marcus Rückert a57bb8202e - fix logging of the path when using stat_cache debugging.
- always run symlink checks as it breaks otherwise

git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.11-ssl-fixes@1326 152afb58-edef-0310-8abb-c4023f1b3aa9
2006-09-21 08:47:30 +00:00
Marcus Rückert 05919041e1 - only run symlink checks if we should not follow them.
git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.11-ssl-fixes@1290 152afb58-edef-0310-8abb-c4023f1b3aa9
2006-09-10 14:11:08 +00:00
Marcus Rückert 0f190e1614 - dont debug the statcache by default!;)
git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.11-ssl-fixes@1287 152afb58-edef-0310-8abb-c4023f1b3aa9
2006-09-07 14:01:38 +00:00
Jan Kneschke 7d4d819599 merged [1055], [1056], [1068], [1172], [1176]
git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.11-ssl-fixes@1286 152afb58-edef-0310-8abb-c4023f1b3aa9
2006-09-07 12:28:48 +00:00
Jan Kneschke 08994e478a don't use strndup if possible
git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.11-ssl-fixes@1285 152afb58-edef-0310-8abb-c4023f1b3aa9
2006-09-07 12:17:00 +00:00
Marcus Rückert 657a024d53 - backport symlink patch in hard version to 1.4.11
git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.11-ssl-fixes@1281 152afb58-edef-0310-8abb-c4023f1b3aa9
2006-09-07 11:00:02 +00:00
Jan Kneschke 478cb34bb3 reverted last patch as open + fstat() results in a hang on named-pipes
git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-merge-1.4.x@875 152afb58-edef-0310-8abb-c4023f1b3aa9
2005-11-22 14:29:55 +00:00
Jan Kneschke 7d8758598f - init FAM after fdevent-backend is up
- open + fstat instead of stat + open for speed reasons
- only init FAM if requested by config


git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-merge-1.4.x@872 152afb58-edef-0310-8abb-c4023f1b3aa9
2005-11-22 11:21:35 +00:00
Jan Kneschke 519788686c removed the if (ISREG || ISDIR) as we need the sce set if we return HANDLER_GO_ON
git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-merge-1.4.x@726 152afb58-edef-0310-8abb-c4023f1b3aa9
2005-09-22 08:00:28 +00:00
Jan Kneschke 56f637b885 removed unusued variables
git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-merge-1.4.x@718 152afb58-edef-0310-8abb-c4023f1b3aa9
2005-09-20 15:44:52 +00:00
Jan Kneschke b795fd36c0 fixed hashing function to only generate unsigned values (fixes #251)
git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-merge-1.4.x@702 152afb58-edef-0310-8abb-c4023f1b3aa9
2005-09-14 07:27:13 +00:00
Jan Kneschke 603d6ace1d don't try to guess, do a read check if we can open it.
git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-merge-1.4.x@682 152afb58-edef-0310-8abb-c4023f1b3aa9
2005-09-02 17:24:17 +00:00
Jan Kneschke ecb30c4eec reverted last chngeset and added asserts() that all inserts and deletes are working
git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-merge-1.4.x@637 152afb58-edef-0310-8abb-c4023f1b3aa9
2005-08-29 10:44:00 +00:00
Jan Kneschke d1e70da839 iterate over the tree on delete and free() the nodes itself
git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-merge-1.4.x@635 152afb58-edef-0310-8abb-c4023f1b3aa9
2005-08-29 09:50:37 +00:00
Jan Kneschke 0212534554 fixed detection of mimetype on uppercase extensions
git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-merge-1.4.x@632 152afb58-edef-0310-8abb-c4023f1b3aa9
2005-08-27 16:35:57 +00:00
Jan Kneschke 79d3bc4491 add support for the original libfam and handle HUP on the fam-fd
git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-merge-1.4.x@622 152afb58-edef-0310-8abb-c4023f1b3aa9
2005-08-25 17:37:17 +00:00
Jan Kneschke 30b1973266 fixed stat-cache for xattr
git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-merge-1.4.x@592 152afb58-edef-0310-8abb-c4023f1b3aa9
2005-08-20 19:09:09 +00:00
Jan Kneschke 5e134da075 dropped file-cache, added stat-cache and modules ALWAYS cleanup at connection-end
git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-merge-1.4.x@502 152afb58-edef-0310-8abb-c4023f1b3aa9
2005-08-08 08:22:06 +00:00