Commit graph

102 commits

Author SHA1 Message Date
ed 6f8a588c4d up2k: fix a mostly-harmless race
as each chunk is written to the file, httpcli calls
up2k.confirm_chunk to register the chunk as completed, and the reply
indicates whether that was the final outstanding chunk, in which case
httpcli closes the file descriptors since there's nothing more to write

the issue is that the final chunk is registered as completed before the
file descriptors are closed, meaning there could be writes that haven't
finished flushing to disk yet

if the client decides to issue another handshake during this window,
up2k sees that all chunks are complete and calls up2k.finish_upload
even as some threads might still be flushing the final writes to disk

so the conditions to hit this bug were as follows (all must be true):
* multiprocessing is disabled
* there is a reverse-proxy
* a client has several idle connections and reuses one of those
* the server's filesystem is EXTREMELY slow, to the point where
   closing a file takes over 30 seconds

the fix is to stop handshakes from being processed while a file is
being closed, which is unfortunately a small bottleneck in that it
prohibits initiating another upload while one is being finalized, but
the required complexity to handle this better is probably not worth it
(a separate mutex for each upload session or something like that)

this issue is mostly harmless, partially because it is super tricky to
hit (only aware of it happening synthetically), and because there is
usually no harmful consequences; the worst-case is if this were to
happen exactly as the server OS decides to crash, which would make the
file appear to be fully uploaded even though it's missing some data
(all extremely unlikely, but not impossible)

there is no performance impact; if anything it should now accept
new tcp connections slightly faster thanks to more granular locking
2024-02-13 19:24:06 +00:00
ed 86419b8f47 suboptimizations and some future safeguards 2024-01-10 23:20:42 +01:00
ed 842817d9e3 improve handling of malicious clients;
* start banning malicious clients according to --ban-422
* reply with a blank 500 to stop firefox from retrying like 20 times
* allow Cc's in a few specific URL params (filenames, dirnames)
2023-12-01 23:08:16 +00:00
ed 4b720f4150 add more prometheus metrics; breaking changes:
* cpp_uptime is now a gauge
* cpp_bans is now cpp_active_bans (and also a gauge)

and other related fixes:
* stop emitting invalid cpp_disk_size/free for offline volumes
* support overriding the spec-mandatory mimetype with ?mime=foo
2023-11-04 20:32:34 +00:00
ed 1f75314463 placeholder expansion in readme and logues; closes #56
also fixes the "scan" volflag which broke in v1.9.14
2023-10-24 16:37:32 +00:00
ed db668ba491 spectrograms are never cropped; share thumbcache 2023-10-15 11:42:57 +00:00
ed 50e01d6904 add more autoban triggers:
* --ban-url: URLs which 404 and also match --sus-urls (bot-scan)
* --ban-403: trying to access volumes that dont exist or require auth
* --ban-422: invalid POST messages, fuzzing and such
* --nonsus-urls: regex of 404s which  shouldn't trigger --ban-404

in may situations it makes sense to handle this logic inside copyparty,
since stuff like cloudflare and running copyparty on another physical
box than the nginx frontend is on becomes fairly clunky
2023-08-26 13:52:24 +00:00
ed fc0405c8f3 add prometheus metrics; closes #49 2023-08-20 17:58:06 +00:00
ed 2437a4e864 the CVE-2023-37474 fix was overly strict; loosen 2023-07-23 11:31:11 +00:00
ed 007d948cb9 fix GHSA-f54q-j679-p9hh: reflected-XSS in cookie-setters;
it was possible to set cookie values which contained newlines,
thus terminating the http header and bleeding into the body.

We now disallow control-characters in queries,
but still allow them in paths, as copyparty supports
filenames containing newlines and other mojibake.

