oliver-zehentleitner / maity

clean-up: uploads and images: the S3 attachment copy reads files without the FILE_CAP its docs promise

Sign in to report

tsk-8axntrksjmwx Open

From the clean-up audit tsk-hgnbapyw7hnh, Area 4 (Uploads and images), read at 80647565. Line numbers are at that SHA; check them against current main first.

This item is on its own card because it may also concern the security team (tsk-v9kheekgq115, Area 4: type/size checks). No security card covers it: searched FILE_CAP, copy_local_to_s3, attachment_store, attachment cap, and the cards related to tsk-v9kheekgq115 (tsk-x2gd2w0146jm is about refused decodes, not this).

Finding 2 (part): the S3 attachment copy is documented to honour FILE_CAP, but nothing enforces it (docs drift, possible hardening)

  • attachment_store.py:398-428 copy_local_to_s3: the docstring says a file "is read whole (at most FILE_CAP, like an upload)". hub/context/replicas.md:599 says the same.
  • The code reads whatever is on the volume: source.get(key) at attachment_store.py:453, then hashes and puts it whole. There is no size check.
  • attachments.py:33 FILE_CAP (10 MiB) is referenced by no code at all. The cap enforced on uploads is middleware.py:65 ATTACHMENT_CAP.
  • Impact: the copy is an operator command (cli._clean_bucket runs after it), so the input is the hub's own volume. An oversized or planted file on the volume is read into memory whole and copied to the bucket, where the hub then serves it, although no upload could have produced it.
  • Proposal, one of:
  1. Enforce the cap: skip a file larger than the upload cap (count it as failed, log the key), using one shared constant (the Area 4 toolbox card, filed at the same time, merges FILE_CAP and ATTACHMENT_CAP).
  2. Reword the docstring and the context line so they say what the code does.
  • Effort: S. Risk: low.

Open question

  • tsk-v9zn8a8k83bj (ops, in review) removes the pre-S3 attachment copies; prod serves from S3. If no hub still needs the volume-to-S3 migration, the copy command (and cli._clean_bucket) could be removed instead, as the alpha keeps no legacy paths. Lead or maintainer to decide: enforce, reword, or remove.

Effort sum: S = 1 point.