4.7 KiB
CONTRACT — step-06 security fix (after SECURITY BLOCK(1) + MEDIUM/LOW findings)
- date: 2026-10-11 | flow: ship-feature (executor, security loop) | branch: feature/step-06-pdf-archives
- status: verified (CONFORME on substance after oracle fix; security re-audit pending)
REQUEST (IMMUTABLE)
Close the HIGH finding (PDF object injection through an archived branding URL) at the sink and at the schema, and the cheap MEDIUM/LOW findings listed below. No behaviour change for valid inputs: the Step 6 goldens must stay green. Findings deferred with a documented limit: pdf-lib uncapped object-stream inflation (pre-existing, needs a Worker or a pre-scan that would refuse our own PDFs), <use> nesting expansion (resvg already refuses), Report v3 collection caps on read.
ACCEPTANCE CRITERIA
- HIGH sink:
packages/pdf/src/render/linkAnnotation.tswrites the URI asPDFHexString.fromText(url)(or escapes\,(,)and refuses control characters) so no URL can close the string literal; a test exports a PDF whose branding URL ishttps://a.example/) /Next << /S /JavaScript /JS (app.alert\(1\)) >> /Z (throughexportFromEnvelopeAFTER bypassing the schema with a cast, reloads the bytes with pdf-lib and asserts no/JavaScriptaction exists and the link's/URIdecodes to the full original string (or the export is refused by criterion 3, in which case the test asserts the typed refusal and a second test proves the sink escaping on a URL with)that the schema accepts, if any). CHECK: cd packages/pdf && corepack pnpm vitest run tests/security.test.ts 2>&1 | grep -E "Tests " | tail -1 EXPECT: Tests .* passed EVIDENCE: 2026-10-11 verifier pass 1 ECARTS(1) = this oracle (tail -2kept only the Duration line), behaviour MET (33/33, sink + schema + refusal tests read). Oracle corrected by the orchestrator; literal run →Tests 33 passed (33). MET. - Schema:
HttpUrlSchemainpackages/domain/src/archive/branding.tsaccepts only^https?://[^\s()\\<>"'\x00-\x1f\x7f]+$(ASCII, no parentheses, backslash, quotes, angle brackets, whitespace, control characters) and ≤ 2048 chars; the current real URLs (https://faunosteo.com,https://zenquality.fr,https://www.instagram.com/paws.iin.harmony) pass; domain tests cover accept/reject. - Export re-validates its inputs:
exportReportArchiverunsBrandingSchema.parse(input.branding)andPdfLabelSetSchema.parse(input.labels)first; a failure →ArchiveExportError('branding_invalid')(new kind, documented) before any page is drawn; test. - PNG budget:
packages/pdf/src/branding.tsreads the PNG IHDR (signature + width/height at bytes 16-23) beforeembedPng; refuse when width × height > 16,777,216 (4096²) or either side > 8192, or when the signature is wrong → that slot fails alone with alogo_failedwarning; test with a crafted IHDR. - Sanitiser hardening in
packages/pdf/src/svg/sanitize.ts: any attribute value containing a backslash\is removed; instyleattributes and in every presentation attribute, any(not part ofurl(#is refused (attribute removed);image-set(,expression(,@import,javascript:,behavior:refused as today.horse.svgandPaws_in_harmony.svgstill sanitise withremoved: [](existing test stays green); new tests foru\72l(,image-set(,fill="u\72l(http://evil/x)". - NaN guard:
packages/pdf/src/svg/view.tsraster size usesNumber.isFiniteon the view box numbers; a non-finite or ≤ 0 box falls back to the 0.6 ratio; test withviewBox="0 0 1e999 1e999"→ a valid size, no NaN. apps/app/src/app/routes/HomeRoute.tsxchecksfile.size > MAX_PDF_BYTESbeforearrayBuffer()and maps it to theinvalid_pdfmessage; route test updated (routes.HomeRoute.import.test.tsxgains one case, others unchanged).docs/PDF-FORMAT.md"Limits" gains: the URL rule, the PNG budget, and a "Known limits" paragraph: pdf-lib inflates PDF object streams without a cap when loading (a crafted PDF of a few hundred KB can expand to hundreds of MB in the tab; mitigation planned: parse in a Worker or locate the attachment without a full load),<use>expansion bounded by the rasterizer, Report collections not capped on read (export refuses above 500 observations).- Green:
corepack pnpm typecheck && corepack pnpm lint && corepack pnpm test:runfrom the root; goldens untouched (git diff --stat 8b86b92 HEAD -- apps/app/tests/fixtures/goldensempty).
FILE SCOPE
packages/pdf/src/{render/linkAnnotation.ts,export.ts,errors.ts,branding.ts,svg/sanitize.ts,svg/view.ts,index.ts}, packages/pdf/tests/**, packages/domain/src/archive/branding.ts, packages/domain/tests/archive.branding-labels.test.ts, apps/app/src/app/routes/HomeRoute.tsx, apps/app/tests/unit/routes.HomeRoute.import.test.tsx, docs/PDF-FORMAT.md. Nothing else.