The changes in `set_k304` are not necessary in fixing the vulnerability,
but makes the behavior more correct.
2023-07-23 10:55:08 +00:00
ed 2b2d8e4e02 tls / gencert fixes 2023-06-10 23:34:34 +00:00
ed c355f9bd91 catch common environment issues (#32):
* error-message which explains how to run on py2 / older py3
   when trying to run from source
* check compatibility between jinja2 and cpython on startup
* verify that webdeps are present on startup
* verify that webdeps are present when building sfx
* make-sfx.sh grabs the strip-hints dependency
2023-06-04 13:13:36 +00:00
ed a1a8a8c7b5 configurable tls-certificate location 2023-04-23 20:56:55 +00:00
ed 6acf436573 u2idx pool instead of per-socket;
prevents running out of FDs thanks to thousands of sqlite3 sessions
and neatly sidesteps what could possibly be a race in python's
sqlite3 bindings where it sometimes forgets to close the fd
2023-04-20 20:36:13 +00:00
ed 1a46738649 raise edgecases (broken envs on windows) 2023-02-19 22:13:33 +00:00
ed 8adfcf5950 win10-based copyparty64.exe 2023-02-14 21:50:14 +00:00
ed 741d781c18 add cors controls + improve preflight + pw header 2023-01-28 00:59:04 +00:00
ed 5bb9f56247 linux 6.1 fixed the 6.0 bugs; remove workarounds 2023-01-16 20:44:57 +00:00
ed 2cb1f50370 fix dualstack on lo 2023-01-11 16:10:07 +00:00
ed db194ab519 support location-based rproxy 2022-12-10 23:43:31 +00:00
ed f1477a1c14 block other copyparties from sniping tcp ports 2022-12-07 21:50:52 +00:00
ed 067cc23346 docs + cleanup 2022-12-03 18:58:56 +00:00
ed 99efc290df fix mdns on windows 2022-12-03 13:31:00 +00:00
ed 2fbdc0a85e misc fixes / cleanup 2022-12-02 23:42:46 +00:00
ed 7c76d08958 drop one of the slowloris detectors 2022-12-02 17:53:23 +00:00
ed f0e78a6826 add landing page with mounting instructions 2022-11-26 19:47:27 +00:00
ed 5cd9d11329 add ssdp responder 2022-11-22 21:40:12 +00:00
ed 4ad4657774 mdns: support running on macos 2022-11-17 20:18:24 +00:00
ed b3eb117e87 add mdns zeroconf announcer 2022-11-13 20:05:16 +00:00
ed c72753c5da add native ipv6 support 2022-11-06 16:48:05 +00:00
ed 89d1f52235 cursory slowloris / buggy-webdav-client detector 2022-11-01 22:18:20 +00:00
ed 3312c6f5bd autoclose connection-flooding clients 2022-10-31 22:42:47 +00:00
ed edad3246e0 make pylance happier 2022-10-29 20:40:25 +00:00
ed f3a501db30 add SMB/CIFS server 2022-10-23 23:08:00 +02:00
ed 4bcd30da6b cleaner daemon instancing 2022-10-23 12:05:44 +02:00
ed c003dfab03 unbold ansi grays 2022-10-19 15:30:17 +02:00
ed 20c6b82bec replace magic numbers with errno.* 2022-10-19 15:21:48 +02:00
ed 32e71a43b8 reinvent fail2ban 2022-09-21 22:27:20 +02:00
ed 9401b5ae13 add filetype detection for nameless uploads 2022-09-18 17:30:57 +02:00
ed add04478e5 multiprocessing: fix listening-socket config 2022-09-15 22:25:11 +02:00
ed e430b2567a add pyoxidizer (windows-only) 2022-09-10 17:33:04 +02:00
ed bc6234e032 parallel socket shutdown 2022-08-31 08:38:34 +02:00
ed 558bfa4e1e siocoutq-based shutdown 2022-08-31 01:16:09 +02:00
ed c00b80ca29 v1.3.11 2022-08-10 23:35:21 +02:00
ed 90555a4cea clean-shutdown while hashing huge files 2022-08-03 21:06:10 +02:00
ed dac2fad48e v1.3.8 2022-07-27 16:07:26 +02:00
ed 6e445487b1 satisfy cloudflare DDoS protection 2022-07-03 16:04:28 +02:00
ed 438384425a add types, isort, errorhandling 2022-06-16 01:07:15 +02:00
ed 0b6f102436 fix multiprocessing ftpd 2022-06-12 16:37:56 +02:00
ed fd9d0e433d thumbnails: try FFmpeg for images too 2022-04-11 10:38:57 +02:00