diff --git a/.claude/tasks/contracts/2026-10-11-step-06-security-fix.md b/.claude/tasks/contracts/2026-10-11-step-06-security-fix.md index 1b84e9a1..10abc0b1 100644 --- a/.claude/tasks/contracts/2026-10-11-step-06-security-fix.md +++ b/.claude/tasks/contracts/2026-10-11-step-06-security-fix.md @@ -1,14 +1,15 @@ # 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: active +- 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), `` nesting expansion (resvg already refuses), Report v3 collection caps on read. ## ACCEPTANCE CRITERIA 1. HIGH sink: `packages/pdf/src/render/linkAnnotation.ts` writes the URI as `PDFHexString.fromText(url)` (or escapes `\`, `(`, `)` and refuses control characters) so no URL can close the string literal; a test exports a PDF whose branding URL is `https://a.example/) /Next << /S /JavaScript /JS (app.alert\(1\)) >> /Z (` through `exportFromEnvelope` AFTER bypassing the schema with a cast, reloads the bytes with pdf-lib and asserts no `/JavaScript` action exists and the link's `/URI` decodes 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 | tail -2 - EXPECT: passed + 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 -2` kept 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. 2. Schema: `HttpUrlSchema` in `packages/domain/src/archive/branding.ts` accepts 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. 3. Export re-validates its inputs: `exportReportArchive` runs `BrandingSchema.parse(input.branding)` and `PdfLabelSetSchema.parse(input.labels)` first; a failure → `ArchiveExportError('branding_invalid')` (new kind, documented) before any page is drawn; test. 4. PNG budget: `packages/pdf/src/branding.ts` reads the PNG IHDR (signature + width/height at bytes 16-23) before `embedPng`; refuse when width × height > 16,777,216 (4096²) or either side > 8192, or when the signature is wrong → that slot fails alone with a `logo_failed` warning; test with a crafted IHDR.