From 1193f9ba6cc7fa101916ac28bdaf51eabf152440 Mon Sep 17 00:00:00 2001 From: ed Date: Sun, 28 Sep 2025 19:29:18 +0000 Subject: [PATCH] stop binary garbage from hitting logs --- copyparty/httpcli.py | 19 ++++++++++--------- copyparty/u2idx.py | 2 +- copyparty/up2k.py | 2 +- copyparty/util.py | 6 +++--- 4 files changed, 15 insertions(+), 14 deletions(-) diff --git a/copyparty/httpcli.py b/copyparty/httpcli.py index 6232f93e..b66a71fe 100644 --- a/copyparty/httpcli.py +++ b/copyparty/httpcli.py @@ -333,6 +333,7 @@ class HttpCli(object): k, zs = header_line.split(":", 1) self.headers[k.lower()] = zs.strip() except: + headerlines = [repr(x) for x in headerlines] msg = "#[ " + " ]\n#[ ".join(headerlines) + " ]" raise Pebkac(400, "bad headers", log=msg) @@ -796,7 +797,7 @@ class HttpCli(object): elif self.mode in ("MOVE", "COPY"): return self.handle_cpmv() and self.keepalive else: - raise Pebkac(400, 'invalid HTTP verb "{0}"'.format(self.mode)) + raise Pebkac(400, "invalid HTTP verb %r" % (self.mode,)) except Exception as ex: if not isinstance(ex, Pebkac): @@ -2124,9 +2125,9 @@ class HttpCli(object): if "get" in opt: return self.handle_get() - raise Pebkac(405, "POST({}) is disabled in server config".format(ctype)) + raise Pebkac(405, "POST(%r) is disabled in server config" % (ctype,)) - raise Pebkac(405, "don't know how to handle POST({})".format(ctype)) + raise Pebkac(405, "don't know how to handle POST(%r)" % (ctype,)) def get_xml_enc(self, txt: str) -> str: ofs = txt[:512].find(' encoding="') @@ -2600,7 +2601,7 @@ class HttpCli(object): if act == "logout": return self.handle_logout() - raise Pebkac(422, 'invalid action "{}"'.format(act)) + raise Pebkac(422, "invalid action %r" % (act,)) def handle_zip_post(self) -> bool: assert self.parser # !rm @@ -3809,7 +3810,7 @@ class HttpCli(object): assert self.parser.gen # !rm p_field, _, p_data = next(self.parser.gen) if p_field != "body": - raise Pebkac(400, "expected body, got {}".format(p_field)) + raise Pebkac(400, "expected body, got %r" % (p_field,)) if "txt_eol" in vfs.flags: p_data = eol_conv(p_data, vfs.flags["txt_eol"]) @@ -5985,7 +5986,7 @@ class HttpCli(object): vp2, fn = zs.rsplit("/", 1) fns.append(fn) if vp != vp2: - t = "mismatching base paths in selection:\n [%s]\n [%s]" + t = "mismatching base paths in selection:\n %r\n %r" raise Pebkac(400, t % (vp, vp2)) vp = vp.strip("/") @@ -5994,7 +5995,7 @@ class HttpCli(object): m = re.search(r"([^0-9a-zA-Z_-])", skey) if m: - raise Pebkac(400, "sharekey has illegal character [%s]" % (m[1],)) + raise Pebkac(400, "sharekey has illegal character %r" % (m[1],)) if vp.startswith(self.args.shr1): raise Pebkac(400, "yo dawg...") @@ -6007,7 +6008,7 @@ class HttpCli(object): qr = cur.execute(q, (skey,)).fetchall() if qr and qr[0]: self.log("sharekey taken by %r" % (qr,)) - raise Pebkac(400, "sharekey [%s] is already in use" % (skey,)) + raise Pebkac(400, "sharekey %r is already in use" % (skey,)) # ensure user has requested perms s_rd = "read" in req["perms"] @@ -6033,7 +6034,7 @@ class HttpCli(object): rfns = set([x[0] for x in reals]) for fn in fns: if fn not in rfns: - raise Pebkac(400, "selected file not found on disk: [%s]" % (fn,)) + raise Pebkac(400, "selected file not found on disk: %r" % (fn,)) pw = req.get("pw") or "" pw = self.asrv.ah.hash(pw) diff --git a/copyparty/u2idx.py b/copyparty/u2idx.py index f6bbfe84..9696c3e2 100644 --- a/copyparty/u2idx.py +++ b/copyparty/u2idx.py @@ -267,7 +267,7 @@ class U2idx(object): v = "exists(select 1 from mt where mt.w = mtw and " + vq else: - raise Pebkac(400, "invalid key [{}]".format(v)) + raise Pebkac(400, "invalid key %r" % (v,)) q += v + " " continue diff --git a/copyparty/up2k.py b/copyparty/up2k.py index 85ad6517..70729176 100644 --- a/copyparty/up2k.py +++ b/copyparty/up2k.py @@ -5038,7 +5038,7 @@ class Up2k(object): for k in cj["hash"]: if not self.r_hash.match(k): raise Pebkac( - 400, "at least one hash is not according to spec: {}".format(k) + 400, "at least one hash is not according to spec: %r" % (k,) ) # try to use client-provided timestamp, don't care if it fails somehow diff --git a/copyparty/util.py b/copyparty/util.py index 03bf7ade..e2ca6338 100644 --- a/copyparty/util.py +++ b/copyparty/util.py @@ -1770,12 +1770,12 @@ class MultipartParser(object): continue if m.group(1).lower() != "form-data": - raise Pebkac(400, "not form-data: {}".format(ln)) + raise Pebkac(400, "not form-data: %r" % (ln,)) try: field = self.re_cdisp_field.match(ln).group(1) # type: ignore except: - raise Pebkac(400, "missing field name: {}".format(ln)) + raise Pebkac(400, "missing field name: %r" % (ln,)) try: fn = self.re_cdisp_file.match(ln).group(1) # type: ignore @@ -1947,7 +1947,7 @@ def get_boundary(headers: dict[str, str]) -> str: ct = headers["content-type"] m = re.match(ptn, ct, re.IGNORECASE) if not m: - raise Pebkac(400, "invalid content-type for a multipart post: {}".format(ct)) + raise Pebkac(400, "invalid content-type for a multipart post: %r" % (ct,)) return m.group(2)