Skip to content

Labels: log retention and images in output - #5

Open
mgilardi wants to merge 9 commits into
mainfrom
co/labels-retention
Open

mgilardi wants to merge 9 commits into
mainfrom
co/labels-retention

Conversation

@mgilardi

Copy link
Copy Markdown
Contributor

Captive Origins task K6.

Stacks on #1 (co/labels-core).

  • pruneLabelPrints(payload) enforces log.keepDays (default 180, 0 keeps all); the site schedules it
  • Images in SVG and PDF from allowed local upload collections, as the person; PNG/JPEG only; no web address is ever fetched; failures draw the placeholder and warn

Tested: 49 tests, tsc, leak check. Not tested: cloud storage, a scheduled job.

🤖 Generated with Claude Code

mgilardi and others added 8 commits November 16, 2026 00:14
Starts the build of the first checkpoint: package files copied from the sibling plugin's shape, a Payload-free layout engine (tokens, fitting, sheet positions, the 4 x 6 in preset), the provider contract types, and a plugin that registers the three collections with writes closed by default.

Not tested: any database, PDF or SVG output, the print endpoint, the admin UI, site filtering for scopeField.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Reads, creates, updates and deletes now stay inside the person's own scope when scopeField is set, with scopeOf resolving the scope and failing closed. Shared (no scope) templates are readable by all and changed only by a platform admin. Covered on an in-memory MongoDB with two made-up sites.

Not tested: the print endpoint's scope check (not built), a real site, a browser.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Both outputs draw the same marks, with barcodes, QR and Data Matrix as vectors from bwip-js (MIT) and the PDF written with pdfkit (MIT). The PDF writer is its own export so the plugin config does not load pdfkit.

Not tested: PDF in a viewer or printer, SVG in a browser, scanning a printed code, sheet pages, images.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
POST /api/labels/print renders a PDF for given documents and a template. It refuses signed-out requests, people with no scope, another scope's template, any document the person cannot read and more than 2,000 labels, and writes one log entry of ids and counts.

Not tested: over real HTTP, render time at 2,000 labels, sets, media choice, sheet pages.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The plugin now throws at config time unless access.manage or access.print is set, and no longer lets any signed-in person read templates or print. access.print decides printing, otherwise access.manage does. Template lookup tries the key, then the id as given, so numeric ids work on SQL databases.

Not tested: numeric ids on a real SQL database; the cost of reading documents at depth 3.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
keepDays was stored but never used, and image elements were placeholder boxes.
pruneLabelPrints deletes old log entries when the site schedules it. Images load
only from upload collections the site names, as the person, as PNG or JPEG;
web addresses are never fetched, and a failed image draws the placeholder with
a warning.

Not tested: cloud storage adapters, a scheduled job, print quality.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Main took the core branch by rebase, so the same changes sit under new
commit ids. Main's tree matches the core branch exactly, so this keeps the
branch tree. Nothing is rewritten. Tests: see pull request.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The 180 day default only takes effect when the site schedules
pruneLabelPrints, so the README now says so plainly. Docs only; no code
changed and no tests were added.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@mgilardi
mgilardi changed the base branch from co/labels-core to main November 16, 2026 16:43
@mgilardi

Copy link
Copy Markdown
Contributor Author

Security and privacy review (EXTANT APE, Head of Research for Simon)

Verdict: changes. The image handling can use up the server's memory.

Checked and fine: CI green. Local: 49 of 49 tests pass. No new dependencies.

  • Retention: 180 days is the default, as ruled, and tested. 0, negative, NaN, Infinity and strings all keep everything, so a bad setting fails safe.
  • Images: remote URLs (scheme://, //) are refused, and data: and file: can't reach a real collection. Records are read as the person, only PNG and JPEG are accepted, with signatures checked, and basename() blocks path traversal. The SVG href is a fixed-type base64 data URI, and SVG uploads can't be used.

Fix before merge

  1. The 5 MB check runs after the whole file is read (src/images.ts:38). A huge upload is loaded into memory in full, for up to 2,000 sources at once through Promise.all in print.ts. stat the file first, or read with a limit.
  2. Each label embeds its own copy of the image (src/pdf.ts:35). pdfkit only reuses images given as a string path, so doc.image(Buffer.from(...)) embeds the image again for every label. 2,000 labels with a 5 MB image comes to about 10 GB. Any printer can start that. Embed once and reuse pdfkit's image object (or register a string key), and cap the total image bytes per request. A test should check that the PDF size barely grows with the label count.
  3. Decompression bomb: pdfkit inflates PNGs with alpha in memory. A 5 MB file can expand to gigabytes. Read the IHDR width and height and refuse images over a pixel limit.

Worth doing
4. The cloud-storage claim doesn't match the code. The CHANGELOG and decisions say cloud-storage collections are refused with a message. The code refuses only when staticDir is missing, and Payload fills in staticDir by default. Storage-adapter collections therefore reach readFile and get the generic "could not be read", or a stale local file. Also, a relative staticDir is joined against the process's working folder. Refuse collections that have a storage adapter, or fix the docs.
5. Retention: keepDays: 0.001 or a future now deletes almost the whole log. Require a whole number of 1 or more. Return or log res.errors from the bulk delete. The delete covers every site with overrideAccess, which is expected, but say so in the docs.
6. #3 and #5 both change the layout and renderPdf calls in print.ts. Whoever merges second should check that images still resolve on sheet media.

🤖 Generated with Claude Code

Review fixes: check file size before reading, cap total image bytes and PNG
pixels, embed each picture once per PDF, refuse collections with local storage
disabled, and make retention accept only whole days of 1 or more.

Tested: new tests for the size and pixel limits, one embedded copy across 50
labels, and bad retention settings (51 pass). Not tested: a real storage
adapter and a large PNG decode.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant