diff --git a/service/copyparty/copyparty.conf b/service/copyparty/copyparty.conf index 7cf0ed8176c97bcf258ba33732513c6883dbbfe5..7e663a4d279a966eb37b17066dbb0519677c7c98 100644 --- a/service/copyparty/copyparty.conf +++ b/service/copyparty/copyparty.conf @@ -55,5 +55,7 @@ r: * A: snow flags: + md_hist: n + zip_who: 2 chmod_f: 664 chmod_d: 775 diff --git a/tools/router-zig-test.py b/tools/router-zig-test.py index da9796a8b6bccce0545074d4fc71855d9e6dc23a..cc48e3f13eb22acaa564de879f4f2bbf38850812 100644 --- a/tools/router-zig-test.py +++ b/tools/router-zig-test.py @@ -51,8 +51,8 @@ def main(): port = listener.getsockname()[1] lines = ['{', ' admin off', ' auto_https off', '}'] with patch.dict(os.environ, {'SNOWGLOBE_STATE': temporary}): - for host, service in [('prod.localhost', 'copyparty'), ('paired.localhost', paired), ('unpaired.localhost', 'copyparty-preview-ffffffff')]: - lines += [f'http://{host}:{port} {{', *router.zig_mirror_routes(service, routes), ' handle {', ' respond 204', ' }', '}'] + for host, service in [('prod.localhost', 'copyparty'), ('paired.localhost', paired), ('unpaired.localhost', 'copyparty-preview-ffffffff'), ('missing.localhost', 'copyparty')]: + lines += [f'http://{host}:{port} {{', *router.zig_mirror_routes(service, {} if host == 'missing.localhost' else routes), ' handle {', ' respond 204', ' }', '}'] conf = root / 'Caddyfile' conf.write_text('\n'.join(lines)) validated = subprocess.run([str(args.caddy), 'validate', '--config', str(conf), '--adapter', 'caddyfile'], capture_output=True, text=True) @@ -89,9 +89,28 @@ def main(): for path in ['/mirrors/zig/', '/mirrors/zig/releases/', '/mirrors/zig/dev/', '/mirrors/zig/releases/zig-0.0.0.tar.xz', '/mirrors/zig/preadme.md', '/mirrors/zig/not-zig.zip']: assert request(host, path) == (204, b'') + for path in ['/mirrors/zig/.hist/preadme.md', '/mirrors/zig/.mirror-locks/file', '/mirrors/.secret', + '/mirrors/zig/nested/.secret/file', '/mirrors/zig/%2ehist/file', '/mirrors/zig/%2Ehist/file', + '/mirrors/zig%2f.hist/file', '/mirrors/zig%2F.hist/file', '//mirrors///zig//.hist/file', + '/mirrors/zig/normal/../.hist/file', '/before/../mirrors/zig/.hist/file', + '/mirrors/zig/?doc=.secret', '/mirrors/zig/?DOC=%2esecret', + '/mirrors/zig/?doc=readme.md&DOC=.secret', '/mirrors/zig/?DOC=.secret&doc=readme.md', + '/mirrors/zig/?doc=%2Esecret', '/mirrors/zig/?x=1&DoC=.secret']: + count = len(Mirror.requests) + assert request(host, path) == (404, b''), path + assert request(host, path, method='HEAD') == (404, b''), path + assert len(Mirror.requests) == count + for path in ['/media/zig/.hist/preadme.md', '/media/?doc=.secret', '/.static/copyparty.css', + '/mirrors/zig/?download=1', '/mirrors/zig/?x=doc=readme.md', + '/mirrors/zig/?doc=preadme.md', '/mirrors/zig/?doc=regular.zip', + '/mirrors/zig/?DOC=visible.md', '/mirrors/zig/?doc', '/mirrors/zig/?x=1&DoC=visible.md']: + assert request(host, path) == (204, b''), path assert request(host, archive, method='POST') == (204, b'') count = len(Mirror.requests) - assert request('unpaired.localhost', archive) == (503, b'') + for host in ['unpaired.localhost', 'missing.localhost']: + assert request(host, archive) == (503, b'') + assert request(host, '/mirrors/zig/.hist/file') == (404, b'') + assert request(host, '/mirrors/zig/?DOC=.secret') == (404, b'') assert len(Mirror.requests) == count finally: caddy.terminate() diff --git a/tools/router.py b/tools/router.py index b339ec8ecbe49ce405c06c1f295f0d3722ac6cc8..72831004ba4e38a044b568cbb0e67c72265249d5 100644 --- a/tools/router.py +++ b/tools/router.py @@ -119,7 +119,9 @@ def zig_mirror_routes(service, routes): mirror = None upstreams = set().union(*(route["upstreams"] for route in routes.values() if mirror in route["services"])) pattern = r"^/mirrors/zig/zig[^/]*\.(?:tar\.xz|zip)(?:\.minisig)?$" - lines = [" @zig_mirror {", " method GET HEAD", f" path_regexp zig_mirror {pattern}", " }", + lines = [" @mirror_private expression `path_regexp('^/+mirrors(?:/+[^/]*)*/+[.]') || (path_regexp('^/+mirrors(?:/|$)') && {http.request.uri.query}.matches('(?i)(^|&)doc=(?:[.]|%2e)'))`", + " handle @mirror_private {", " respond 404", " }", + " @zig_mirror {", " method GET HEAD", f" path_regexp zig_mirror {pattern}", " }", " handle @zig_mirror {"] if upstreams: if any(not re.fullmatch(r"127\.0\.0\.1:[0-9]+|\[::1\]:[0-9]+", upstream) for upstream in upstreams): @@ -349,7 +351,7 @@ def render(token): continue lines += [" tracing {", f" span {service}", " span_attributes {", f" snowglobe.service {service}", " snowglobe.kind edge", " }", " }"] - if (service == "copyparty" and "zig-mirror" in internal_services) or re.fullmatch(r"copyparty-preview-[0-9a-f]{8}", service): + if service == "copyparty" or re.fullmatch(r"copyparty-preview-[0-9a-f]{8}", service): lines += zig_mirror_routes(service, routes) manifest = os.path.join(ROUTE_DIR, service + ".json") assets = {} diff --git a/tools/zig-mirror.md b/tools/zig-mirror.md index d94db4dd37fc27467488ad07b4fa8e49887b0303..a461acab5d09d88d1e9faf0a15d96ecdd2ac1dd9 100644 --- a/tools/zig-mirror.md +++ b/tools/zig-mirror.md @@ -49,7 +49,7 @@ group. Run the mirror image's `verify` command against the copied destination before publishing it. A disposable container can bind that exact subtree read-only. The checksum and authenticity passes may run concurrently with bounded CPU/I/O to reuse the filesystem cache. Both must finish successfully. -Retain old `.hist` metadata privately; anonymous users lack dot-file permission. +Retain old `.hist` metadata privately; verify that public URLs cannot fetch it. Promote the reviewed configuration through `tools/deploy.py prod`. Do not replace containers by hand. Confirm anonymous GET/HEAD/Range on flat and nested URLs,